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 years ago |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- /*
- * Copyright 2013 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.gitblit.tickets;
-
- import com.gitblit.utils.StringUtils;
-
- /**
- * A Lucene query builder.
- *
- * @author James Moger
- *
- */
- public class QueryBuilder {
-
- private final QueryBuilder parent;
- private String q;
- private transient StringBuilder sb;
- private int opCount;
-
- public static QueryBuilder q(String kernel) {
- return new QueryBuilder(kernel);
- }
-
- private QueryBuilder(QueryBuilder parent) {
- this.sb = new StringBuilder();
- this.parent = parent;
- }
-
- public QueryBuilder() {
- this("");
- }
-
- public QueryBuilder(String query) {
- this.sb = new StringBuilder(query == null ? "" : query);
- this.parent = null;
- }
-
- public boolean containsField(String field) {
- return sb.toString().contains(field + ":");
- }
-
- /**
- * Creates a new AND subquery. Make sure to call endSubquery to
- * get return *this* query.
- *
- * e.g. field:something AND (subquery)
- *
- * @return a subquery
- */
- public QueryBuilder andSubquery() {
- sb.append(" AND (");
- return new QueryBuilder(this);
- }
-
- /**
- * Creates a new OR subquery. Make sure to call endSubquery to
- * get return *this* query.
- *
- * e.g. field:something OR (subquery)
- *
- * @return a subquery
- */
- public QueryBuilder orSubquery() {
- sb.append(" OR (");
- return new QueryBuilder(this);
- }
-
- /**
- * Ends a subquery and returns the parent query.
- *
- * @return the parent query
- */
- public QueryBuilder endSubquery() {
- this.q = sb.toString().trim();
- if (q.length() > 0) {
- parent.sb.append(q).append(')');
- }
- return parent;
- }
-
- /**
- * Append an OR condition.
- *
- * @param condition
- * @return
- */
- public QueryBuilder or(String condition) {
- return op(condition, " OR ");
- }
-
- /**
- * Append an AND condition.
- *
- * @param condition
- * @return
- */
- public QueryBuilder and(String condition) {
- return op(condition, " AND ");
- }
-
- /**
- * Append an AND NOT condition.
- *
- * @param condition
- * @return
- */
- public QueryBuilder andNot(String condition) {
- return op(condition, " AND NOT ");
- }
-
- /**
- * Nest this query as a subquery.
- *
- * e.g. field:something AND field2:something else
- * ==> (field:something AND field2:something else)
- *
- * @return this query nested as a subquery
- */
- public QueryBuilder toSubquery() {
- if (opCount > 1) {
- sb.insert(0, '(').append(')');
- }
- return this;
- }
-
- /**
- * Nest this query as an AND subquery of the condition
- *
- * @param condition
- * @return the query nested as an AND subquery of the specified condition
- */
- public QueryBuilder subqueryOf(String condition) {
- if (!StringUtils.isEmpty(condition)) {
- toSubquery().and(condition);
- }
- return this;
- }
-
- /**
- * Removes a condition from the query.
- *
- * @param condition
- * @return the query
- */
- public QueryBuilder remove(String condition) {
- int start = sb.indexOf(condition);
- if (start == 0) {
- // strip first condition
- sb.replace(0, condition.length(), "");
- } else if (start > 1) {
- // locate condition in query
- int space1 = sb.lastIndexOf(" ", start - 1);
- int space0 = sb.lastIndexOf(" ", space1 - 1);
- if (space0 > -1 && space1 > -1) {
- String conjunction = sb.substring(space0, space1).trim();
- if ("OR".equals(conjunction) || "AND".equals(conjunction)) {
- // remove the conjunction
- sb.replace(space0, start + condition.length(), "");
- } else {
- // unknown conjunction
- sb.replace(start, start + condition.length(), "");
- }
- } else {
- sb.replace(start, start + condition.length(), "");
- }
- }
- return this;
- }
-
- /**
- * Generate the return the Lucene query.
- *
- * @return the generated query
- */
- public String build() {
- if (parent != null) {
- throw new IllegalAccessError("You can not build a subquery! endSubquery() instead!");
- }
- this.q = sb.toString().trim();
-
- // cleanup paranthesis
- while (q.contains("()")) {
- q = q.replace("()", "");
- }
- if (q.length() > 0) {
- if (q.charAt(0) == '(' && q.charAt(q.length() - 1) == ')') {
- // query is wrapped by unnecessary paranthesis
- q = q.substring(1, q.length() - 1);
- }
- }
- return q;
- }
-
- private QueryBuilder op(String condition, String op) {
- opCount++;
- if (!StringUtils.isEmpty(condition)) {
- if (sb.length() != 0) {
- sb.append(op);
- }
- sb.append(condition);
- }
- return this;
- }
-
- @Override
- public String toString() {
- return sb.toString().trim();
- }
- }
|