commit | author | age
|
5e3521
|
1 |
/*
|
JM |
2 |
* Copyright 2014 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
package com.gitblit.wicket.pages;
|
|
17 |
|
cd7e4f
|
18 |
import java.io.IOException;
|
5e3521
|
19 |
import java.text.DateFormat;
|
JM |
20 |
import java.text.MessageFormat;
|
|
21 |
import java.text.SimpleDateFormat;
|
|
22 |
import java.util.ArrayList;
|
|
23 |
import java.util.Arrays;
|
|
24 |
import java.util.Calendar;
|
|
25 |
import java.util.Collections;
|
|
26 |
import java.util.Date;
|
|
27 |
import java.util.List;
|
|
28 |
import java.util.Map;
|
|
29 |
import java.util.Set;
|
|
30 |
import java.util.TimeZone;
|
|
31 |
import java.util.TreeSet;
|
|
32 |
|
|
33 |
import javax.servlet.http.HttpServletRequest;
|
|
34 |
|
|
35 |
import org.apache.wicket.AttributeModifier;
|
|
36 |
import org.apache.wicket.Component;
|
|
37 |
import org.apache.wicket.MarkupContainer;
|
|
38 |
import org.apache.wicket.PageParameters;
|
cd7e4f
|
39 |
import org.apache.wicket.RequestCycle;
|
5e3521
|
40 |
import org.apache.wicket.RestartResponseException;
|
JM |
41 |
import org.apache.wicket.ajax.AjaxRequestTarget;
|
|
42 |
import org.apache.wicket.behavior.SimpleAttributeModifier;
|
|
43 |
import org.apache.wicket.markup.html.basic.Label;
|
|
44 |
import org.apache.wicket.markup.html.image.ContextImage;
|
|
45 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
|
46 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
cd7e4f
|
47 |
import org.apache.wicket.markup.html.link.Link;
|
PM |
48 |
import org.apache.wicket.markup.html.link.StatelessLink;
|
|
49 |
import org.apache.wicket.markup.html.pages.RedirectPage;
|
5e3521
|
50 |
import org.apache.wicket.markup.html.panel.Fragment;
|
JM |
51 |
import org.apache.wicket.markup.repeater.Item;
|
|
52 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
53 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
54 |
import org.apache.wicket.model.Model;
|
cd7e4f
|
55 |
import org.apache.wicket.protocol.http.RequestUtils;
|
5e3521
|
56 |
import org.apache.wicket.protocol.http.WebRequest;
|
cd7e4f
|
57 |
import org.apache.wicket.request.target.basic.RedirectRequestTarget;
|
5e3521
|
58 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
JM |
59 |
import org.eclipse.jgit.lib.PersonIdent;
|
|
60 |
import org.eclipse.jgit.lib.Ref;
|
|
61 |
import org.eclipse.jgit.lib.Repository;
|
|
62 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
63 |
|
|
64 |
import com.gitblit.Constants;
|
|
65 |
import com.gitblit.Constants.AccessPermission;
|
c211e9
|
66 |
import com.gitblit.Constants.AuthorizationControl;
|
5e3521
|
67 |
import com.gitblit.Keys;
|
JM |
68 |
import com.gitblit.git.PatchsetCommand;
|
|
69 |
import com.gitblit.git.PatchsetReceivePack;
|
|
70 |
import com.gitblit.models.PathModel.PathChangeModel;
|
|
71 |
import com.gitblit.models.RegistrantAccessPermission;
|
|
72 |
import com.gitblit.models.RepositoryModel;
|
b236ce
|
73 |
import com.gitblit.models.RepositoryUrl;
|
5e3521
|
74 |
import com.gitblit.models.SubmoduleModel;
|
JM |
75 |
import com.gitblit.models.TicketModel;
|
|
76 |
import com.gitblit.models.TicketModel.Change;
|
|
77 |
import com.gitblit.models.TicketModel.CommentSource;
|
|
78 |
import com.gitblit.models.TicketModel.Field;
|
|
79 |
import com.gitblit.models.TicketModel.Patchset;
|
|
80 |
import com.gitblit.models.TicketModel.PatchsetType;
|
|
81 |
import com.gitblit.models.TicketModel.Review;
|
|
82 |
import com.gitblit.models.TicketModel.Score;
|
|
83 |
import com.gitblit.models.TicketModel.Status;
|
|
84 |
import com.gitblit.models.UserModel;
|
|
85 |
import com.gitblit.tickets.TicketIndexer.Lucene;
|
|
86 |
import com.gitblit.tickets.TicketLabel;
|
|
87 |
import com.gitblit.tickets.TicketMilestone;
|
|
88 |
import com.gitblit.tickets.TicketResponsible;
|
b236ce
|
89 |
import com.gitblit.utils.ArrayUtils;
|
5e3521
|
90 |
import com.gitblit.utils.JGitUtils;
|
JM |
91 |
import com.gitblit.utils.JGitUtils.MergeStatus;
|
cd7e4f
|
92 |
import com.gitblit.utils.CommitCache;
|
5e3521
|
93 |
import com.gitblit.utils.MarkdownUtils;
|
cd7e4f
|
94 |
import com.gitblit.utils.RefLogUtils;
|
5e3521
|
95 |
import com.gitblit.utils.StringUtils;
|
JM |
96 |
import com.gitblit.utils.TimeUtils;
|
|
97 |
import com.gitblit.wicket.GitBlitWebSession;
|
fdd82f
|
98 |
import com.gitblit.wicket.TicketsUI;
|
5e3521
|
99 |
import com.gitblit.wicket.WicketUtils;
|
a59232
|
100 |
import com.gitblit.wicket.panels.AvatarImage;
|
cd7e4f
|
101 |
import com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation;
|
5e3521
|
102 |
import com.gitblit.wicket.panels.BasePanel.JavascriptTextPrompt;
|
JM |
103 |
import com.gitblit.wicket.panels.CommentPanel;
|
|
104 |
import com.gitblit.wicket.panels.DiffStatPanel;
|
|
105 |
import com.gitblit.wicket.panels.IconAjaxLink;
|
|
106 |
import com.gitblit.wicket.panels.LinkPanel;
|
|
107 |
import com.gitblit.wicket.panels.ShockWaveComponent;
|
|
108 |
import com.gitblit.wicket.panels.SimpleAjaxLink;
|
|
109 |
|
|
110 |
/**
|
|
111 |
* The ticket page handles viewing and updating a ticket.
|
|
112 |
*
|
|
113 |
* @author James Moger
|
|
114 |
*
|
|
115 |
*/
|
fdd82f
|
116 |
public class TicketPage extends RepositoryPage {
|
5e3521
|
117 |
|
JM |
118 |
static final String NIL = "<nil>";
|
|
119 |
|
|
120 |
static final String ESC_NIL = StringUtils.escapeForHtml(NIL, false);
|
|
121 |
|
|
122 |
final int avatarWidth = 40;
|
|
123 |
|
|
124 |
final TicketModel ticket;
|
|
125 |
|
|
126 |
public TicketPage(PageParameters params) {
|
|
127 |
super(params);
|
|
128 |
|
|
129 |
final UserModel user = GitBlitWebSession.get().getUser() == null ? UserModel.ANONYMOUS : GitBlitWebSession.get().getUser();
|
|
130 |
final RepositoryModel repository = getRepositoryModel();
|
|
131 |
final String id = WicketUtils.getObject(params);
|
|
132 |
long ticketId = Long.parseLong(id);
|
|
133 |
ticket = app().tickets().getTicket(repository, ticketId);
|
|
134 |
|
|
135 |
if (ticket == null) {
|
|
136 |
// ticket not found
|
|
137 |
throw new RestartResponseException(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
|
|
138 |
}
|
|
139 |
|
|
140 |
final List<Change> revisions = new ArrayList<Change>();
|
|
141 |
List<Change> comments = new ArrayList<Change>();
|
|
142 |
List<Change> statusChanges = new ArrayList<Change>();
|
|
143 |
List<Change> discussion = new ArrayList<Change>();
|
|
144 |
for (Change change : ticket.changes) {
|
|
145 |
if (change.hasComment() || (change.isStatusChange() && (change.getStatus() != Status.New))) {
|
|
146 |
discussion.add(change);
|
|
147 |
}
|
|
148 |
if (change.hasComment()) {
|
|
149 |
comments.add(change);
|
|
150 |
}
|
|
151 |
if (change.hasPatchset()) {
|
|
152 |
revisions.add(change);
|
|
153 |
}
|
|
154 |
if (change.isStatusChange() && !change.hasPatchset()) {
|
|
155 |
statusChanges.add(change);
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
final Change currentRevision = revisions.isEmpty() ? null : revisions.get(revisions.size() - 1);
|
|
160 |
final Patchset currentPatchset = ticket.getCurrentPatchset();
|
|
161 |
|
|
162 |
/*
|
|
163 |
* TICKET HEADER
|
|
164 |
*/
|
|
165 |
String href = urlFor(TicketsPage.class, params).toString();
|
|
166 |
add(new ExternalLink("ticketNumber", href, "#" + ticket.number));
|
|
167 |
Label headerStatus = new Label("headerStatus", ticket.status.toString());
|
fdd82f
|
168 |
WicketUtils.setCssClass(headerStatus, TicketsUI.getLozengeClass(ticket.status, false));
|
5e3521
|
169 |
add(headerStatus);
|
JM |
170 |
add(new Label("ticketTitle", ticket.title));
|
|
171 |
if (currentPatchset == null) {
|
|
172 |
add(new Label("diffstat").setVisible(false));
|
|
173 |
} else {
|
|
174 |
// calculate the current diffstat of the patchset
|
|
175 |
add(new DiffStatPanel("diffstat", ticket.insertions, ticket.deletions));
|
|
176 |
}
|
|
177 |
|
|
178 |
|
|
179 |
/*
|
|
180 |
* TAB TITLES
|
|
181 |
*/
|
|
182 |
add(new Label("commentCount", "" + comments.size()).setVisible(!comments.isEmpty()));
|
|
183 |
add(new Label("commitCount", "" + (currentPatchset == null ? 0 : currentPatchset.commits)).setVisible(currentPatchset != null));
|
|
184 |
|
|
185 |
|
|
186 |
/*
|
|
187 |
* TICKET AUTHOR and DATE (DISCUSSION TAB)
|
|
188 |
*/
|
|
189 |
UserModel createdBy = app().users().getUserModel(ticket.createdBy);
|
|
190 |
if (createdBy == null) {
|
|
191 |
add(new Label("whoCreated", ticket.createdBy));
|
|
192 |
} else {
|
|
193 |
add(new LinkPanel("whoCreated", null, createdBy.getDisplayName(),
|
|
194 |
UserPage.class, WicketUtils.newUsernameParameter(createdBy.username)));
|
|
195 |
}
|
|
196 |
|
|
197 |
if (ticket.isProposal()) {
|
|
198 |
// clearly indicate this is a change ticket
|
|
199 |
add(new Label("creationMessage", getString("gb.proposedThisChange")));
|
|
200 |
} else {
|
|
201 |
// standard ticket
|
|
202 |
add(new Label("creationMessage", getString("gb.createdThisTicket")));
|
|
203 |
}
|
|
204 |
|
|
205 |
String dateFormat = app().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
|
|
206 |
String timestampFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy");
|
|
207 |
final TimeZone timezone = getTimeZone();
|
|
208 |
final DateFormat df = new SimpleDateFormat(dateFormat);
|
|
209 |
df.setTimeZone(timezone);
|
|
210 |
final DateFormat tsf = new SimpleDateFormat(timestampFormat);
|
|
211 |
tsf.setTimeZone(timezone);
|
|
212 |
final Calendar cal = Calendar.getInstance(timezone);
|
|
213 |
|
|
214 |
String fuzzydate;
|
|
215 |
TimeUtils tu = getTimeUtils();
|
|
216 |
Date createdDate = ticket.created;
|
|
217 |
if (TimeUtils.isToday(createdDate, timezone)) {
|
|
218 |
fuzzydate = tu.today();
|
|
219 |
} else if (TimeUtils.isYesterday(createdDate, timezone)) {
|
|
220 |
fuzzydate = tu.yesterday();
|
|
221 |
} else {
|
|
222 |
// calculate a fuzzy time ago date
|
|
223 |
cal.setTime(createdDate);
|
|
224 |
cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
225 |
cal.set(Calendar.MINUTE, 0);
|
|
226 |
cal.set(Calendar.SECOND, 0);
|
|
227 |
cal.set(Calendar.MILLISECOND, 0);
|
|
228 |
createdDate = cal.getTime();
|
|
229 |
fuzzydate = getTimeUtils().timeAgo(createdDate);
|
|
230 |
}
|
|
231 |
Label when = new Label("whenCreated", fuzzydate + ", " + df.format(createdDate));
|
|
232 |
WicketUtils.setHtmlTooltip(when, tsf.format(ticket.created));
|
|
233 |
add(when);
|
|
234 |
|
|
235 |
String exportHref = urlFor(ExportTicketPage.class, params).toString();
|
|
236 |
add(new ExternalLink("exportJson", exportHref, "json"));
|
|
237 |
|
|
238 |
|
|
239 |
/*
|
|
240 |
* RESPONSIBLE (DISCUSSION TAB)
|
|
241 |
*/
|
|
242 |
if (StringUtils.isEmpty(ticket.responsible)) {
|
|
243 |
add(new Label("responsible"));
|
|
244 |
} else {
|
|
245 |
UserModel responsible = app().users().getUserModel(ticket.responsible);
|
|
246 |
if (responsible == null) {
|
|
247 |
add(new Label("responsible", ticket.responsible));
|
|
248 |
} else {
|
|
249 |
add(new LinkPanel("responsible", null, responsible.getDisplayName(),
|
|
250 |
UserPage.class, WicketUtils.newUsernameParameter(responsible.username)));
|
|
251 |
}
|
|
252 |
}
|
|
253 |
|
|
254 |
/*
|
|
255 |
* MILESTONE PROGRESS (DISCUSSION TAB)
|
|
256 |
*/
|
|
257 |
if (StringUtils.isEmpty(ticket.milestone)) {
|
|
258 |
add(new Label("milestone"));
|
|
259 |
} else {
|
|
260 |
// link to milestone query
|
270e9e
|
261 |
TicketMilestone tm = app().tickets().getMilestone(repository, ticket.milestone);
|
JM |
262 |
if (tm == null) {
|
|
263 |
tm = new TicketMilestone(ticket.milestone);
|
|
264 |
}
|
e03317
|
265 |
PageParameters milestoneParameters;
|
270e9e
|
266 |
if (tm.isOpen()) {
|
e03317
|
267 |
milestoneParameters = WicketUtils.newOpenTicketsParameter(repositoryName);
|
JM |
268 |
} else {
|
|
269 |
milestoneParameters = WicketUtils.newRepositoryParameter(repositoryName);
|
|
270 |
}
|
5e3521
|
271 |
milestoneParameters.put(Lucene.milestone.name(), ticket.milestone);
|
JM |
272 |
int progress = 0;
|
|
273 |
int open = 0;
|
|
274 |
int closed = 0;
|
270e9e
|
275 |
if (tm != null) {
|
JM |
276 |
progress = tm.getProgress();
|
|
277 |
open = tm.getOpenTickets();
|
|
278 |
closed = tm.getClosedTickets();
|
5e3521
|
279 |
}
|
JM |
280 |
|
|
281 |
Fragment milestoneProgress = new Fragment("milestone", "milestoneProgressFragment", this);
|
|
282 |
milestoneProgress.add(new LinkPanel("link", null, ticket.milestone, TicketsPage.class, milestoneParameters));
|
|
283 |
Label label = new Label("progress");
|
|
284 |
WicketUtils.setCssStyle(label, "width:" + progress + "%;");
|
|
285 |
milestoneProgress.add(label);
|
9f50fd
|
286 |
WicketUtils.setHtmlTooltip(milestoneProgress, MessageFormat.format(getString("gb.milestoneProgress"), open, closed));
|
5e3521
|
287 |
add(milestoneProgress);
|
JM |
288 |
}
|
|
289 |
|
|
290 |
|
|
291 |
/*
|
|
292 |
* TICKET DESCRIPTION (DISCUSSION TAB)
|
|
293 |
*/
|
|
294 |
String desc;
|
|
295 |
if (StringUtils.isEmpty(ticket.body)) {
|
|
296 |
desc = getString("gb.noDescriptionGiven");
|
|
297 |
} else {
|
d07b16
|
298 |
String bugtraq = bugtraqProcessor().processText(getRepository(), repositoryName, ticket.body);
|
a59627
|
299 |
String html = MarkdownUtils.transformGFM(app().settings(), bugtraq, ticket.repository);
|
JM |
300 |
String safeHtml = app().xssFilter().relaxed(html);
|
|
301 |
desc = safeHtml;
|
5e3521
|
302 |
}
|
JM |
303 |
add(new Label("ticketDescription", desc).setEscapeModelStrings(false));
|
|
304 |
|
|
305 |
|
|
306 |
/*
|
|
307 |
* PARTICIPANTS (DISCUSSION TAB)
|
|
308 |
*/
|
|
309 |
if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
|
|
310 |
// gravatar allowed
|
|
311 |
List<String> participants = ticket.getParticipants();
|
|
312 |
add(new Label("participantsLabel", MessageFormat.format(getString(participants.size() > 1 ? "gb.nParticipants" : "gb.oneParticipant"),
|
|
313 |
"<b>" + participants.size() + "</b>")).setEscapeModelStrings(false));
|
|
314 |
ListDataProvider<String> participantsDp = new ListDataProvider<String>(participants);
|
|
315 |
DataView<String> participantsView = new DataView<String>("participants", participantsDp) {
|
|
316 |
private static final long serialVersionUID = 1L;
|
|
317 |
|
|
318 |
@Override
|
|
319 |
public void populateItem(final Item<String> item) {
|
|
320 |
String username = item.getModelObject();
|
|
321 |
UserModel user = app().users().getUserModel(username);
|
|
322 |
if (user == null) {
|
|
323 |
user = new UserModel(username);
|
|
324 |
}
|
b57b9e
|
325 |
item.add(new AvatarImage("participant", user.getDisplayName(),
|
5e3521
|
326 |
user.emailAddress, null, 25, true));
|
JM |
327 |
}
|
|
328 |
};
|
|
329 |
add(participantsView);
|
|
330 |
} else {
|
|
331 |
// gravatar prohibited
|
|
332 |
add(new Label("participantsLabel").setVisible(false));
|
|
333 |
add(new Label("participants").setVisible(false));
|
|
334 |
}
|
|
335 |
|
|
336 |
|
|
337 |
/*
|
|
338 |
* LARGE STATUS INDICATOR WITH ICON (DISCUSSION TAB->SIDE BAR)
|
|
339 |
*/
|
|
340 |
Fragment ticketStatus = new Fragment("ticketStatus", "ticketStatusFragment", this);
|
fdd82f
|
341 |
Label ticketIcon = TicketsUI.getStateIcon("ticketIcon", ticket);
|
5e3521
|
342 |
ticketStatus.add(ticketIcon);
|
JM |
343 |
ticketStatus.add(new Label("ticketStatus", ticket.status.toString()));
|
fdd82f
|
344 |
WicketUtils.setCssClass(ticketStatus, TicketsUI.getLozengeClass(ticket.status, false));
|
5e3521
|
345 |
add(ticketStatus);
|
JM |
346 |
|
|
347 |
|
|
348 |
/*
|
|
349 |
* UPDATE FORM (DISCUSSION TAB)
|
|
350 |
*/
|
7ca053
|
351 |
if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
|
cc1c3f
|
352 |
if (user.canAdmin(ticket, repository) && ticket.isOpen()) {
|
85775a
|
353 |
/*
|
JM |
354 |
* OPEN TICKET
|
|
355 |
*/
|
|
356 |
Fragment controls = new Fragment("controls", "openControlsFragment", this);
|
5e3521
|
357 |
|
85775a
|
358 |
/*
|
JM |
359 |
* STATUS
|
|
360 |
*/
|
|
361 |
List<Status> choices = new ArrayList<Status>();
|
|
362 |
if (ticket.isProposal()) {
|
|
363 |
choices.addAll(Arrays.asList(TicketModel.Status.proposalWorkflow));
|
|
364 |
} else if (ticket.isBug()) {
|
|
365 |
choices.addAll(Arrays.asList(TicketModel.Status.bugWorkflow));
|
|
366 |
} else {
|
|
367 |
choices.addAll(Arrays.asList(TicketModel.Status.requestWorkflow));
|
5e3521
|
368 |
}
|
85775a
|
369 |
choices.remove(ticket.status);
|
5e3521
|
370 |
|
85775a
|
371 |
ListDataProvider<Status> workflowDp = new ListDataProvider<Status>(choices);
|
JM |
372 |
DataView<Status> statusView = new DataView<Status>("newStatus", workflowDp) {
|
|
373 |
private static final long serialVersionUID = 1L;
|
5e3521
|
374 |
|
85775a
|
375 |
@Override
|
JM |
376 |
public void populateItem(final Item<Status> item) {
|
|
377 |
SimpleAjaxLink<Status> link = new SimpleAjaxLink<Status>("link", item.getModel()) {
|
5e3521
|
378 |
|
85775a
|
379 |
private static final long serialVersionUID = 1L;
|
5e3521
|
380 |
|
85775a
|
381 |
@Override
|
JM |
382 |
public void onClick(AjaxRequestTarget target) {
|
|
383 |
Status status = getModel().getObject();
|
|
384 |
Change change = new Change(user.username);
|
|
385 |
change.setField(Field.status, status);
|
|
386 |
if (!ticket.isWatching(user.username)) {
|
|
387 |
change.watch(user.username);
|
5e3521
|
388 |
}
|
85775a
|
389 |
TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
|
JM |
390 |
app().tickets().createNotifier().sendMailing(update);
|
47a544
|
391 |
redirectTo(TicketsPage.class, getPageParameters());
|
5e3521
|
392 |
}
|
85775a
|
393 |
};
|
fdd82f
|
394 |
String css = TicketsUI.getStatusClass(item.getModel().getObject());
|
85775a
|
395 |
WicketUtils.setCssClass(link, css);
|
JM |
396 |
item.add(link);
|
|
397 |
}
|
|
398 |
};
|
|
399 |
controls.add(statusView);
|
5e3521
|
400 |
|
85775a
|
401 |
/*
|
JM |
402 |
* RESPONSIBLE LIST
|
|
403 |
*/
|
|
404 |
Set<String> userlist = new TreeSet<String>(ticket.getParticipants());
|
c211e9
|
405 |
if (UserModel.ANONYMOUS.canPush(getRepositoryModel())
|
JM |
406 |
|| AuthorizationControl.AUTHENTICATED == getRepositoryModel().authorizationControl) {
|
|
407 |
// authorization is ANONYMOUS or AUTHENTICATED (i.e. all users can be set responsible)
|
|
408 |
userlist.addAll(app().users().getAllUsernames());
|
|
409 |
} else {
|
|
410 |
// authorization is by NAMED users (users with PUSH permission can be set responsible)
|
|
411 |
for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {
|
805468
|
412 |
if (rp.permission.atLeast(AccessPermission.PUSH)) {
|
c211e9
|
413 |
userlist.add(rp.registrant);
|
JM |
414 |
}
|
5e3521
|
415 |
}
|
JM |
416 |
}
|
85775a
|
417 |
List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();
|
JM |
418 |
if (!StringUtils.isEmpty(ticket.responsible)) {
|
|
419 |
// exclude the current responsible
|
|
420 |
userlist.remove(ticket.responsible);
|
5e3521
|
421 |
}
|
85775a
|
422 |
for (String username : userlist) {
|
JM |
423 |
UserModel u = app().users().getUserModel(username);
|
|
424 |
if (u != null) {
|
|
425 |
responsibles.add(new TicketResponsible(u));
|
|
426 |
}
|
|
427 |
}
|
|
428 |
Collections.sort(responsibles);
|
|
429 |
responsibles.add(new TicketResponsible(ESC_NIL, "", ""));
|
|
430 |
ListDataProvider<TicketResponsible> responsibleDp = new ListDataProvider<TicketResponsible>(responsibles);
|
|
431 |
DataView<TicketResponsible> responsibleView = new DataView<TicketResponsible>("newResponsible", responsibleDp) {
|
|
432 |
private static final long serialVersionUID = 1L;
|
5e3521
|
433 |
|
85775a
|
434 |
@Override
|
JM |
435 |
public void populateItem(final Item<TicketResponsible> item) {
|
|
436 |
SimpleAjaxLink<TicketResponsible> link = new SimpleAjaxLink<TicketResponsible>("link", item.getModel()) {
|
5e3521
|
437 |
|
85775a
|
438 |
private static final long serialVersionUID = 1L;
|
JM |
439 |
|
|
440 |
@Override
|
|
441 |
public void onClick(AjaxRequestTarget target) {
|
|
442 |
TicketResponsible responsible = getModel().getObject();
|
|
443 |
Change change = new Change(user.username);
|
|
444 |
change.setField(Field.responsible, responsible.username);
|
|
445 |
if (!StringUtils.isEmpty(responsible.username)) {
|
|
446 |
if (!ticket.isWatching(responsible.username)) {
|
|
447 |
change.watch(responsible.username);
|
|
448 |
}
|
|
449 |
}
|
|
450 |
if (!ticket.isWatching(user.username)) {
|
|
451 |
change.watch(user.username);
|
|
452 |
}
|
|
453 |
TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
|
|
454 |
app().tickets().createNotifier().sendMailing(update);
|
47a544
|
455 |
redirectTo(TicketsPage.class, getPageParameters());
|
85775a
|
456 |
}
|
JM |
457 |
};
|
|
458 |
item.add(link);
|
|
459 |
}
|
|
460 |
};
|
|
461 |
controls.add(responsibleView);
|
|
462 |
|
|
463 |
/*
|
|
464 |
* MILESTONE LIST
|
|
465 |
*/
|
|
466 |
List<TicketMilestone> milestones = app().tickets().getMilestones(repository, Status.Open);
|
|
467 |
if (!StringUtils.isEmpty(ticket.milestone)) {
|
|
468 |
for (TicketMilestone milestone : milestones) {
|
|
469 |
if (milestone.name.equals(ticket.milestone)) {
|
|
470 |
milestones.remove(milestone);
|
|
471 |
break;
|
|
472 |
}
|
|
473 |
}
|
|
474 |
}
|
|
475 |
milestones.add(new TicketMilestone(ESC_NIL));
|
|
476 |
ListDataProvider<TicketMilestone> milestoneDp = new ListDataProvider<TicketMilestone>(milestones);
|
|
477 |
DataView<TicketMilestone> milestoneView = new DataView<TicketMilestone>("newMilestone", milestoneDp) {
|
|
478 |
private static final long serialVersionUID = 1L;
|
|
479 |
|
|
480 |
@Override
|
|
481 |
public void populateItem(final Item<TicketMilestone> item) {
|
|
482 |
SimpleAjaxLink<TicketMilestone> link = new SimpleAjaxLink<TicketMilestone>("link", item.getModel()) {
|
|
483 |
|
|
484 |
private static final long serialVersionUID = 1L;
|
|
485 |
|
|
486 |
@Override
|
|
487 |
public void onClick(AjaxRequestTarget target) {
|
|
488 |
TicketMilestone milestone = getModel().getObject();
|
|
489 |
Change change = new Change(user.username);
|
|
490 |
if (NIL.equals(milestone.name) || ESC_NIL.equals(milestone.name)) {
|
|
491 |
change.setField(Field.milestone, "");
|
|
492 |
} else {
|
|
493 |
change.setField(Field.milestone, milestone.name);
|
|
494 |
}
|
|
495 |
if (!ticket.isWatching(user.username)) {
|
|
496 |
change.watch(user.username);
|
|
497 |
}
|
|
498 |
TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
|
|
499 |
app().tickets().createNotifier().sendMailing(update);
|
47a544
|
500 |
redirectTo(TicketsPage.class, getPageParameters());
|
85775a
|
501 |
}
|
JM |
502 |
};
|
|
503 |
item.add(link);
|
|
504 |
}
|
|
505 |
};
|
|
506 |
controls.add(milestoneView);
|
|
507 |
|
|
508 |
String editHref = urlFor(EditTicketPage.class, params).toString();
|
|
509 |
controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));
|
|
510 |
|
|
511 |
add(controls);
|
|
512 |
} else {
|
|
513 |
/*
|
|
514 |
* CLOSED TICKET
|
|
515 |
*/
|
|
516 |
Fragment controls = new Fragment("controls", "closedControlsFragment", this);
|
|
517 |
|
|
518 |
String editHref = urlFor(EditTicketPage.class, params).toString();
|
|
519 |
controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));
|
|
520 |
|
|
521 |
add(controls);
|
|
522 |
}
|
5e3521
|
523 |
} else {
|
JM |
524 |
add(new Label("controls").setVisible(false));
|
|
525 |
}
|
|
526 |
|
|
527 |
|
|
528 |
/*
|
|
529 |
* TICKET METADATA
|
|
530 |
*/
|
|
531 |
add(new Label("ticketType", ticket.type.toString()));
|
4a2fb1
|
532 |
|
f9c78c
|
533 |
add(new Label("priority", ticket.priority.toString()));
|
PM |
534 |
add(new Label("severity", ticket.severity.toString()));
|
4a2fb1
|
535 |
|
5e3521
|
536 |
if (StringUtils.isEmpty(ticket.topic)) {
|
JM |
537 |
add(new Label("ticketTopic").setVisible(false));
|
|
538 |
} else {
|
|
539 |
// process the topic using the bugtraq config to link things
|
d07b16
|
540 |
String topic = bugtraqProcessor().processText(getRepository(), repositoryName, ticket.topic);
|
a59627
|
541 |
String safeTopic = app().xssFilter().relaxed(topic);
|
JM |
542 |
add(new Label("ticketTopic", safeTopic).setEscapeModelStrings(false));
|
5e3521
|
543 |
}
|
4a2fb1
|
544 |
|
JM |
545 |
|
5e3521
|
546 |
|
JM |
547 |
|
|
548 |
/*
|
|
549 |
* VOTERS
|
|
550 |
*/
|
|
551 |
List<String> voters = ticket.getVoters();
|
|
552 |
Label votersCount = new Label("votes", "" + voters.size());
|
|
553 |
if (voters.size() == 0) {
|
|
554 |
WicketUtils.setCssClass(votersCount, "badge");
|
|
555 |
} else {
|
|
556 |
WicketUtils.setCssClass(votersCount, "badge badge-info");
|
|
557 |
}
|
|
558 |
add(votersCount);
|
5fcd95
|
559 |
if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
|
5e3521
|
560 |
Model<String> model;
|
JM |
561 |
if (ticket.isVoter(user.username)) {
|
|
562 |
model = Model.of(getString("gb.removeVote"));
|
|
563 |
} else {
|
|
564 |
model = Model.of(MessageFormat.format(getString("gb.vote"), ticket.type.toString()));
|
|
565 |
}
|
|
566 |
SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("voteLink", model) {
|
|
567 |
|
|
568 |
private static final long serialVersionUID = 1L;
|
|
569 |
|
|
570 |
@Override
|
|
571 |
public void onClick(AjaxRequestTarget target) {
|
|
572 |
Change change = new Change(user.username);
|
|
573 |
if (ticket.isVoter(user.username)) {
|
|
574 |
change.unvote(user.username);
|
|
575 |
} else {
|
|
576 |
change.vote(user.username);
|
|
577 |
}
|
|
578 |
app().tickets().updateTicket(repository, ticket.number, change);
|
47a544
|
579 |
redirectTo(TicketsPage.class, getPageParameters());
|
5e3521
|
580 |
}
|
JM |
581 |
};
|
|
582 |
add(link);
|
|
583 |
} else {
|
|
584 |
add(new Label("voteLink").setVisible(false));
|
|
585 |
}
|
|
586 |
|
|
587 |
|
|
588 |
/*
|
|
589 |
* WATCHERS
|
|
590 |
*/
|
|
591 |
List<String> watchers = ticket.getWatchers();
|
|
592 |
Label watchersCount = new Label("watchers", "" + watchers.size());
|
|
593 |
if (watchers.size() == 0) {
|
|
594 |
WicketUtils.setCssClass(watchersCount, "badge");
|
|
595 |
} else {
|
|
596 |
WicketUtils.setCssClass(watchersCount, "badge badge-info");
|
|
597 |
}
|
|
598 |
add(watchersCount);
|
5fcd95
|
599 |
if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
|
5e3521
|
600 |
Model<String> model;
|
JM |
601 |
if (ticket.isWatching(user.username)) {
|
|
602 |
model = Model.of(getString("gb.stopWatching"));
|
|
603 |
} else {
|
|
604 |
model = Model.of(MessageFormat.format(getString("gb.watch"), ticket.type.toString()));
|
|
605 |
}
|
|
606 |
SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("watchLink", model) {
|
|
607 |
|
|
608 |
private static final long serialVersionUID = 1L;
|
|
609 |
|
|
610 |
@Override
|
|
611 |
public void onClick(AjaxRequestTarget target) {
|
|
612 |
Change change = new Change(user.username);
|
|
613 |
if (ticket.isWatching(user.username)) {
|
|
614 |
change.unwatch(user.username);
|
|
615 |
} else {
|
|
616 |
change.watch(user.username);
|
|
617 |
}
|
|
618 |
app().tickets().updateTicket(repository, ticket.number, change);
|
47a544
|
619 |
redirectTo(TicketsPage.class, getPageParameters());
|
5e3521
|
620 |
}
|
JM |
621 |
};
|
|
622 |
add(link);
|
|
623 |
} else {
|
|
624 |
add(new Label("watchLink").setVisible(false));
|
|
625 |
}
|
|
626 |
|
|
627 |
|
|
628 |
/*
|
|
629 |
* TOPIC & LABELS (DISCUSSION TAB->SIDE BAR)
|
|
630 |
*/
|
|
631 |
ListDataProvider<String> labelsDp = new ListDataProvider<String>(ticket.getLabels());
|
|
632 |
DataView<String> labelsView = new DataView<String>("labels", labelsDp) {
|
|
633 |
private static final long serialVersionUID = 1L;
|
|
634 |
|
|
635 |
@Override
|
|
636 |
public void populateItem(final Item<String> item) {
|
|
637 |
final String value = item.getModelObject();
|
|
638 |
Label label = new Label("label", value);
|
|
639 |
TicketLabel tLabel = app().tickets().getLabel(repository, value);
|
|
640 |
String background = MessageFormat.format("background-color:{0};", tLabel.color);
|
|
641 |
label.add(new SimpleAttributeModifier("style", background));
|
|
642 |
item.add(label);
|
|
643 |
}
|
|
644 |
};
|
|
645 |
|
|
646 |
add(labelsView);
|
|
647 |
|
|
648 |
|
|
649 |
/*
|
|
650 |
* COMMENTS & STATUS CHANGES (DISCUSSION TAB)
|
|
651 |
*/
|
|
652 |
if (comments.size() == 0) {
|
|
653 |
add(new Label("discussion").setVisible(false));
|
|
654 |
} else {
|
|
655 |
Fragment discussionFragment = new Fragment("discussion", "discussionFragment", this);
|
|
656 |
ListDataProvider<Change> discussionDp = new ListDataProvider<Change>(discussion);
|
|
657 |
DataView<Change> discussionView = new DataView<Change>("discussion", discussionDp) {
|
|
658 |
private static final long serialVersionUID = 1L;
|
|
659 |
|
|
660 |
@Override
|
|
661 |
public void populateItem(final Item<Change> item) {
|
|
662 |
final Change entry = item.getModelObject();
|
|
663 |
if (entry.isMerge()) {
|
|
664 |
/*
|
|
665 |
* MERGE
|
|
666 |
*/
|
|
667 |
String resolvedBy = entry.getString(Field.mergeSha);
|
|
668 |
|
|
669 |
// identify the merged patch, it is likely the last
|
|
670 |
Patchset mergedPatch = null;
|
|
671 |
for (Change c : revisions) {
|
|
672 |
if (c.patchset.tip.equals(resolvedBy)) {
|
|
673 |
mergedPatch = c.patchset;
|
|
674 |
break;
|
|
675 |
}
|
|
676 |
}
|
|
677 |
|
|
678 |
String commitLink;
|
|
679 |
if (mergedPatch == null) {
|
|
680 |
// shouldn't happen, but just-in-case
|
|
681 |
int len = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
|
|
682 |
commitLink = resolvedBy.substring(0, len);
|
|
683 |
} else {
|
|
684 |
// expected result
|
|
685 |
commitLink = mergedPatch.toString();
|
|
686 |
}
|
|
687 |
|
|
688 |
Fragment mergeFragment = new Fragment("entry", "mergeFragment", this);
|
|
689 |
mergeFragment.add(new LinkPanel("commitLink", null, commitLink,
|
|
690 |
CommitPage.class, WicketUtils.newObjectParameter(repositoryName, resolvedBy)));
|
|
691 |
mergeFragment.add(new Label("toBranch", MessageFormat.format(getString("gb.toBranch"),
|
|
692 |
"<b>" + ticket.mergeTo + "</b>")).setEscapeModelStrings(false));
|
|
693 |
addUserAttributions(mergeFragment, entry, 0);
|
|
694 |
addDateAttributions(mergeFragment, entry);
|
|
695 |
|
|
696 |
item.add(mergeFragment);
|
|
697 |
} else if (entry.isStatusChange()) {
|
|
698 |
/*
|
|
699 |
* STATUS CHANGE
|
|
700 |
*/
|
|
701 |
Fragment frag = new Fragment("entry", "statusFragment", this);
|
|
702 |
Label status = new Label("statusChange", entry.getStatus().toString());
|
fdd82f
|
703 |
String css = TicketsUI.getLozengeClass(entry.getStatus(), false);
|
5e3521
|
704 |
WicketUtils.setCssClass(status, css);
|
JM |
705 |
frag.add(status);
|
|
706 |
addUserAttributions(frag, entry, avatarWidth);
|
|
707 |
addDateAttributions(frag, entry);
|
|
708 |
item.add(frag);
|
|
709 |
} else {
|
|
710 |
/*
|
|
711 |
* COMMENT
|
|
712 |
*/
|
d07b16
|
713 |
String bugtraq = bugtraqProcessor().processText(getRepository(), repositoryName, entry.comment.text);
|
887300
|
714 |
String comment = MarkdownUtils.transformGFM(app().settings(), bugtraq, repositoryName);
|
a59627
|
715 |
String safeComment = app().xssFilter().relaxed(comment);
|
5e3521
|
716 |
Fragment frag = new Fragment("entry", "commentFragment", this);
|
JM |
717 |
Label commentIcon = new Label("commentIcon");
|
|
718 |
if (entry.comment.src == CommentSource.Email) {
|
|
719 |
WicketUtils.setCssClass(commentIcon, "iconic-mail");
|
|
720 |
} else {
|
|
721 |
WicketUtils.setCssClass(commentIcon, "iconic-comment-alt2-stroke");
|
|
722 |
}
|
|
723 |
frag.add(commentIcon);
|
a59627
|
724 |
frag.add(new Label("comment", safeComment).setEscapeModelStrings(false));
|
5e3521
|
725 |
addUserAttributions(frag, entry, avatarWidth);
|
JM |
726 |
addDateAttributions(frag, entry);
|
|
727 |
item.add(frag);
|
|
728 |
}
|
|
729 |
}
|
|
730 |
};
|
|
731 |
discussionFragment.add(discussionView);
|
|
732 |
add(discussionFragment);
|
|
733 |
}
|
|
734 |
|
|
735 |
/*
|
|
736 |
* ADD COMMENT PANEL
|
|
737 |
*/
|
|
738 |
if (UserModel.ANONYMOUS.equals(user)
|
|
739 |
|| !repository.isBare
|
|
740 |
|| repository.isFrozen
|
|
741 |
|| repository.isMirror) {
|
|
742 |
|
|
743 |
// prohibit comments for anonymous users, local working copy repos,
|
|
744 |
// frozen repos, and mirrors
|
|
745 |
add(new Label("newComment").setVisible(false));
|
|
746 |
} else {
|
|
747 |
// permit user to comment
|
|
748 |
Fragment newComment = new Fragment("newComment", "newCommentFragment", this);
|
b57b9e
|
749 |
AvatarImage img = new AvatarImage("newCommentAvatar", user.username, user.emailAddress,
|
5e3521
|
750 |
"gravatar-round", avatarWidth, true);
|
JM |
751 |
newComment.add(img);
|
|
752 |
CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);
|
|
753 |
commentPanel.setRepository(repositoryName);
|
|
754 |
newComment.add(commentPanel);
|
|
755 |
add(newComment);
|
|
756 |
}
|
|
757 |
|
|
758 |
|
|
759 |
/*
|
|
760 |
* PATCHSET TAB
|
|
761 |
*/
|
|
762 |
if (currentPatchset == null) {
|
31e1bf
|
763 |
// no patchset available
|
d85bfb
|
764 |
RepositoryUrl repoUrl = getRepositoryUrl(user, repository);
|
1590fd
|
765 |
boolean canPropose = repoUrl != null && repoUrl.hasPermission() && repoUrl.permission.atLeast(AccessPermission.CLONE) && !UserModel.ANONYMOUS.equals(user);
|
d85bfb
|
766 |
if (ticket.isOpen() && app().tickets().isAcceptingNewPatchsets(repository) && canPropose) {
|
31e1bf
|
767 |
// ticket & repo will accept a proposal patchset
|
JM |
768 |
// show the instructions for proposing a patchset
|
|
769 |
Fragment changeIdFrag = new Fragment("patchset", "proposeFragment", this);
|
|
770 |
changeIdFrag.add(new Label("proposeInstructions", MarkdownUtils.transformMarkdown(getString("gb.proposeInstructions"))).setEscapeModelStrings(false));
|
|
771 |
changeIdFrag.add(new Label("ptWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Barnum")));
|
d85bfb
|
772 |
changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
|
31e1bf
|
773 |
changeIdFrag.add(new Label("gitWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Git")));
|
d85bfb
|
774 |
changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
|
31e1bf
|
775 |
add(changeIdFrag);
|
JM |
776 |
} else {
|
4affd0
|
777 |
// explain why you can't propose a patchset
|
JM |
778 |
Fragment fragment = new Fragment("patchset", "canNotProposeFragment", this);
|
|
779 |
String reason = "";
|
|
780 |
if (ticket.isClosed()) {
|
|
781 |
reason = getString("gb.ticketIsClosed");
|
|
782 |
} else if (repository.isMirror) {
|
|
783 |
reason = getString("gb.repositoryIsMirror");
|
|
784 |
} else if (repository.isFrozen) {
|
|
785 |
reason = getString("gb.repositoryIsFrozen");
|
|
786 |
} else if (!repository.acceptNewPatchsets) {
|
|
787 |
reason = getString("gb.repositoryDoesNotAcceptPatchsets");
|
d85bfb
|
788 |
} else if (!canPropose) {
|
JM |
789 |
if (UserModel.ANONYMOUS.equals(user)) {
|
|
790 |
reason = getString("gb.anonymousCanNotPropose");
|
|
791 |
} else {
|
|
792 |
reason = getString("gb.youDoNotHaveClonePermission");
|
|
793 |
}
|
4affd0
|
794 |
} else {
|
JM |
795 |
reason = getString("gb.serverDoesNotAcceptPatchsets");
|
|
796 |
}
|
|
797 |
fragment.add(new Label("reason", reason));
|
|
798 |
add(fragment);
|
31e1bf
|
799 |
}
|
5e3521
|
800 |
} else {
|
JM |
801 |
// show current patchset
|
|
802 |
Fragment patchsetFrag = new Fragment("patchset", "patchsetFragment", this);
|
|
803 |
patchsetFrag.add(new Label("commitsInPatchset", MessageFormat.format(getString("gb.commitsInPatchsetN"), currentPatchset.number)));
|
|
804 |
|
a0d5c8
|
805 |
patchsetFrag.add(createMergePanel(user, repository));
|
JM |
806 |
|
|
807 |
if (ticket.isOpen()) {
|
|
808 |
// current revision
|
|
809 |
MarkupContainer panel = createPatchsetPanel("panel", repository, user);
|
|
810 |
patchsetFrag.add(panel);
|
|
811 |
addUserAttributions(patchsetFrag, currentRevision, avatarWidth);
|
|
812 |
addUserAttributions(panel, currentRevision, 0);
|
|
813 |
addDateAttributions(panel, currentRevision);
|
|
814 |
} else {
|
|
815 |
// current revision
|
|
816 |
patchsetFrag.add(new Label("panel").setVisible(false));
|
|
817 |
}
|
5e3521
|
818 |
|
JM |
819 |
// commits
|
|
820 |
List<RevCommit> commits = JGitUtils.getRevLog(getRepository(), currentPatchset.base, currentPatchset.tip);
|
|
821 |
ListDataProvider<RevCommit> commitsDp = new ListDataProvider<RevCommit>(commits);
|
|
822 |
DataView<RevCommit> commitsView = new DataView<RevCommit>("commit", commitsDp) {
|
|
823 |
private static final long serialVersionUID = 1L;
|
|
824 |
|
|
825 |
@Override
|
|
826 |
public void populateItem(final Item<RevCommit> item) {
|
|
827 |
RevCommit commit = item.getModelObject();
|
|
828 |
PersonIdent author = commit.getAuthorIdent();
|
b57b9e
|
829 |
item.add(new AvatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
|
5e3521
|
830 |
item.add(new Label("author", commit.getAuthorIdent().getName()));
|
JM |
831 |
item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),
|
|
832 |
CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
|
|
833 |
item.add(new LinkPanel("diff", "link", getString("gb.diff"), CommitDiffPage.class,
|
|
834 |
WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
|
|
835 |
item.add(new Label("title", StringUtils.trimString(commit.getShortMessage(), Constants.LEN_SHORTLOG_REFS)));
|
a59232
|
836 |
item.add(WicketUtils.createDateLabel("commitDate", JGitUtils.getAuthorDate(commit), GitBlitWebSession
|
5e3521
|
837 |
.get().getTimezone(), getTimeUtils(), false));
|
JM |
838 |
item.add(new DiffStatPanel("commitDiffStat", 0, 0, true));
|
|
839 |
}
|
|
840 |
};
|
|
841 |
patchsetFrag.add(commitsView);
|
|
842 |
add(patchsetFrag);
|
|
843 |
}
|
|
844 |
|
|
845 |
|
|
846 |
/*
|
|
847 |
* ACTIVITY TAB
|
|
848 |
*/
|
|
849 |
Fragment revisionHistory = new Fragment("activity", "activityFragment", this);
|
|
850 |
List<Change> events = new ArrayList<Change>(ticket.changes);
|
|
851 |
Collections.sort(events);
|
|
852 |
Collections.reverse(events);
|
|
853 |
ListDataProvider<Change> eventsDp = new ListDataProvider<Change>(events);
|
|
854 |
DataView<Change> eventsView = new DataView<Change>("event", eventsDp) {
|
|
855 |
private static final long serialVersionUID = 1L;
|
|
856 |
|
|
857 |
@Override
|
|
858 |
public void populateItem(final Item<Change> item) {
|
|
859 |
Change event = item.getModelObject();
|
|
860 |
|
|
861 |
addUserAttributions(item, event, 16);
|
|
862 |
|
|
863 |
if (event.hasPatchset()) {
|
|
864 |
// patchset
|
|
865 |
Patchset patchset = event.patchset;
|
cd7e4f
|
866 |
//In the case of using a cached change list
|
PM |
867 |
item.setVisible(!patchset.isDeleted());
|
|
868 |
|
5e3521
|
869 |
String what;
|
JM |
870 |
if (event.isStatusChange() && (Status.New == event.getStatus())) {
|
|
871 |
what = getString("gb.proposedThisChange");
|
|
872 |
} else if (patchset.rev == 1) {
|
|
873 |
what = MessageFormat.format(getString("gb.uploadedPatchsetN"), patchset.number);
|
|
874 |
} else {
|
|
875 |
if (patchset.added == 1) {
|
|
876 |
what = getString("gb.addedOneCommit");
|
|
877 |
} else {
|
|
878 |
what = MessageFormat.format(getString("gb.addedNCommits"), patchset.added);
|
|
879 |
}
|
|
880 |
}
|
|
881 |
item.add(new Label("what", what));
|
|
882 |
|
|
883 |
LinkPanel psr = new LinkPanel("patchsetRevision", null, patchset.number + "-" + patchset.rev,
|
|
884 |
ComparePage.class, WicketUtils.newRangeParameter(repositoryName, patchset.parent == null ? patchset.base : patchset.parent, patchset.tip), true);
|
|
885 |
WicketUtils.setHtmlTooltip(psr, patchset.toString());
|
|
886 |
item.add(psr);
|
|
887 |
String typeCss = getPatchsetTypeCss(patchset.type);
|
|
888 |
Label typeLabel = new Label("patchsetType", patchset.type.toString());
|
|
889 |
if (typeCss == null) {
|
|
890 |
typeLabel.setVisible(false);
|
|
891 |
} else {
|
|
892 |
WicketUtils.setCssClass(typeLabel, typeCss);
|
|
893 |
}
|
|
894 |
item.add(typeLabel);
|
|
895 |
|
cd7e4f
|
896 |
Link<Void> deleteLink = createDeletePatchsetLink(repository, patchset);
|
PM |
897 |
|
|
898 |
if (user.canDeleteRef(repository)) {
|
|
899 |
item.add(deleteLink.setVisible(patchset.canDelete));
|
|
900 |
} else {
|
|
901 |
item.add(deleteLink.setVisible(false));
|
|
902 |
}
|
|
903 |
|
5e3521
|
904 |
// show commit diffstat
|
JM |
905 |
item.add(new DiffStatPanel("patchsetDiffStat", patchset.insertions, patchset.deletions, patchset.rev > 1));
|
|
906 |
} else if (event.hasComment()) {
|
|
907 |
// comment
|
|
908 |
item.add(new Label("what", getString("gb.commented")));
|
|
909 |
item.add(new Label("patchsetRevision").setVisible(false));
|
|
910 |
item.add(new Label("patchsetType").setVisible(false));
|
cd7e4f
|
911 |
item.add(new Label("deleteRevision").setVisible(false));
|
5e3521
|
912 |
item.add(new Label("patchsetDiffStat").setVisible(false));
|
JM |
913 |
} else if (event.hasReview()) {
|
|
914 |
// review
|
|
915 |
String score;
|
|
916 |
switch (event.review.score) {
|
|
917 |
case approved:
|
|
918 |
score = "<span style='color:darkGreen'>" + getScoreDescription(event.review.score) + "</span>";
|
|
919 |
break;
|
|
920 |
case vetoed:
|
|
921 |
score = "<span style='color:darkRed'>" + getScoreDescription(event.review.score) + "</span>";
|
|
922 |
break;
|
|
923 |
default:
|
|
924 |
score = getScoreDescription(event.review.score);
|
|
925 |
}
|
|
926 |
item.add(new Label("what", MessageFormat.format(getString("gb.reviewedPatchsetRev"),
|
|
927 |
event.review.patchset, event.review.rev, score))
|
|
928 |
.setEscapeModelStrings(false));
|
|
929 |
item.add(new Label("patchsetRevision").setVisible(false));
|
|
930 |
item.add(new Label("patchsetType").setVisible(false));
|
cd7e4f
|
931 |
item.add(new Label("deleteRevision").setVisible(false));
|
5e3521
|
932 |
item.add(new Label("patchsetDiffStat").setVisible(false));
|
JM |
933 |
} else {
|
|
934 |
// field change
|
|
935 |
item.add(new Label("patchsetRevision").setVisible(false));
|
|
936 |
item.add(new Label("patchsetType").setVisible(false));
|
cd7e4f
|
937 |
item.add(new Label("deleteRevision").setVisible(false));
|
5e3521
|
938 |
item.add(new Label("patchsetDiffStat").setVisible(false));
|
JM |
939 |
|
|
940 |
String what = "";
|
|
941 |
if (event.isStatusChange()) {
|
|
942 |
switch (event.getStatus()) {
|
|
943 |
case New:
|
|
944 |
if (ticket.isProposal()) {
|
|
945 |
what = getString("gb.proposedThisChange");
|
|
946 |
} else {
|
|
947 |
what = getString("gb.createdThisTicket");
|
|
948 |
}
|
|
949 |
break;
|
|
950 |
default:
|
|
951 |
break;
|
|
952 |
}
|
|
953 |
}
|
|
954 |
item.add(new Label("what", what).setVisible(what.length() > 0));
|
|
955 |
}
|
|
956 |
|
|
957 |
addDateAttributions(item, event);
|
|
958 |
|
|
959 |
if (event.hasFieldChanges()) {
|
|
960 |
StringBuilder sb = new StringBuilder();
|
|
961 |
sb.append("<table class=\"summary\"><tbody>");
|
|
962 |
for (Map.Entry<Field, String> entry : event.fields.entrySet()) {
|
|
963 |
String value;
|
|
964 |
switch (entry.getKey()) {
|
|
965 |
case body:
|
|
966 |
String body = entry.getValue();
|
|
967 |
if (event.isStatusChange() && Status.New == event.getStatus() && StringUtils.isEmpty(body)) {
|
|
968 |
// ignore initial empty description
|
|
969 |
continue;
|
|
970 |
}
|
|
971 |
// trim body changes
|
|
972 |
if (StringUtils.isEmpty(body)) {
|
|
973 |
value = "<i>" + ESC_NIL + "</i>";
|
|
974 |
} else {
|
|
975 |
value = StringUtils.trimString(body, Constants.LEN_SHORTLOG_REFS);
|
|
976 |
}
|
|
977 |
break;
|
|
978 |
case status:
|
|
979 |
// special handling for status
|
|
980 |
Status status = event.getStatus();
|
fdd82f
|
981 |
String css = TicketsUI.getLozengeClass(status, true);
|
5e3521
|
982 |
value = String.format("<span class=\"%1$s\">%2$s</span>", css, status.toString());
|
JM |
983 |
break;
|
|
984 |
default:
|
|
985 |
value = StringUtils.isEmpty(entry.getValue()) ? ("<i>" + ESC_NIL + "</i>") : StringUtils.escapeForHtml(entry.getValue(), false);
|
|
986 |
break;
|
|
987 |
}
|
|
988 |
sb.append("<tr><th style=\"width:70px;\">");
|
3d1b42
|
989 |
try {
|
JM |
990 |
sb.append(getString("gb." + entry.getKey().name()));
|
|
991 |
} catch (Exception e) {
|
|
992 |
sb.append(entry.getKey().name());
|
|
993 |
}
|
5e3521
|
994 |
sb.append("</th><td>");
|
JM |
995 |
sb.append(value);
|
|
996 |
sb.append("</td></tr>");
|
|
997 |
}
|
|
998 |
sb.append("</tbody></table>");
|
a59627
|
999 |
String safeHtml = app().xssFilter().relaxed(sb.toString());
|
JM |
1000 |
item.add(new Label("fields", safeHtml).setEscapeModelStrings(false));
|
5e3521
|
1001 |
} else {
|
JM |
1002 |
item.add(new Label("fields").setVisible(false));
|
|
1003 |
}
|
|
1004 |
}
|
|
1005 |
};
|
|
1006 |
revisionHistory.add(eventsView);
|
|
1007 |
add(revisionHistory);
|
|
1008 |
}
|
|
1009 |
|
|
1010 |
protected void addUserAttributions(MarkupContainer container, Change entry, int avatarSize) {
|
|
1011 |
UserModel commenter = app().users().getUserModel(entry.author);
|
|
1012 |
if (commenter == null) {
|
|
1013 |
// unknown user
|
b57b9e
|
1014 |
container.add(new AvatarImage("changeAvatar", entry.author,
|
5e3521
|
1015 |
entry.author, null, avatarSize, false).setVisible(avatarSize > 0));
|
JM |
1016 |
container.add(new Label("changeAuthor", entry.author.toLowerCase()));
|
|
1017 |
} else {
|
|
1018 |
// known user
|
b57b9e
|
1019 |
container.add(new AvatarImage("changeAvatar", commenter.getDisplayName(),
|
5e3521
|
1020 |
commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,
|
JM |
1021 |
avatarSize, true).setVisible(avatarSize > 0));
|
|
1022 |
container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),
|
|
1023 |
UserPage.class, WicketUtils.newUsernameParameter(commenter.username)));
|
|
1024 |
}
|
|
1025 |
}
|
|
1026 |
|
|
1027 |
protected void addDateAttributions(MarkupContainer container, Change entry) {
|
|
1028 |
container.add(WicketUtils.createDateLabel("changeDate", entry.date, GitBlitWebSession
|
|
1029 |
.get().getTimezone(), getTimeUtils(), false));
|
|
1030 |
|
|
1031 |
// set the id attribute
|
|
1032 |
if (entry.hasComment()) {
|
|
1033 |
container.setOutputMarkupId(true);
|
|
1034 |
container.add(new AttributeModifier("id", Model.of(entry.getId())));
|
|
1035 |
ExternalLink link = new ExternalLink("changeLink", "#" + entry.getId());
|
|
1036 |
container.add(link);
|
|
1037 |
} else {
|
|
1038 |
container.add(new Label("changeLink").setVisible(false));
|
|
1039 |
}
|
|
1040 |
}
|
|
1041 |
|
|
1042 |
protected String getProposeWorkflow(String resource, String url, long ticketId) {
|
|
1043 |
String md = readResource(resource);
|
|
1044 |
md = md.replace("${url}", url);
|
|
1045 |
md = md.replace("${repo}", StringUtils.getLastPathElement(StringUtils.stripDotGit(repositoryName)));
|
|
1046 |
md = md.replace("${ticketId}", "" + ticketId);
|
|
1047 |
md = md.replace("${patchset}", "" + 1);
|
|
1048 |
md = md.replace("${reviewBranch}", Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticketId)));
|
f1b882
|
1049 |
String integrationBranch = Repository.shortenRefName(getRepositoryModel().mergeTo);
|
b335dd
|
1050 |
if (!StringUtils.isEmpty(ticket.mergeTo)) {
|
JM |
1051 |
integrationBranch = ticket.mergeTo;
|
|
1052 |
}
|
|
1053 |
md = md.replace("${integrationBranch}", integrationBranch);
|
5e3521
|
1054 |
return MarkdownUtils.transformMarkdown(md);
|
JM |
1055 |
}
|
|
1056 |
|
|
1057 |
protected Fragment createPatchsetPanel(String wicketId, RepositoryModel repository, UserModel user) {
|
|
1058 |
final Patchset currentPatchset = ticket.getCurrentPatchset();
|
|
1059 |
List<Patchset> patchsets = new ArrayList<Patchset>(ticket.getPatchsetRevisions(currentPatchset.number));
|
|
1060 |
patchsets.remove(currentPatchset);
|
|
1061 |
Collections.reverse(patchsets);
|
|
1062 |
|
|
1063 |
Fragment panel = new Fragment(wicketId, "collapsiblePatchsetFragment", this);
|
|
1064 |
|
|
1065 |
// patchset header
|
|
1066 |
String ps = "<b>" + currentPatchset.number + "</b>";
|
|
1067 |
if (currentPatchset.rev == 1) {
|
|
1068 |
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetN"), ps)).setEscapeModelStrings(false));
|
|
1069 |
} else {
|
|
1070 |
String rev = "<b>" + currentPatchset.rev + "</b>";
|
|
1071 |
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetNRevisionN"), ps, rev)).setEscapeModelStrings(false));
|
|
1072 |
}
|
|
1073 |
panel.add(new LinkPanel("patchId", null, "rev " + currentPatchset.rev,
|
|
1074 |
CommitPage.class, WicketUtils.newObjectParameter(repositoryName, currentPatchset.tip), true));
|
|
1075 |
|
|
1076 |
// compare menu
|
|
1077 |
panel.add(new LinkPanel("compareMergeBase", null, getString("gb.compareToMergeBase"),
|
|
1078 |
ComparePage.class, WicketUtils.newRangeParameter(repositoryName, currentPatchset.base, currentPatchset.tip), true));
|
|
1079 |
|
|
1080 |
ListDataProvider<Patchset> compareMenuDp = new ListDataProvider<Patchset>(patchsets);
|
|
1081 |
DataView<Patchset> compareMenu = new DataView<Patchset>("comparePatch", compareMenuDp) {
|
|
1082 |
private static final long serialVersionUID = 1L;
|
|
1083 |
@Override
|
|
1084 |
public void populateItem(final Item<Patchset> item) {
|
|
1085 |
Patchset patchset = item.getModelObject();
|
|
1086 |
LinkPanel link = new LinkPanel("compareLink", null,
|
|
1087 |
MessageFormat.format(getString("gb.compareToN"), patchset.number + "-" + patchset.rev),
|
|
1088 |
ComparePage.class, WicketUtils.newRangeParameter(getRepositoryModel().name,
|
|
1089 |
patchset.tip, currentPatchset.tip), true);
|
|
1090 |
item.add(link);
|
|
1091 |
|
|
1092 |
}
|
|
1093 |
};
|
|
1094 |
panel.add(compareMenu);
|
|
1095 |
|
|
1096 |
|
|
1097 |
// reviews
|
|
1098 |
List<Change> reviews = ticket.getReviews(currentPatchset);
|
|
1099 |
ListDataProvider<Change> reviewsDp = new ListDataProvider<Change>(reviews);
|
|
1100 |
DataView<Change> reviewsView = new DataView<Change>("reviews", reviewsDp) {
|
|
1101 |
private static final long serialVersionUID = 1L;
|
|
1102 |
|
|
1103 |
@Override
|
|
1104 |
public void populateItem(final Item<Change> item) {
|
|
1105 |
Change change = item.getModelObject();
|
|
1106 |
final String username = change.author;
|
|
1107 |
UserModel user = app().users().getUserModel(username);
|
|
1108 |
if (user == null) {
|
|
1109 |
item.add(new Label("reviewer", username));
|
|
1110 |
} else {
|
|
1111 |
item.add(new LinkPanel("reviewer", null, user.getDisplayName(),
|
|
1112 |
UserPage.class, WicketUtils.newUsernameParameter(username)));
|
|
1113 |
}
|
|
1114 |
|
|
1115 |
// indicate review score
|
|
1116 |
Review review = change.review;
|
|
1117 |
Label scoreLabel = new Label("score");
|
|
1118 |
String scoreClass = getScoreClass(review.score);
|
|
1119 |
String tooltip = getScoreDescription(review.score);
|
|
1120 |
WicketUtils.setCssClass(scoreLabel, scoreClass);
|
|
1121 |
if (!StringUtils.isEmpty(tooltip)) {
|
|
1122 |
WicketUtils.setHtmlTooltip(scoreLabel, tooltip);
|
|
1123 |
}
|
|
1124 |
item.add(scoreLabel);
|
|
1125 |
}
|
|
1126 |
};
|
|
1127 |
panel.add(reviewsView);
|
|
1128 |
|
|
1129 |
|
57a71d
|
1130 |
if (ticket.isOpen() && user.canReviewPatchset(repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
|
5e3521
|
1131 |
// can only review open tickets
|
JM |
1132 |
Review myReview = null;
|
|
1133 |
for (Change change : ticket.getReviews(currentPatchset)) {
|
|
1134 |
if (change.author.equals(user.username)) {
|
|
1135 |
myReview = change.review;
|
|
1136 |
}
|
|
1137 |
}
|
|
1138 |
|
|
1139 |
// user can review, add review controls
|
|
1140 |
Fragment reviewControls = new Fragment("reviewControls", "reviewControlsFragment", this);
|
|
1141 |
|
|
1142 |
// show "approve" button if no review OR not current score
|
|
1143 |
if (user.canApprovePatchset(repository) && (myReview == null || Score.approved != myReview.score)) {
|
|
1144 |
reviewControls.add(createReviewLink("approveLink", Score.approved));
|
|
1145 |
} else {
|
|
1146 |
reviewControls.add(new Label("approveLink").setVisible(false));
|
|
1147 |
}
|
|
1148 |
|
|
1149 |
// show "looks good" button if no review OR not current score
|
|
1150 |
if (myReview == null || Score.looks_good != myReview.score) {
|
|
1151 |
reviewControls.add(createReviewLink("looksGoodLink", Score.looks_good));
|
|
1152 |
} else {
|
|
1153 |
reviewControls.add(new Label("looksGoodLink").setVisible(false));
|
|
1154 |
}
|
|
1155 |
|
|
1156 |
// show "needs improvement" button if no review OR not current score
|
|
1157 |
if (myReview == null || Score.needs_improvement != myReview.score) {
|
|
1158 |
reviewControls.add(createReviewLink("needsImprovementLink", Score.needs_improvement));
|
|
1159 |
} else {
|
|
1160 |
reviewControls.add(new Label("needsImprovementLink").setVisible(false));
|
|
1161 |
}
|
|
1162 |
|
|
1163 |
// show "veto" button if no review OR not current score
|
|
1164 |
if (user.canVetoPatchset(repository) && (myReview == null || Score.vetoed != myReview.score)) {
|
|
1165 |
reviewControls.add(createReviewLink("vetoLink", Score.vetoed));
|
|
1166 |
} else {
|
|
1167 |
reviewControls.add(new Label("vetoLink").setVisible(false));
|
|
1168 |
}
|
|
1169 |
panel.add(reviewControls);
|
|
1170 |
} else {
|
|
1171 |
// user can not review
|
|
1172 |
panel.add(new Label("reviewControls").setVisible(false));
|
|
1173 |
}
|
|
1174 |
|
|
1175 |
String insertions = MessageFormat.format("<span style=\"color:darkGreen;font-weight:bold;\">+{0}</span>", ticket.insertions);
|
|
1176 |
String deletions = MessageFormat.format("<span style=\"color:darkRed;font-weight:bold;\">-{0}</span>", ticket.deletions);
|
|
1177 |
panel.add(new Label("patchsetStat", MessageFormat.format(StringUtils.escapeForHtml(getString("gb.diffStat"), false),
|
|
1178 |
insertions, deletions)).setEscapeModelStrings(false));
|
|
1179 |
|
|
1180 |
// changed paths list
|
|
1181 |
List<PathChangeModel> paths = JGitUtils.getFilesInRange(getRepository(), currentPatchset.base, currentPatchset.tip);
|
|
1182 |
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
|
|
1183 |
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
|
|
1184 |
private static final long serialVersionUID = 1L;
|
|
1185 |
int counter;
|
|
1186 |
|
|
1187 |
@Override
|
|
1188 |
public void populateItem(final Item<PathChangeModel> item) {
|
|
1189 |
final PathChangeModel entry = item.getModelObject();
|
|
1190 |
Label changeType = new Label("changeType", "");
|
|
1191 |
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
|
|
1192 |
setChangeTypeTooltip(changeType, entry.changeType);
|
|
1193 |
item.add(changeType);
|
|
1194 |
|
|
1195 |
boolean hasSubmodule = false;
|
|
1196 |
String submodulePath = null;
|
|
1197 |
if (entry.isTree()) {
|
|
1198 |
// tree
|
|
1199 |
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class,
|
|
1200 |
WicketUtils
|
|
1201 |
.newPathParameter(repositoryName, currentPatchset.tip, entry.path), true));
|
|
1202 |
item.add(new Label("diffStat").setVisible(false));
|
|
1203 |
} else if (entry.isSubmodule()) {
|
|
1204 |
// submodule
|
|
1205 |
String submoduleId = entry.objectId;
|
|
1206 |
SubmoduleModel submodule = getSubmodule(entry.path);
|
|
1207 |
submodulePath = submodule.gitblitPath;
|
|
1208 |
hasSubmodule = submodule.hasSubmodule;
|
|
1209 |
|
|
1210 |
item.add(new LinkPanel("pathName", "list", entry.path + " @ " +
|
|
1211 |
getShortObjectId(submoduleId), TreePage.class,
|
|
1212 |
WicketUtils.newPathParameter(submodulePath, submoduleId, ""), true).setEnabled(hasSubmodule));
|
|
1213 |
item.add(new Label("diffStat").setVisible(false));
|
|
1214 |
} else {
|
|
1215 |
// blob
|
|
1216 |
String displayPath = entry.path;
|
|
1217 |
String path = entry.path;
|
|
1218 |
if (entry.isSymlink()) {
|
e562d4
|
1219 |
RevCommit commit = JGitUtils.getCommit(getRepository(), PatchsetCommand.getTicketBranch(ticket.number));
|
5e3521
|
1220 |
path = JGitUtils.getStringContent(getRepository(), commit.getTree(), path);
|
JM |
1221 |
displayPath = entry.path + " -> " + path;
|
|
1222 |
}
|
|
1223 |
|
|
1224 |
if (entry.changeType.equals(ChangeType.ADD)) {
|
|
1225 |
// add show view
|
|
1226 |
item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
|
|
1227 |
WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
|
|
1228 |
} else if (entry.changeType.equals(ChangeType.DELETE)) {
|
|
1229 |
// delete, show label
|
|
1230 |
item.add(new Label("pathName", displayPath));
|
|
1231 |
} else {
|
|
1232 |
// mod, show diff
|
|
1233 |
item.add(new LinkPanel("pathName", "list", displayPath, BlobDiffPage.class,
|
|
1234 |
WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
|
|
1235 |
}
|
bbd820
|
1236 |
item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
|
5e3521
|
1237 |
}
|
JM |
1238 |
|
|
1239 |
// quick links
|
|
1240 |
if (entry.isSubmodule()) {
|
|
1241 |
// submodule
|
|
1242 |
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
|
|
1243 |
.newPathParameter(repositoryName, entry.commitId, entry.path)))
|
|
1244 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD)));
|
|
1245 |
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
|
|
1246 |
.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
|
|
1247 |
} else {
|
|
1248 |
// tree or blob
|
|
1249 |
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
|
|
1250 |
.newBlobDiffParameter(repositoryName, currentPatchset.base, currentPatchset.tip, entry.path)))
|
|
1251 |
.setEnabled(!entry.changeType.equals(ChangeType.ADD)
|
|
1252 |
&& !entry.changeType.equals(ChangeType.DELETE)));
|
|
1253 |
item.add(setNewTarget(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
|
|
1254 |
.newPathParameter(repositoryName, currentPatchset.tip, entry.path)))
|
|
1255 |
.setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
|
|
1256 |
}
|
|
1257 |
|
|
1258 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
1259 |
counter++;
|
|
1260 |
}
|
|
1261 |
};
|
|
1262 |
panel.add(pathsView);
|
|
1263 |
|
1221a4
|
1264 |
addPtCheckoutInstructions(user, repository, panel);
|
JM |
1265 |
addGitCheckoutInstructions(user, repository, panel);
|
5e3521
|
1266 |
|
JM |
1267 |
return panel;
|
|
1268 |
}
|
|
1269 |
|
|
1270 |
protected IconAjaxLink<String> createReviewLink(String wicketId, final Score score) {
|
|
1271 |
return new IconAjaxLink<String>(wicketId, getScoreClass(score), Model.of(getScoreDescription(score))) {
|
|
1272 |
|
|
1273 |
private static final long serialVersionUID = 1L;
|
|
1274 |
|
|
1275 |
@Override
|
|
1276 |
public void onClick(AjaxRequestTarget target) {
|
|
1277 |
review(score);
|
|
1278 |
}
|
|
1279 |
};
|
|
1280 |
}
|
|
1281 |
|
|
1282 |
protected String getScoreClass(Score score) {
|
|
1283 |
switch (score) {
|
|
1284 |
case vetoed:
|
|
1285 |
return "fa fa-exclamation-circle";
|
|
1286 |
case needs_improvement:
|
|
1287 |
return "fa fa-thumbs-o-down";
|
|
1288 |
case looks_good:
|
|
1289 |
return "fa fa-thumbs-o-up";
|
|
1290 |
case approved:
|
|
1291 |
return "fa fa-check-circle";
|
|
1292 |
case not_reviewed:
|
|
1293 |
default:
|
|
1294 |
return "fa fa-minus-circle";
|
|
1295 |
}
|
|
1296 |
}
|
|
1297 |
|
|
1298 |
protected String getScoreDescription(Score score) {
|
|
1299 |
String description;
|
|
1300 |
switch (score) {
|
|
1301 |
case vetoed:
|
|
1302 |
description = getString("gb.veto");
|
|
1303 |
break;
|
|
1304 |
case needs_improvement:
|
|
1305 |
description = getString("gb.needsImprovement");
|
|
1306 |
break;
|
|
1307 |
case looks_good:
|
|
1308 |
description = getString("gb.looksGood");
|
|
1309 |
break;
|
|
1310 |
case approved:
|
|
1311 |
description = getString("gb.approve");
|
|
1312 |
break;
|
|
1313 |
case not_reviewed:
|
|
1314 |
default:
|
|
1315 |
description = getString("gb.hasNotReviewed");
|
|
1316 |
}
|
|
1317 |
return String.format("%1$s (%2$+d)", description, score.getValue());
|
|
1318 |
}
|
|
1319 |
|
|
1320 |
protected void review(Score score) {
|
|
1321 |
UserModel user = GitBlitWebSession.get().getUser();
|
|
1322 |
Patchset ps = ticket.getCurrentPatchset();
|
|
1323 |
Change change = new Change(user.username);
|
|
1324 |
change.review(ps, score, !ticket.isReviewer(user.username));
|
|
1325 |
if (!ticket.isWatching(user.username)) {
|
|
1326 |
change.watch(user.username);
|
|
1327 |
}
|
|
1328 |
TicketModel updatedTicket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);
|
|
1329 |
app().tickets().createNotifier().sendMailing(updatedTicket);
|
47a544
|
1330 |
redirectTo(TicketsPage.class, getPageParameters());
|
5e3521
|
1331 |
}
|
JM |
1332 |
|
|
1333 |
protected <X extends MarkupContainer> X setNewTarget(X x) {
|
|
1334 |
x.add(new SimpleAttributeModifier("target", "_blank"));
|
|
1335 |
return x;
|
|
1336 |
}
|
|
1337 |
|
1221a4
|
1338 |
protected void addGitCheckoutInstructions(UserModel user, RepositoryModel repository, MarkupContainer panel) {
|
5e3521
|
1339 |
panel.add(new Label("gitStep1", MessageFormat.format(getString("gb.stepN"), 1)));
|
JM |
1340 |
panel.add(new Label("gitStep2", MessageFormat.format(getString("gb.stepN"), 2)));
|
|
1341 |
|
|
1342 |
String ticketBranch = Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticket.number));
|
|
1343 |
|
1221a4
|
1344 |
String step1 = "git fetch origin";
|
2f8b4f
|
1345 |
String step2 = MessageFormat.format("git checkout {0} && git pull --ff-only\nOR\ngit checkout {0} && git reset --hard origin/{0}", ticketBranch);
|
5e3521
|
1346 |
|
JM |
1347 |
panel.add(new Label("gitPreStep1", step1));
|
|
1348 |
panel.add(new Label("gitPreStep2", step2));
|
|
1349 |
|
|
1350 |
panel.add(createCopyFragment("gitCopyStep1", step1.replace("\n", " && ")));
|
|
1351 |
panel.add(createCopyFragment("gitCopyStep2", step2.replace("\n", " && ")));
|
|
1352 |
}
|
|
1353 |
|
1221a4
|
1354 |
protected void addPtCheckoutInstructions(UserModel user, RepositoryModel repository, MarkupContainer panel) {
|
5e3521
|
1355 |
String step1 = MessageFormat.format("pt checkout {0,number,0}", ticket.number);
|
JM |
1356 |
panel.add(new Label("ptPreStep", step1));
|
|
1357 |
panel.add(createCopyFragment("ptCopyStep", step1));
|
|
1358 |
}
|
|
1359 |
|
|
1360 |
/**
|
|
1361 |
* Adds a merge panel for the patchset to the markup container. The panel
|
|
1362 |
* may just a message if the patchset can not be merged.
|
|
1363 |
*
|
|
1364 |
* @param c
|
|
1365 |
* @param user
|
|
1366 |
* @param repository
|
|
1367 |
*/
|
|
1368 |
protected Component createMergePanel(UserModel user, RepositoryModel repository) {
|
|
1369 |
Patchset patchset = ticket.getCurrentPatchset();
|
|
1370 |
if (patchset == null) {
|
|
1371 |
// no patchset to merge
|
|
1372 |
return new Label("mergePanel");
|
|
1373 |
}
|
|
1374 |
|
|
1375 |
boolean allowMerge;
|
|
1376 |
if (repository.requireApproval) {
|
|
1377 |
// rpeository requires approval
|
|
1378 |
allowMerge = ticket.isOpen() && ticket.isApproved(patchset);
|
|
1379 |
} else {
|
|
1380 |
// vetos are binding
|
|
1381 |
allowMerge = ticket.isOpen() && !ticket.isVetoed(patchset);
|
|
1382 |
}
|
|
1383 |
|
|
1384 |
MergeStatus mergeStatus = JGitUtils.canMerge(getRepository(), patchset.tip, ticket.mergeTo);
|
|
1385 |
if (allowMerge) {
|
|
1386 |
if (MergeStatus.MERGEABLE == mergeStatus) {
|
|
1387 |
// patchset can be cleanly merged to integration branch OR has already been merged
|
|
1388 |
Fragment mergePanel = new Fragment("mergePanel", "mergeableFragment", this);
|
|
1389 |
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetMergeable"), ticket.mergeTo)));
|
|
1390 |
if (user.canPush(repository)) {
|
|
1391 |
// user can merge locally
|
|
1392 |
SimpleAjaxLink<String> mergeButton = new SimpleAjaxLink<String>("mergeButton", Model.of(getString("gb.merge"))) {
|
|
1393 |
|
|
1394 |
private static final long serialVersionUID = 1L;
|
|
1395 |
|
|
1396 |
@Override
|
|
1397 |
public void onClick(AjaxRequestTarget target) {
|
|
1398 |
|
|
1399 |
// ensure the patchset is still current AND not vetoed
|
|
1400 |
Patchset patchset = ticket.getCurrentPatchset();
|
|
1401 |
final TicketModel refreshedTicket = app().tickets().getTicket(getRepositoryModel(), ticket.number);
|
|
1402 |
if (patchset.equals(refreshedTicket.getCurrentPatchset())) {
|
|
1403 |
// patchset is current, check for recent veto
|
|
1404 |
if (!refreshedTicket.isVetoed(patchset)) {
|
|
1405 |
// patchset is not vetoed
|
|
1406 |
|
|
1407 |
// execute the merge using the ticket service
|
|
1408 |
app().tickets().exec(new Runnable() {
|
|
1409 |
@Override
|
|
1410 |
public void run() {
|
|
1411 |
PatchsetReceivePack rp = new PatchsetReceivePack(
|
|
1412 |
app().gitblit(),
|
|
1413 |
getRepository(),
|
|
1414 |
getRepositoryModel(),
|
|
1415 |
GitBlitWebSession.get().getUser());
|
|
1416 |
MergeStatus result = rp.merge(refreshedTicket);
|
|
1417 |
if (MergeStatus.MERGED == result) {
|
|
1418 |
// notify participants and watchers
|
|
1419 |
rp.sendAll();
|
|
1420 |
} else {
|
|
1421 |
// merge failure
|
|
1422 |
String msg = MessageFormat.format("Failed to merge ticket {0,number,0}: {1}", ticket.number, result.name());
|
|
1423 |
logger.error(msg);
|
|
1424 |
GitBlitWebSession.get().cacheErrorMessage(msg);
|
|
1425 |
}
|
|
1426 |
}
|
|
1427 |
});
|
|
1428 |
} else {
|
|
1429 |
// vetoed patchset
|
|
1430 |
String msg = MessageFormat.format("Can not merge ticket {0,number,0}, patchset {1,number,0} has been vetoed!",
|
|
1431 |
ticket.number, patchset.number);
|
|
1432 |
GitBlitWebSession.get().cacheErrorMessage(msg);
|
|
1433 |
logger.error(msg);
|
|
1434 |
}
|
|
1435 |
} else {
|
|
1436 |
// not current patchset
|
|
1437 |
String msg = MessageFormat.format("Can not merge ticket {0,number,0}, the patchset has been updated!", ticket.number);
|
|
1438 |
GitBlitWebSession.get().cacheErrorMessage(msg);
|
|
1439 |
logger.error(msg);
|
|
1440 |
}
|
47a544
|
1441 |
|
K |
1442 |
redirectTo(TicketsPage.class, getPageParameters());
|
5e3521
|
1443 |
}
|
JM |
1444 |
};
|
|
1445 |
mergePanel.add(mergeButton);
|
|
1446 |
Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetMergeableMore");
|
|
1447 |
mergePanel.add(instructions);
|
|
1448 |
} else {
|
|
1449 |
mergePanel.add(new Label("mergeButton").setVisible(false));
|
|
1450 |
mergePanel.add(new Label("mergeMore").setVisible(false));
|
|
1451 |
}
|
|
1452 |
return mergePanel;
|
|
1453 |
} else if (MergeStatus.ALREADY_MERGED == mergeStatus) {
|
|
1454 |
// patchset already merged
|
|
1455 |
Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
|
|
1456 |
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
|
|
1457 |
return mergePanel;
|
4a2fb1
|
1458 |
} else if (MergeStatus.MISSING_INTEGRATION_BRANCH == mergeStatus) {
|
JM |
1459 |
// target/integration branch is missing
|
|
1460 |
Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
|
|
1461 |
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
|
|
1462 |
mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.missingIntegrationBranchMore"), ticket.mergeTo)));
|
|
1463 |
return mergePanel;
|
5e3521
|
1464 |
} else {
|
JM |
1465 |
// patchset can not be cleanly merged
|
|
1466 |
Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
|
|
1467 |
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
|
|
1468 |
if (user.canPush(repository)) {
|
|
1469 |
// user can merge locally
|
|
1470 |
Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetNotMergeableMore");
|
|
1471 |
mergePanel.add(instructions);
|
|
1472 |
} else {
|
|
1473 |
mergePanel.add(new Label("mergeMore").setVisible(false));
|
|
1474 |
}
|
|
1475 |
return mergePanel;
|
|
1476 |
}
|
|
1477 |
} else {
|
|
1478 |
// merge not allowed
|
|
1479 |
if (MergeStatus.ALREADY_MERGED == mergeStatus) {
|
|
1480 |
// patchset already merged
|
|
1481 |
Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
|
|
1482 |
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
|
|
1483 |
return mergePanel;
|
|
1484 |
} else if (ticket.isVetoed(patchset)) {
|
|
1485 |
// patchset has been vetoed
|
|
1486 |
Fragment mergePanel = new Fragment("mergePanel", "vetoedFragment", this);
|
|
1487 |
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
|
|
1488 |
return mergePanel;
|
|
1489 |
} else if (repository.requireApproval) {
|
|
1490 |
// patchset has been not been approved for merge
|
|
1491 |
Fragment mergePanel = new Fragment("mergePanel", "notApprovedFragment", this);
|
|
1492 |
mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotApproved"), ticket.mergeTo)));
|
|
1493 |
mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.patchsetNotApprovedMore"), ticket.mergeTo)));
|
|
1494 |
return mergePanel;
|
|
1495 |
} else {
|
|
1496 |
// other case
|
|
1497 |
return new Label("mergePanel");
|
|
1498 |
}
|
|
1499 |
}
|
|
1500 |
}
|
|
1501 |
|
|
1502 |
protected Component getMergeInstructions(UserModel user, RepositoryModel repository, String markupId, String infoKey) {
|
|
1503 |
Fragment cmd = new Fragment(markupId, "commandlineMergeFragment", this);
|
|
1504 |
cmd.add(new Label("instructions", MessageFormat.format(getString(infoKey), ticket.mergeTo)));
|
|
1505 |
|
|
1506 |
// git instructions
|
|
1507 |
cmd.add(new Label("mergeStep1", MessageFormat.format(getString("gb.stepN"), 1)));
|
|
1508 |
cmd.add(new Label("mergeStep2", MessageFormat.format(getString("gb.stepN"), 2)));
|
|
1509 |
cmd.add(new Label("mergeStep3", MessageFormat.format(getString("gb.stepN"), 3)));
|
|
1510 |
|
|
1511 |
String ticketBranch = Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticket.number));
|
|
1512 |
String reviewBranch = PatchsetCommand.getReviewBranch(ticket.number);
|
|
1513 |
|
bf426b
|
1514 |
String step1 = MessageFormat.format("git checkout -b {0} {1}", reviewBranch, ticket.mergeTo);
|
JM |
1515 |
String step2 = MessageFormat.format("git pull origin {0}", ticketBranch);
|
|
1516 |
String step3 = MessageFormat.format("git checkout {0}\ngit merge {1}\ngit push origin {0}\ngit branch -d {1}", ticket.mergeTo, reviewBranch);
|
5e3521
|
1517 |
|
JM |
1518 |
cmd.add(new Label("mergePreStep1", step1));
|
|
1519 |
cmd.add(new Label("mergePreStep2", step2));
|
|
1520 |
cmd.add(new Label("mergePreStep3", step3));
|
|
1521 |
|
|
1522 |
cmd.add(createCopyFragment("mergeCopyStep1", step1.replace("\n", " && ")));
|
|
1523 |
cmd.add(createCopyFragment("mergeCopyStep2", step2.replace("\n", " && ")));
|
|
1524 |
cmd.add(createCopyFragment("mergeCopyStep3", step3.replace("\n", " && ")));
|
|
1525 |
|
|
1526 |
// pt instructions
|
|
1527 |
String ptStep = MessageFormat.format("pt pull {0,number,0}", ticket.number);
|
|
1528 |
cmd.add(new Label("ptMergeStep", ptStep));
|
|
1529 |
cmd.add(createCopyFragment("ptMergeCopyStep", step1.replace("\n", " && ")));
|
|
1530 |
return cmd;
|
|
1531 |
}
|
|
1532 |
|
|
1533 |
/**
|
|
1534 |
* Returns the primary repository url
|
|
1535 |
*
|
|
1536 |
* @param user
|
|
1537 |
* @param repository
|
|
1538 |
* @return the primary repository url
|
|
1539 |
*/
|
d85bfb
|
1540 |
protected RepositoryUrl getRepositoryUrl(UserModel user, RepositoryModel repository) {
|
5e3521
|
1541 |
HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();
|
7d3a31
|
1542 |
List<RepositoryUrl> urls = app().services().getRepositoryUrls(req, user, repository);
|
b236ce
|
1543 |
if (ArrayUtils.isEmpty(urls)) {
|
JM |
1544 |
return null;
|
|
1545 |
}
|
d85bfb
|
1546 |
RepositoryUrl primary = urls.get(0);
|
JM |
1547 |
return primary;
|
5e3521
|
1548 |
}
|
JM |
1549 |
|
|
1550 |
/**
|
|
1551 |
* Returns the ticket (if any) that this commit references.
|
|
1552 |
*
|
|
1553 |
* @param commit
|
|
1554 |
* @return null or a ticket
|
|
1555 |
*/
|
|
1556 |
protected TicketModel getTicket(RevCommit commit) {
|
|
1557 |
try {
|
|
1558 |
Map<String, Ref> refs = getRepository().getRefDatabase().getRefs(Constants.R_TICKETS_PATCHSETS);
|
|
1559 |
for (Map.Entry<String, Ref> entry : refs.entrySet()) {
|
|
1560 |
if (entry.getValue().getObjectId().equals(commit.getId())) {
|
|
1561 |
long id = PatchsetCommand.getTicketNumber(entry.getKey());
|
|
1562 |
TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), id);
|
|
1563 |
return ticket;
|
|
1564 |
}
|
|
1565 |
}
|
|
1566 |
} catch (Exception e) {
|
|
1567 |
logger().error("failed to determine ticket from ref", e);
|
|
1568 |
}
|
|
1569 |
return null;
|
|
1570 |
}
|
|
1571 |
|
|
1572 |
protected String getPatchsetTypeCss(PatchsetType type) {
|
|
1573 |
String typeCss;
|
|
1574 |
switch (type) {
|
|
1575 |
case Rebase:
|
|
1576 |
case Rebase_Squash:
|
fdd82f
|
1577 |
typeCss = TicketsUI.getLozengeClass(Status.Declined, false);
|
5e3521
|
1578 |
break;
|
JM |
1579 |
case Squash:
|
|
1580 |
case Amend:
|
fdd82f
|
1581 |
typeCss = TicketsUI.getLozengeClass(Status.On_Hold, false);
|
5e3521
|
1582 |
break;
|
JM |
1583 |
case Proposal:
|
fdd82f
|
1584 |
typeCss = TicketsUI.getLozengeClass(Status.New, false);
|
5e3521
|
1585 |
break;
|
JM |
1586 |
case FastForward:
|
|
1587 |
default:
|
|
1588 |
typeCss = null;
|
|
1589 |
break;
|
|
1590 |
}
|
|
1591 |
return typeCss;
|
|
1592 |
}
|
|
1593 |
|
|
1594 |
@Override
|
|
1595 |
protected String getPageName() {
|
|
1596 |
return getString("gb.ticket");
|
|
1597 |
}
|
|
1598 |
|
|
1599 |
@Override
|
|
1600 |
protected Class<? extends BasePage> getRepoNavPageClass() {
|
|
1601 |
return TicketsPage.class;
|
|
1602 |
}
|
|
1603 |
|
|
1604 |
@Override
|
|
1605 |
protected String getPageTitle(String repositoryName) {
|
|
1606 |
return "#" + ticket.number + " - " + ticket.title;
|
|
1607 |
}
|
|
1608 |
|
|
1609 |
protected Fragment createCopyFragment(String wicketId, String text) {
|
|
1610 |
if (app().settings().getBoolean(Keys.web.allowFlashCopyToClipboard, true)) {
|
|
1611 |
// clippy: flash-based copy & paste
|
|
1612 |
Fragment copyFragment = new Fragment(wicketId, "clippyPanel", this);
|
|
1613 |
String baseUrl = WicketUtils.getGitblitURL(getRequest());
|
|
1614 |
ShockWaveComponent clippy = new ShockWaveComponent("clippy", baseUrl + "/clippy.swf");
|
|
1615 |
clippy.setValue("flashVars", "text=" + StringUtils.encodeURL(text));
|
|
1616 |
copyFragment.add(clippy);
|
|
1617 |
return copyFragment;
|
|
1618 |
} else {
|
|
1619 |
// javascript: manual copy & paste with modal browser prompt dialog
|
|
1620 |
Fragment copyFragment = new Fragment(wicketId, "jsPanel", this);
|
|
1621 |
ContextImage img = WicketUtils.newImage("copyIcon", "clippy.png");
|
|
1622 |
img.add(new JavascriptTextPrompt("onclick", "Copy to Clipboard (Ctrl+C, Enter)", text));
|
|
1623 |
copyFragment.add(img);
|
|
1624 |
return copyFragment;
|
|
1625 |
}
|
|
1626 |
}
|
cd7e4f
|
1627 |
|
PM |
1628 |
private Link<Void> createDeletePatchsetLink(final RepositoryModel repositoryModel, final Patchset patchset)
|
|
1629 |
{
|
|
1630 |
Link<Void> deleteLink = new Link<Void>("deleteRevision") {
|
|
1631 |
private static final long serialVersionUID = 1L;
|
|
1632 |
|
|
1633 |
@Override
|
|
1634 |
public void onClick() {
|
|
1635 |
Repository r = app().repositories().getRepository(repositoryModel.name);
|
|
1636 |
UserModel user = GitBlitWebSession.get().getUser();
|
|
1637 |
|
|
1638 |
if (r == null) {
|
|
1639 |
if (app().repositories().isCollectingGarbage(repositoryModel.name)) {
|
|
1640 |
error(MessageFormat.format(getString("gb.busyCollectingGarbage"), repositoryModel.name));
|
|
1641 |
} else {
|
|
1642 |
error(MessageFormat.format("Failed to find repository {0}", repositoryModel.name));
|
|
1643 |
}
|
|
1644 |
return;
|
|
1645 |
}
|
|
1646 |
|
|
1647 |
//Construct the ref name based on the patchset
|
|
1648 |
String ticketShard = String.format("%02d", ticket.number);
|
|
1649 |
ticketShard = ticketShard.substring(ticketShard.length() - 2);
|
|
1650 |
final String refName = String.format("%s%s/%d/%d", Constants.R_TICKETS_PATCHSETS, ticketShard, ticket.number, patchset.number);
|
|
1651 |
|
|
1652 |
Ref ref = null;
|
|
1653 |
boolean success = true;
|
|
1654 |
|
|
1655 |
try {
|
|
1656 |
ref = r.getRef(refName);
|
|
1657 |
|
|
1658 |
if (ref != null) {
|
|
1659 |
success = JGitUtils.deleteBranchRef(r, ref.getName());
|
|
1660 |
} else {
|
|
1661 |
success = false;
|
|
1662 |
}
|
|
1663 |
|
|
1664 |
if (success) {
|
|
1665 |
// clear commit cache
|
|
1666 |
CommitCache.instance().clear(repositoryModel.name, refName);
|
|
1667 |
|
|
1668 |
// optionally update reflog
|
|
1669 |
if (RefLogUtils.hasRefLogBranch(r)) {
|
|
1670 |
RefLogUtils.deleteRef(user, r, ref);
|
|
1671 |
}
|
|
1672 |
|
|
1673 |
TicketModel updatedTicket = app().tickets().deletePatchset(ticket, patchset, user.username);
|
|
1674 |
|
|
1675 |
if (updatedTicket == null) {
|
|
1676 |
success = false;
|
|
1677 |
}
|
|
1678 |
}
|
|
1679 |
} catch (IOException e) {
|
|
1680 |
logger().error("failed to determine ticket from ref", e);
|
|
1681 |
success = false;
|
|
1682 |
} finally {
|
|
1683 |
r.close();
|
|
1684 |
}
|
|
1685 |
|
|
1686 |
if (success) {
|
|
1687 |
getSession().info(MessageFormat.format(getString("gb.deletePatchsetSuccess"), patchset.number));
|
|
1688 |
logger().info(MessageFormat.format("{0} deleted patchset {1} from ticket {2}",
|
|
1689 |
user.username, patchset.number, ticket.number));
|
|
1690 |
} else {
|
|
1691 |
getSession().error(MessageFormat.format(getString("gb.deletePatchsetFailure"),patchset.number));
|
|
1692 |
}
|
|
1693 |
|
|
1694 |
//Force reload of the page to rebuild ticket change cache
|
|
1695 |
String relativeUrl = urlFor(TicketsPage.class, getPageParameters()).toString();
|
|
1696 |
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
|
|
1697 |
setResponsePage(new RedirectPage(absoluteUrl));
|
|
1698 |
}
|
|
1699 |
};
|
|
1700 |
|
|
1701 |
WicketUtils.setHtmlTooltip(deleteLink, MessageFormat.format(getString("gb.deletePatchset"), patchset.number));
|
|
1702 |
|
|
1703 |
deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(getString("gb.deletePatchset"), patchset.number)));
|
|
1704 |
|
|
1705 |
return deleteLink;
|
|
1706 |
}
|
|
1707 |
|
5e3521
|
1708 |
}
|