From c134a0c3f2440a09c5b8c8c6837c95aba3d4f84f Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 8 Mar 2014 11:27:00 -0500 Subject: Move Gitblit branches to refs/meta/gitblit --- src/main/java/com/gitblit/Constants.java | 2 +- .../java/com/gitblit/service/LuceneService.java | 8 +- .../com/gitblit/tickets/BranchTicketService.java | 28 ++++- src/main/java/com/gitblit/utils/RefLogUtils.java | 118 ++++++++++----------- .../java/com/gitblit/wicket/panels/RefsPanel.java | 6 +- src/site/tickets_replication.mkd | 12 +-- src/site/tickets_setup.mkd | 2 +- 7 files changed, 100 insertions(+), 76 deletions(-) (limited to 'src') diff --git a/src/main/java/com/gitblit/Constants.java b/src/main/java/com/gitblit/Constants.java index e93f7b1d..2a98b53f 100644 --- a/src/main/java/com/gitblit/Constants.java +++ b/src/main/java/com/gitblit/Constants.java @@ -100,7 +100,7 @@ public class Constants { public static final String HEAD = "HEAD"; - public static final String R_GITBLIT = "refs/gitblit/"; + public static final String R_META = "refs/meta/"; public static final String R_HEADS = "refs/heads/"; diff --git a/src/main/java/com/gitblit/service/LuceneService.java b/src/main/java/com/gitblit/service/LuceneService.java index 70e3b244..714a1e29 100644 --- a/src/main/java/com/gitblit/service/LuceneService.java +++ b/src/main/java/com/gitblit/service/LuceneService.java @@ -476,8 +476,8 @@ public class LuceneService implements Runnable { && branch.equals(defaultBranch)) { // indexing "default" branch indexBranch = true; - } else if (branch.getName().startsWith(com.gitblit.Constants.R_GITBLIT)) { - // skip Gitblit internal branches + } else if (branch.getName().startsWith(com.gitblit.Constants.R_META)) { + // skip internal meta branches indexBranch = false; } else { // normal explicit branch check @@ -807,8 +807,8 @@ public class LuceneService implements Runnable { && branch.equals(defaultBranch)) { // indexing "default" branch indexBranch = true; - } else if (branch.getName().startsWith(com.gitblit.Constants.R_GITBLIT)) { - // ignore internal Gitblit branches + } else if (branch.getName().startsWith(com.gitblit.Constants.R_META)) { + // ignore internal meta branches indexBranch = false; } else { // normal explicit branch check diff --git a/src/main/java/com/gitblit/tickets/BranchTicketService.java b/src/main/java/com/gitblit/tickets/BranchTicketService.java index a25dac84..0f71d864 100644 --- a/src/main/java/com/gitblit/tickets/BranchTicketService.java +++ b/src/main/java/com/gitblit/tickets/BranchTicketService.java @@ -43,6 +43,8 @@ import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.RefRename; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.Repository; @@ -80,7 +82,7 @@ import com.gitblit.utils.StringUtils; */ public class BranchTicketService extends ITicketService implements RefsChangedListener { - public static final String BRANCH = "refs/gitblit/tickets"; + public static final String BRANCH = "refs/meta/gitblit/tickets"; private static final String JOURNAL = "journal.json"; @@ -193,10 +195,32 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi * @return a refmodel for the gitblit tickets branch or null */ private RefModel getTicketsBranch(Repository db) { - List refs = JGitUtils.getRefs(db, Constants.R_GITBLIT); + List refs = JGitUtils.getRefs(db, "refs/"); + Ref oldRef = null; for (RefModel ref : refs) { if (ref.reference.getName().equals(BRANCH)) { return ref; + } else if (ref.reference.getName().equals("refs/gitblit/tickets")) { + oldRef = ref.reference; + } + } + if (oldRef != null) { + // rename old ref to refs/meta/gitblit/tickets + RefRename cmd; + try { + cmd = db.renameRef(oldRef.getName(), BRANCH); + cmd.setRefLogIdent(new PersonIdent("Gitblit", "gitblit@localhost")); + cmd.setRefLogMessage("renamed " + oldRef.getName() + " => " + BRANCH); + Result res = cmd.rename(); + switch (res) { + case RENAMED: + log.info(db.getDirectory() + " " + cmd.getRefLogMessage()); + return getTicketsBranch(db); + default: + log.error("failed to rename " + oldRef.getName() + " => " + BRANCH + " (" + res.name() + ")"); + } + } catch (IOException e) { + log.error("failed to rename tickets branch", e); } } return null; diff --git a/src/main/java/com/gitblit/utils/RefLogUtils.java b/src/main/java/com/gitblit/utils/RefLogUtils.java index a87579ff..f08c99e7 100644 --- a/src/main/java/com/gitblit/utils/RefLogUtils.java +++ b/src/main/java/com/gitblit/utils/RefLogUtils.java @@ -72,7 +72,7 @@ import com.gitblit.models.UserModel; */ public class RefLogUtils { - private static final String GB_REFLOG = "refs/gitblit/reflog"; + private static final String GB_REFLOG = "refs/meta/gitblit/reflog"; private static final Logger LOGGER = LoggerFactory.getLogger(RefLogUtils.class); @@ -122,32 +122,34 @@ public class RefLogUtils { * @return a refmodel for the reflog branch or null */ public static RefModel getRefLogBranch(Repository repository) { - List refs = JGitUtils.getRefs(repository, com.gitblit.Constants.R_GITBLIT); - RefModel pushLog = null; - final String GB_PUSHES = "refs/gitblit/pushes"; + List refs = JGitUtils.getRefs(repository, "refs/"); + Ref oldRef = null; for (RefModel ref : refs) { if (ref.reference.getName().equals(GB_REFLOG)) { return ref; - } else if (ref.reference.getName().equals(GB_PUSHES)) { - pushLog = ref; + } else if (ref.reference.getName().equals("refs/gitblit/reflog")) { + oldRef = ref.reference; + } else if (ref.reference.getName().equals("refs/gitblit/pushes")) { + oldRef = ref.reference; } } - if (pushLog != null) { - // rename refs/gitblit/pushes to refs/gitblit/reflog + if (oldRef != null) { + // rename old ref to refs/meta/gitblit/reflog RefRename cmd; try { - cmd = repository.renameRef(GB_PUSHES, GB_REFLOG); + cmd = repository.renameRef(oldRef.getName(), GB_REFLOG); cmd.setRefLogIdent(new PersonIdent("Gitblit", "gitblit@localhost")); - cmd.setRefLogMessage("renamed " + GB_PUSHES + " => " + GB_REFLOG); + cmd.setRefLogMessage("renamed " + oldRef.getName() + " => " + GB_REFLOG); Result res = cmd.rename(); switch (res) { case RENAMED: + LOGGER.info(repository.getDirectory() + " " + cmd.getRefLogMessage()); return getRefLogBranch(repository); default: - LOGGER.error("failed to rename " + GB_PUSHES + " => " + GB_REFLOG + " (" + res.name() + ")"); + LOGGER.error("failed to rename " + oldRef.getName() + " => " + GB_REFLOG + " (" + res.name() + ")"); } } catch (IOException e) { - LOGGER.error("failed to rename pushlog", e); + LOGGER.error("failed to rename reflog", e); } } return null; @@ -241,7 +243,7 @@ public class RefLogUtils { ObjectId headId = repository.resolve(GB_REFLOG + "^{commit}"); ObjectInserter odi = repository.newObjectInserter(); try { - // Create the in-memory index of the push log entry + // Create the in-memory index of the reflog log entry DirCache index = createIndex(repository, headId, commands); ObjectId indexTreeId = index.writeTree(odi); @@ -304,7 +306,7 @@ public class RefLogUtils { } /** - * Creates an in-memory index of the push log entry. + * Creates an in-memory index of the reflog entry. * * @param repo * @param headId @@ -428,8 +430,8 @@ public class RefLogUtils { * @param minimumDate * @param offset * @param maxCount - * if < 0, all pushes are returned. - * @return a list of push log entries + * if < 0, all entries are returned. + * @return a list of reflog entries */ public static List getRefLog(String repositoryName, Repository repository, Date minimumDate, int offset, int maxCount) { @@ -507,31 +509,31 @@ public class RefLogUtils { } /** - * Returns the list of pushes separated by ref (e.g. each ref has it's own - * PushLogEntry object). + * Returns the list of entries organized by ref (e.g. each ref has it's own + * RefLogEntry object). * * @param repositoryName * @param repository * @param maxCount - * @return a list of push log entries separated by ref + * @return a list of reflog entries separated by ref */ public static List getLogByRef(String repositoryName, Repository repository, int maxCount) { return getLogByRef(repositoryName, repository, 0, maxCount); } /** - * Returns the list of pushes separated by ref (e.g. each ref has it's own - * PushLogEntry object). + * Returns the list of entries organized by ref (e.g. each ref has it's own + * RefLogEntry object). * * @param repositoryName * @param repository * @param offset * @param maxCount - * @return a list of push log entries separated by ref + * @return a list of reflog entries separated by ref */ public static List getLogByRef(String repositoryName, Repository repository, int offset, int maxCount) { - // break the push log into ref push logs and then merge them back into a list + // break the reflog into ref entries and then merge them back into a list Map> refMap = new HashMap>(); List refLog = getRefLog(repositoryName, repository, offset, maxCount); for (RefLogEntry entry : refLog) { @@ -543,10 +545,10 @@ public class RefLogUtils { // construct new ref-specific ref change entry RefLogEntry refChange; if (entry instanceof DailyLogEntry) { - // simulated push log from commits grouped by date + // simulated reflog from commits grouped by date refChange = new DailyLogEntry(entry.repository, entry.date); } else { - // real push log entry + // real reflog entry refChange = new RefLogEntry(entry.repository, entry.date, entry.user); } refChange.updateRef(ref, entry.getChangeType(ref), entry.getOldId(ref), entry.getNewId(ref)); @@ -577,33 +579,32 @@ public class RefLogUtils { * @return a list of ref log entries separated by ref */ public static List getLogByRef(String repositoryName, Repository repository, Date minimumDate) { - // break the push log into ref push logs and then merge them back into a list + // break the reflog into refs and then merge them back into a list Map> refMap = new HashMap>(); - List pushes = getRefLog(repositoryName, repository, minimumDate); - for (RefLogEntry push : pushes) { - for (String ref : push.getChangedRefs()) { + List entries = getRefLog(repositoryName, repository, minimumDate); + for (RefLogEntry entry : entries) { + for (String ref : entry.getChangedRefs()) { if (!refMap.containsKey(ref)) { refMap.put(ref, new ArrayList()); } - // construct new ref-specific push log entry - RefLogEntry refPush = new RefLogEntry(push.repository, push.date, push.user); - refPush.updateRef(ref, push.getChangeType(ref), push.getOldId(ref), push.getNewId(ref)); - refPush.addCommits(push.getCommits(ref)); + // construct new ref-specific log entry + RefLogEntry refPush = new RefLogEntry(entry.repository, entry.date, entry.user); + refPush.updateRef(ref, entry.getChangeType(ref), entry.getOldId(ref), entry.getNewId(ref)); + refPush.addCommits(entry.getCommits(ref)); refMap.get(ref).add(refPush); } } - // merge individual ref pushes into master list - List refPushLog = new ArrayList(); - for (List refPush : refMap.values()) { - refPushLog.addAll(refPush); + // merge individual ref entries into master list + List refLog = new ArrayList(); + for (List entry : refMap.values()) { + refLog.addAll(entry); } - // sort ref push log - Collections.sort(refPushLog); + Collections.sort(refLog); - return refPushLog; + return refLog; } /** @@ -614,7 +615,7 @@ public class RefLogUtils { * @param minimumDate * @param offset * @param maxCount - * if < 0, all pushes are returned. + * if < 0, all entries are returned. * @param the timezone to use when aggregating commits by date * @return a list of grouped commit log entries */ @@ -703,7 +704,7 @@ public class RefLogUtils { /** * Returns the list of commits separated by ref (e.g. each ref has it's own - * PushLogEntry object for each day). + * RefLogEntry object for each day). * * @param repositoryName * @param repository @@ -713,36 +714,35 @@ public class RefLogUtils { */ public static List getDailyLogByRef(String repositoryName, Repository repository, Date minimumDate, TimeZone timezone) { - // break the push log into ref push logs and then merge them back into a list + // break the reflog into ref entries and then merge them back into a list Map> refMap = new HashMap>(); - List pushes = getDailyLog(repositoryName, repository, minimumDate, 0, -1, timezone); - for (DailyLogEntry push : pushes) { - for (String ref : push.getChangedRefs()) { + List entries = getDailyLog(repositoryName, repository, minimumDate, 0, -1, timezone); + for (DailyLogEntry entry : entries) { + for (String ref : entry.getChangedRefs()) { if (!refMap.containsKey(ref)) { refMap.put(ref, new ArrayList()); } - // construct new ref-specific push log entry - DailyLogEntry refPush = new DailyLogEntry(push.repository, push.date, push.user); - refPush.updateRef(ref, push.getChangeType(ref), push.getOldId(ref), push.getNewId(ref)); - refPush.addCommits(push.getCommits(ref)); - refMap.get(ref).add(refPush); + // construct new ref-specific log entry + DailyLogEntry refEntry = new DailyLogEntry(entry.repository, entry.date, entry.user); + refEntry.updateRef(ref, entry.getChangeType(ref), entry.getOldId(ref), entry.getNewId(ref)); + refEntry.addCommits(entry.getCommits(ref)); + refMap.get(ref).add(refEntry); } } - // merge individual ref pushes into master list - List refPushLog = new ArrayList(); - for (List refPush : refMap.values()) { - for (DailyLogEntry entry : refPush) { + // merge individual ref entries into master list + List refLog = new ArrayList(); + for (List refEntry : refMap.values()) { + for (DailyLogEntry entry : refEntry) { if (entry.getCommitCount() > 0) { - refPushLog.add(entry); + refLog.add(entry); } } } - // sort ref push log - Collections.sort(refPushLog); + Collections.sort(refLog); - return refPushLog; + return refLog; } } diff --git a/src/main/java/com/gitblit/wicket/panels/RefsPanel.java b/src/main/java/com/gitblit/wicket/panels/RefsPanel.java index 6e9e866e..8d21086d 100644 --- a/src/main/java/com/gitblit/wicket/panels/RefsPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RefsPanel.java @@ -173,11 +173,11 @@ public class RefsPanel extends BasePanel { // codereview refs linkClass = CommitPage.class; cssClass = "otherRef"; - } else if (name.startsWith(com.gitblit.Constants.R_GITBLIT)) { - // gitblit refs + } else if (name.startsWith(com.gitblit.Constants.R_META)) { + // internal meta refs linkClass = LogPage.class; cssClass = "otherRef"; - name = name.substring(com.gitblit.Constants.R_GITBLIT.length()); + name = name.substring(com.gitblit.Constants.R_META.length()); } Component c = new LinkPanel("refName", null, name, linkClass, diff --git a/src/site/tickets_replication.mkd b/src/site/tickets_replication.mkd index 542fd5fc..472c7270 100644 --- a/src/site/tickets_replication.mkd +++ b/src/site/tickets_replication.mkd @@ -23,7 +23,7 @@ After you've done this, you will need to reset Gitblit's internal ticket cache a #### Ticket Replication Gitblit supports ticket replication for a couple of scenarios with the *BranchTicketService*. This requires that the Gitblit instance receiving the ticket data be configured for the *BranchTicketService*. Likewise, the source of the ticket data must be a repository that has ticket data persisted using the *BranchTicketService*. -##### Manually Pushing refs/gitblit/tickets +##### Manually Pushing refs/meta/gitblit/tickets Let's say you wanted to create a perfect clone of the Gitblit repository hosted at https://dev.gitblit.com in your own Gitblit instance. We'll use this repository as an example because it is configured for the *BranchTicketService*. @@ -41,7 +41,7 @@ Let's say you wanted to create a perfect clone of the Gitblit repository hosted If your push was successful you should have a new repository with the entire official Gitblit tickets data. -##### Mirroring refs/gitblit/tickets +##### Mirroring refs/meta/gitblit/tickets Gitblit 1.4.0 introduces a mirroring service. This is not the same as the federation feature - although there are similarities. @@ -55,16 +55,16 @@ If you setup a mirror of another Gitblit repository which uses the *BranchTicket 4. After you have indexed the repository, Gitblit will take over and incrementally update your tickets data on each fetch. #### Advanced Administration -Repository owners or Gitblit administrators have the option of manually editing ticket data. To do this you must fetch and checkout the `refs/gitblit/tickets` ref. This orphan branch is where ticket data is stored. You may then use a text editor to **carefully** manipulate journals and push your changes back upstream. I recommend using a JSON validation tool to ensure your changes are valid JSON. +Repository owners or Gitblit administrators have the option of manually editing ticket data. To do this you must fetch and checkout the `refs/meta/gitblit/tickets` ref. This orphan branch is where ticket data is stored. You may then use a text editor to **carefully** manipulate journals and push your changes back upstream. I recommend using a JSON validation tool to ensure your changes are valid JSON. - git fetch origin refs/gitblit/tickets + git fetch origin refs/meta/gitblit/tickets git checkout -B tix FETCH_HEAD ...fix data... git add . git commit - git push origin HEAD:refs/gitblit/tickets + git push origin HEAD:refs/meta/gitblit/tickets -Gitblit will identify the incoming `refs/gitblit/tickets` ref update and will incrementally index the changed tickets OR, if the update is non-fast-forward, all tickets on that branch will be reindexed. +Gitblit will identify the incoming `refs/meta/gitblit/tickets` ref update and will incrementally index the changed tickets OR, if the update is non-fast-forward, all tickets on that branch will be reindexed. ### RedisTicketService diff --git a/src/site/tickets_setup.mkd b/src/site/tickets_setup.mkd index ee27b44a..c098f4c1 100644 --- a/src/site/tickets_setup.mkd +++ b/src/site/tickets_setup.mkd @@ -20,7 +20,7 @@ Your ticket journals are persisted to `tickets/{shard}/{id}/journal.json`. Thes tickets.service = com.gitblit.tickets.BranchTicketService -Your ticket journals are persisted to `id/{shard}/{id}/journal.json`. These journals are stored on an orphan branch, `refs/gitblit/tickets`, within your repository. This allows you to easily clone your entire ticket history to client working copies or to mirrors. +Your ticket journals are persisted to `id/{shard}/{id}/journal.json`. These journals are stored on an orphan branch, `refs/meta/gitblit/tickets`, within your repository. This allows you to easily clone your entire ticket history to client working copies or to mirrors. #### Redis Ticket Service -- cgit v1.2.3 From cc1c3ffa7d261d2e8bcdc600253528e8d09e1d06 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 8 Mar 2014 11:53:01 -0500 Subject: Allow selection of integration branch in new ticket page --- src/main/java/com/gitblit/models/UserModel.java | 12 ++- .../com/gitblit/wicket/pages/EditTicketPage.java | 114 +++++++++++---------- .../com/gitblit/wicket/pages/NewTicketPage.html | 5 + .../com/gitblit/wicket/pages/NewTicketPage.java | 31 +++++- .../java/com/gitblit/wicket/pages/TicketPage.java | 2 +- 5 files changed, 104 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/main/java/com/gitblit/models/UserModel.java b/src/main/java/com/gitblit/models/UserModel.java index fee9c172..675835d3 100644 --- a/src/main/java/com/gitblit/models/UserModel.java +++ b/src/main/java/com/gitblit/models/UserModel.java @@ -449,9 +449,15 @@ public class UserModel implements Principal, Serializable, Comparable public boolean canEdit(TicketModel ticket, RepositoryModel repository) { return isAuthenticated() && - (username.equals(ticket.createdBy) - || username.equals(ticket.responsible) - || canPush(repository)); + (canPush(repository) + || (ticket != null && username.equals(ticket.responsible)) + || (ticket != null && username.equals(ticket.createdBy))); + } + + public boolean canAdmin(TicketModel ticket, RepositoryModel repository) { + return isAuthenticated() && + (canPush(repository) + || ticket != null && username.equals(ticket.responsible)); } public boolean canReviewPatchset(RepositoryModel model) { diff --git a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java index ac759589..b5004861 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java @@ -250,71 +250,77 @@ public class EditTicketPage extends RepositoryPage { status.add(new DropDownChoice("status", statusModel, statusChoices)); form.add(status); - // responsible - Set userlist = new TreeSet(ticket.getParticipants()); + if (currentUser.canAdmin(ticket, getRepositoryModel())) { + // responsible + Set userlist = new TreeSet(ticket.getParticipants()); - for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) { - if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) { - userlist.add(rp.registrant); + for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) { + if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) { + userlist.add(rp.registrant); + } } - } - List responsibles = new ArrayList(); - for (String username : userlist) { - UserModel user = app().users().getUserModel(username); - if (user != null) { - TicketResponsible responsible = new TicketResponsible(user); - responsibles.add(responsible); - if (user.username.equals(ticket.responsible)) { - responsibleModel.setObject(responsible); + List responsibles = new ArrayList(); + for (String username : userlist) { + UserModel user = app().users().getUserModel(username); + if (user != null) { + TicketResponsible responsible = new TicketResponsible(user); + responsibles.add(responsible); + if (user.username.equals(ticket.responsible)) { + responsibleModel.setObject(responsible); + } } } - } - Collections.sort(responsibles); - responsibles.add(new TicketResponsible(NIL, "", "")); - Fragment responsible = new Fragment("responsible", "responsibleFragment", this); - responsible.add(new DropDownChoice("responsible", responsibleModel, responsibles)); - form.add(responsible.setVisible(!responsibles.isEmpty())); - - // milestone - List milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open); - for (TicketMilestone milestone : milestones) { - if (milestone.name.equals(ticket.milestone)) { - milestoneModel.setObject(milestone); - break; + Collections.sort(responsibles); + responsibles.add(new TicketResponsible(NIL, "", "")); + Fragment responsible = new Fragment("responsible", "responsibleFragment", this); + responsible.add(new DropDownChoice("responsible", responsibleModel, responsibles)); + form.add(responsible.setVisible(!responsibles.isEmpty())); + + // milestone + List milestones = app().tickets().getMilestones(getRepositoryModel(), Status.Open); + for (TicketMilestone milestone : milestones) { + if (milestone.name.equals(ticket.milestone)) { + milestoneModel.setObject(milestone); + break; + } + } + if (milestoneModel.getObject() == null && !StringUtils.isEmpty(ticket.milestone)) { + // ensure that this unrecognized milestone is listed + // so that we get the selection. + TicketMilestone tms = new TicketMilestone(ticket.milestone); + milestones.add(tms); + milestoneModel.setObject(tms); + } + if (!milestones.isEmpty()) { + milestones.add(new TicketMilestone(NIL)); } - } - if (milestoneModel.getObject() == null && !StringUtils.isEmpty(ticket.milestone)) { - // ensure that this unrecognized milestone is listed - // so that we get the selection. - TicketMilestone tms = new TicketMilestone(ticket.milestone); - milestones.add(tms); - milestoneModel.setObject(tms); - } - if (!milestones.isEmpty()) { - milestones.add(new TicketMilestone(NIL)); - } - Fragment milestone = new Fragment("milestone", "milestoneFragment", this); + Fragment milestone = new Fragment("milestone", "milestoneFragment", this); - milestone.add(new DropDownChoice("milestone", milestoneModel, milestones)); - form.add(milestone.setVisible(!milestones.isEmpty())); + milestone.add(new DropDownChoice("milestone", milestoneModel, milestones)); + form.add(milestone.setVisible(!milestones.isEmpty())); - // mergeTo (integration branch) - List branches = new ArrayList(); - for (String branch : getRepositoryModel().getLocalBranches()) { - // exclude ticket branches - if (!branch.startsWith(Constants.R_TICKET)) { - branches.add(Repository.shortenRefName(branch)); + // mergeTo (integration branch) + List branches = new ArrayList(); + for (String branch : getRepositoryModel().getLocalBranches()) { + // exclude ticket branches + if (!branch.startsWith(Constants.R_TICKET)) { + branches.add(Repository.shortenRefName(branch)); + } } - } - branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD)); - branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD)); - - Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this); - mergeto.add(new DropDownChoice("mergeto", mergeToModel, branches)); - form.add(mergeto.setVisible(!branches.isEmpty())); + branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD)); + branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD)); + Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this); + mergeto.add(new DropDownChoice("mergeto", mergeToModel, branches)); + form.add(mergeto.setVisible(!branches.isEmpty())); + } else { + // user can not admin this ticket + form.add(new Label("responsible").setVisible(false)); + form.add(new Label("milestone").setVisible(false)); + form.add(new Label("mergeto").setVisible(false)); + } form.add(new Button("update")); Button cancel = new Button("cancel") { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html index 71570df4..447c6aa4 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html +++ b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.html @@ -41,6 +41,7 @@ * + @@ -62,5 +63,9 @@ + + + + \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java index 17ad1d1b..25fe48f4 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java @@ -29,7 +29,9 @@ import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; +import org.eclipse.jgit.lib.Repository; +import com.gitblit.Constants; import com.gitblit.Constants.AccessPermission; import com.gitblit.models.RegistrantAccessPermission; import com.gitblit.models.TicketModel; @@ -61,6 +63,8 @@ public class NewTicketPage extends RepositoryPage { private IModel topicModel; + private IModel mergeToModel; + private IModel responsibleModel; private IModel milestoneModel; @@ -83,6 +87,7 @@ public class NewTicketPage extends RepositoryPage { typeModel = Model.of(TicketModel.Type.defaultType); titleModel = Model.of(); topicModel = Model.of(); + mergeToModel = Model.of(Repository.shortenRefName(getRepositoryModel().HEAD)); responsibleModel = Model.of(); milestoneModel = Model.of(); @@ -123,6 +128,12 @@ public class NewTicketPage extends RepositoryPage { change.setField(Field.milestone, milestone.name); } + // integration branch + String mergeTo = mergeToModel.getObject(); + if (!StringUtils.isEmpty(mergeTo)) { + change.setField(Field.mergeTo, mergeTo); + } + TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change); if (ticket != null) { TicketNotifier notifier = app().tickets().createNotifier(); @@ -149,7 +160,7 @@ public class NewTicketPage extends RepositoryPage { descriptionEditor.setRepository(repositoryName); form.add(descriptionEditor); - if (currentUser != null && currentUser.isAuthenticated && currentUser.canPush(getRepositoryModel())) { + if (currentUser.canAdmin(null, getRepositoryModel())) { // responsible List responsibles = new ArrayList(); for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) { @@ -170,10 +181,26 @@ public class NewTicketPage extends RepositoryPage { Fragment milestone = new Fragment("milestone", "milestoneFragment", this); milestone.add(new DropDownChoice("milestone", milestoneModel, milestones)); form.add(milestone.setVisible(!milestones.isEmpty())); + + // integration branch + List branches = new ArrayList(); + for (String branch : getRepositoryModel().getLocalBranches()) { + // exclude ticket branches + if (!branch.startsWith(Constants.R_TICKET)) { + branches.add(Repository.shortenRefName(branch)); + } + } + branches.remove(Repository.shortenRefName(getRepositoryModel().HEAD)); + branches.add(0, Repository.shortenRefName(getRepositoryModel().HEAD)); + + Fragment mergeto = new Fragment("mergeto", "mergeToFragment", this); + mergeto.add(new DropDownChoice("mergeto", mergeToModel, branches)); + form.add(mergeto.setVisible(!branches.isEmpty())); } else { - // user does not have permission to assign milestone or responsible + // user does not have permission to assign milestone, responsible, or mergeto form.add(new Label("responsible").setVisible(false)); form.add(new Label("milestone").setVisible(false)); + form.add(new Label("mergeto").setVisible(false)); } form.add(new Button("create")); diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index 7b492dc2..1c0544c8 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -327,7 +327,7 @@ public class TicketPage extends TicketBasePage { * UPDATE FORM (DISCUSSION TAB) */ if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) { - if (ticket.isOpen()) { + if (user.canAdmin(ticket, repository) && ticket.isOpen()) { /* * OPEN TICKET */ -- cgit v1.2.3 From b335dda6b2a2254e2d4c3162ea945496d9a0eb58 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 8 Mar 2014 11:53:38 -0500 Subject: Fix integration branch in propose instructions --- src/main/java/com/gitblit/wicket/pages/TicketPage.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index 1c0544c8..d3ddc89f 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -988,7 +988,11 @@ public class TicketPage extends TicketBasePage { md = md.replace("${ticketId}", "" + ticketId); md = md.replace("${patchset}", "" + 1); md = md.replace("${reviewBranch}", Repository.shortenRefName(PatchsetCommand.getTicketBranch(ticketId))); - md = md.replace("${integrationBranch}", Repository.shortenRefName(getRepositoryModel().HEAD)); + String integrationBranch = Repository.shortenRefName(getRepositoryModel().HEAD); + if (!StringUtils.isEmpty(ticket.mergeTo)) { + integrationBranch = ticket.mergeTo; + } + md = md.replace("${integrationBranch}", integrationBranch); return MarkdownUtils.transformMarkdown(md); } -- cgit v1.2.3 From b919a7f3f5b8415df7d237b1644193430a64f299 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 8 Mar 2014 11:59:18 -0500 Subject: Prevent Lucene queries from starting with a conjunction --- src/main/java/com/gitblit/tickets/QueryBuilder.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/main/java/com/gitblit/tickets/QueryBuilder.java b/src/main/java/com/gitblit/tickets/QueryBuilder.java index 17aeb988..0a6d0e99 100644 --- a/src/main/java/com/gitblit/tickets/QueryBuilder.java +++ b/src/main/java/com/gitblit/tickets/QueryBuilder.java @@ -201,6 +201,12 @@ public class QueryBuilder { q = q.substring(1, q.length() - 1); } } + if (q.startsWith("AND ")) { + q = q.substring(3).trim(); + } + if (q.startsWith("OR ")) { + q = q.substring(2).trim(); + } return q; } -- cgit v1.2.3