Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Ticket tracker with patchset contributions A basic issue tracker styled as a hybrid of GitHub and BitBucket issues. You may attach commits to an existing ticket or you can push a single commit to create a *proposal* ticket. Tickets keep track of patchsets (one or more commits) and allow patchset rewriting (rebase, amend, squash) by detecing the non-fast-forward update and assigning a new patchset number to the new commits. Ticket tracker -------------- The ticket tracker stores tickets as an append-only journal of changes. The journals are deserialized and a ticket is built by applying the journal entries. Tickets are indexed using Apache Lucene and all queries and searches are executed against this Lucene index. There is one trade-off to this persistence design: user attributions are non-relational. What does that mean? Each journal entry stores the username of the author. If the username changes in the user service, the journal entry will not reflect that change because the values are hard-coded. Here are a few reasons/justifications for this design choice: 1. commit identifications (author, committer, tagger) are non-relational 2. maintains the KISS principle 3. your favorite text editor can still be your administration tool Persistence Choices ------------------- **FileTicketService**: stores journals on the filesystem **BranchTicketService**: stores journals on an orphan branch **RedisTicketService**: stores journals in a Redis key-value datastore It should be relatively straight-forward to develop other backends (MongoDB, etc) as long as the journal design is preserved. Pushing Commits --------------- Each push to a ticket is identified as a patchset revision. A patchset revision may add commits to the patchset (fast-forward) OR a patchset revision may rewrite history (rebase, squash, rebase+squash, or amend). Patchset authors should not be afraid to polish, revise, and rewrite their code before merging into the proposed branch. Gitblit will create one ref for each patchset. These refs are updated for fast-forward pushes or created for rewrites. They are formatted as `refs/tickets/{shard}/{id}/{patchset}`. The *shard* is the last two digits of the id. If the id < 10, prefix a 0. The *shard* is always two digits long. The shard's purpose is to ensure Gitblit doesn't exceed any filesystem directory limits for file creation. **Creating a Proposal Ticket** You may create a new change proposal ticket just by pushing a **single commit** to `refs/for/{branch}` where branch is the proposed integration branch OR `refs/for/new` or `refs/for/default` which both will use the default repository branch. git push origin HEAD:refs/for/new **Updating a Patchset** The safe way to update an existing patchset is to push to the patchset ref. git push origin HEAD:refs/heads/ticket/{id} This ensures you do not accidentally create a new patchset in the event that the patchset was updated after you last pulled. The not-so-safe way to update an existing patchset is to push using the magic ref. git push origin HEAD:refs/for/{id} This push ref will update an exisitng patchset OR create a new patchset if the update is non-fast-forward. **Rebasing, Squashing, Amending** Gitblit makes rebasing, squashing, and amending patchsets easy. Normally, pushing a non-fast-forward update would require rewind (RW+) repository permissions. Gitblit provides a magic ref which will allow ticket participants to rewrite a ticket patchset as long as the ticket is open. git push origin HEAD:refs/for/{id} Pushing changes to this ref allows the patchset authors to rebase, squash, or amend the patchset commits without requiring client-side use of the *--force* flag on push AND without requiring RW+ permission to the repository. Since each patchset is tracked with a ref it is easy to recover from accidental non-fast-forward updates. Features -------- - Ticket tracker with status changes and responsible assignments - Patchset revision scoring mechanism - Update/Rewrite patchset handling - Close-on-push detection - Server-side Merge button for simple merges - Comments with Markdown syntax support - Rich mail notifications - Voting - Mentions - Watch lists - Querying - Searches - Partial miletones support - Multiple backend options
10 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright 2013 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.panels;
  17. import java.text.DateFormat;
  18. import java.text.MessageFormat;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.List;
  23. import java.util.TimeZone;
  24. import org.apache.wicket.markup.html.basic.Label;
  25. import org.apache.wicket.markup.repeater.Item;
  26. import org.apache.wicket.markup.repeater.data.DataView;
  27. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  28. import org.eclipse.jgit.lib.PersonIdent;
  29. import com.gitblit.Constants;
  30. import com.gitblit.Keys;
  31. import com.gitblit.models.DailyLogEntry;
  32. import com.gitblit.models.RepositoryCommit;
  33. import com.gitblit.utils.StringUtils;
  34. import com.gitblit.utils.TimeUtils;
  35. import com.gitblit.wicket.WicketUtils;
  36. import com.gitblit.wicket.pages.CommitPage;
  37. import com.gitblit.wicket.pages.ComparePage;
  38. import com.gitblit.wicket.pages.SummaryPage;
  39. import com.gitblit.wicket.pages.TagPage;
  40. import com.gitblit.wicket.pages.TicketsPage;
  41. import com.gitblit.wicket.pages.TreePage;
  42. public class DigestsPanel extends BasePanel {
  43. private static final long serialVersionUID = 1L;
  44. private final boolean hasChanges;
  45. private boolean hasMore;
  46. public DigestsPanel(String wicketId, List<DailyLogEntry> digests) {
  47. super(wicketId);
  48. hasChanges = digests.size() > 0;
  49. ListDataProvider<DailyLogEntry> dp = new ListDataProvider<DailyLogEntry>(digests);
  50. DataView<DailyLogEntry> pushView = new DataView<DailyLogEntry>("change", dp) {
  51. private static final long serialVersionUID = 1L;
  52. @Override
  53. public void populateItem(final Item<DailyLogEntry> logItem) {
  54. final DailyLogEntry change = logItem.getModelObject();
  55. String dateFormat = app().settings().getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
  56. TimeZone timezone = getTimeZone();
  57. DateFormat df = new SimpleDateFormat(dateFormat);
  58. df.setTimeZone(timezone);
  59. String fullRefName = change.getChangedRefs().get(0);
  60. String shortRefName = fullRefName;
  61. String ticketId = "";
  62. boolean isTag = false;
  63. boolean isTicket = false;
  64. if (shortRefName.startsWith(Constants.R_TICKET)) {
  65. ticketId = shortRefName = shortRefName.substring(Constants.R_TICKET.length());
  66. shortRefName = MessageFormat.format(getString("gb.ticketN"), ticketId);
  67. isTicket = true;
  68. } else if (shortRefName.startsWith(Constants.R_HEADS)) {
  69. shortRefName = shortRefName.substring(Constants.R_HEADS.length());
  70. } else if (shortRefName.startsWith(Constants.R_TAGS)) {
  71. shortRefName = shortRefName.substring(Constants.R_TAGS.length());
  72. isTag = true;
  73. }
  74. String fuzzydate;
  75. TimeUtils tu = getTimeUtils();
  76. Date pushDate = change.date;
  77. if (TimeUtils.isToday(pushDate, timezone)) {
  78. fuzzydate = tu.today();
  79. } else if (TimeUtils.isYesterday(pushDate, timezone)) {
  80. fuzzydate = tu.yesterday();
  81. } else {
  82. fuzzydate = getTimeUtils().timeAgo(pushDate);
  83. }
  84. logItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(pushDate)));
  85. Label changeIcon = new Label("changeIcon");
  86. // use the repository hash color to differentiate the icon.
  87. String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
  88. WicketUtils.setCssStyle(changeIcon, "color: " + color);
  89. if (isTag) {
  90. WicketUtils.setCssClass(changeIcon, "iconic-tag");
  91. } else if (isTicket) {
  92. WicketUtils.setCssClass(changeIcon, "fa fa-ticket");
  93. } else {
  94. WicketUtils.setCssClass(changeIcon, "iconic-loop");
  95. }
  96. logItem.add(changeIcon);
  97. if (isTag) {
  98. // tags are special
  99. PersonIdent ident = change.getCommits().get(0).getAuthorIdent();
  100. if (!StringUtils.isEmpty(ident.getName())) {
  101. logItem.add(new Label("whoChanged", ident.getName()));
  102. } else {
  103. logItem.add(new Label("whoChanged", ident.getEmailAddress()));
  104. }
  105. } else {
  106. logItem.add(new Label("whoChanged").setVisible(false));
  107. }
  108. String preposition = "gb.of";
  109. boolean isDelete = false;
  110. String what;
  111. String by = null;
  112. switch(change.getChangeType(fullRefName)) {
  113. case CREATE:
  114. if (isTag) {
  115. // new tag
  116. what = getString("gb.createdNewTag");
  117. preposition = "gb.in";
  118. } else {
  119. // new branch
  120. what = getString("gb.createdNewBranch");
  121. preposition = "gb.in";
  122. }
  123. break;
  124. case DELETE:
  125. isDelete = true;
  126. if (isTag) {
  127. what = getString("gb.deletedTag");
  128. } else {
  129. what = getString("gb.deletedBranch");
  130. }
  131. preposition = "gb.from";
  132. break;
  133. default:
  134. what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.commitsTo") : getString("gb.oneCommitTo"), change.getCommitCount());
  135. if (change.getAuthorCount() == 1) {
  136. by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
  137. } else {
  138. by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
  139. }
  140. break;
  141. }
  142. logItem.add(new Label("whatChanged", what));
  143. logItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
  144. if (isDelete) {
  145. // can't link to deleted ref
  146. logItem.add(new Label("refChanged", shortRefName));
  147. } else if (isTag) {
  148. // link to tag
  149. logItem.add(new LinkPanel("refChanged", null, shortRefName,
  150. TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
  151. } else if (isTicket) {
  152. // link to ticket
  153. logItem.add(new LinkPanel("refChanged", null, shortRefName,
  154. TicketsPage.class, WicketUtils.newObjectParameter(change.repository, ticketId)));
  155. } else {
  156. // link to tree
  157. logItem.add(new LinkPanel("refChanged", null, shortRefName,
  158. TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
  159. }
  160. // to/from/etc
  161. logItem.add(new Label("repoPreposition", getString(preposition)));
  162. String repoName = StringUtils.stripDotGit(change.repository);
  163. logItem.add(new LinkPanel("repoChanged", null, repoName,
  164. SummaryPage.class, WicketUtils.newRepositoryParameter(change.repository)));
  165. int maxCommitCount = 5;
  166. List<RepositoryCommit> commits = change.getCommits();
  167. if (commits.size() > maxCommitCount) {
  168. commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
  169. }
  170. // compare link
  171. String compareLinkText = null;
  172. if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
  173. compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
  174. } else if (change.getCommitCount() > maxCommitCount) {
  175. int diff = change.getCommitCount() - maxCommitCount;
  176. compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
  177. }
  178. if (StringUtils.isEmpty(compareLinkText)) {
  179. logItem.add(new Label("compareLink").setVisible(false));
  180. } else {
  181. String endRangeId = change.getNewId(fullRefName);
  182. String startRangeId = change.getOldId(fullRefName);
  183. logItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
  184. }
  185. final boolean showSwatch = app().settings().getBoolean(Keys.web.repositoryListSwatches, true);
  186. ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
  187. DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {
  188. private static final long serialVersionUID = 1L;
  189. @Override
  190. public void populateItem(final Item<RepositoryCommit> commitItem) {
  191. final RepositoryCommit commit = commitItem.getModelObject();
  192. // author gravatar
  193. commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
  194. // merge icon
  195. if (commit.getParentCount() > 1) {
  196. commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
  197. } else {
  198. commitItem.add(WicketUtils.newBlankImage("commitIcon"));
  199. }
  200. // short message
  201. String shortMessage = commit.getShortMessage();
  202. String trimmedMessage = shortMessage;
  203. if (commit.getRefs() != null && commit.getRefs().size() > 0) {
  204. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
  205. } else {
  206. trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
  207. }
  208. LinkPanel shortlog = new LinkPanel("commitShortMessage", "list",
  209. trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
  210. change.repository, commit.getName()));
  211. if (!shortMessage.equals(trimmedMessage)) {
  212. WicketUtils.setHtmlTooltip(shortlog, shortMessage);
  213. }
  214. commitItem.add(shortlog);
  215. // commit hash link
  216. int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
  217. LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen),
  218. CommitPage.class, WicketUtils.newObjectParameter(
  219. change.repository, commit.getName()));
  220. WicketUtils.setCssClass(commitHash, "shortsha1");
  221. WicketUtils.setHtmlTooltip(commitHash, commit.getName());
  222. commitItem.add(commitHash);
  223. if (showSwatch) {
  224. // set repository color
  225. String color = StringUtils.getColor(StringUtils.stripDotGit(change.repository));
  226. WicketUtils.setCssStyle(commitItem, MessageFormat.format("border-left: 2px solid {0};", color));
  227. }
  228. }
  229. };
  230. logItem.add(commitsView);
  231. }
  232. };
  233. add(pushView);
  234. }
  235. public boolean hasMore() {
  236. return hasMore;
  237. }
  238. public boolean hideIfEmpty() {
  239. setVisible(hasChanges);
  240. return hasChanges;
  241. }
  242. }