| | |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.NoSuchElementException; |
| | | import java.util.Set; |
| | | import java.util.TreeSet; |
| | | import java.util.regex.Matcher; |
| | |
| | | |
| | | public Integer deletions; |
| | | |
| | | public Priority priority; |
| | | |
| | | public Severity severity; |
| | | |
| | | /** |
| | | * Builds an effective ticket from the collection of changes. A change may |
| | | * Add or Subtract information from a ticket, but the collection of changes |
| | |
| | | changes = new ArrayList<Change>(); |
| | | status = Status.New; |
| | | type = Type.defaultType; |
| | | priority = Priority.defaultPriority; |
| | | severity = Severity.defaultSeverity; |
| | | } |
| | | |
| | | public boolean isOpen() { |
| | |
| | | case mergeSha: |
| | | mergeSha = toString(value); |
| | | break; |
| | | case priority: |
| | | priority = TicketModel.Priority.fromObject(value, priority); |
| | | break; |
| | | case severity: |
| | | severity = TicketModel.Severity.fromObject(value, severity); |
| | | break; |
| | | default: |
| | | // unknown |
| | | break; |
| | |
| | | } |
| | | |
| | | public boolean hasComment() { |
| | | return comment != null && !comment.isDeleted(); |
| | | return comment != null && !comment.isDeleted() && comment.text != null; |
| | | } |
| | | |
| | | public Comment comment(String text) { |
| | |
| | | for (String item : items) { |
| | | list.add(prefix + item); |
| | | } |
| | | setField(field, join(list, ",")); |
| | | if (hasField(field)) { |
| | | String flat = getString(field); |
| | | if (isEmpty(flat)) { |
| | | // field is empty, use this list |
| | | setField(field, join(list, ",")); |
| | | } else { |
| | | // merge this list into the existing field list |
| | | Set<String> set = new TreeSet<String>(Arrays.asList(flat.split(","))); |
| | | set.addAll(list); |
| | | setField(field, join(set, ",")); |
| | | } |
| | | } else { |
| | | // does not have a list for this field |
| | | setField(field, join(list, ",")); |
| | | } |
| | | } |
| | | |
| | | public String getId() { |
| | |
| | | } |
| | | |
| | | public static enum Score { |
| | | approved(2), looks_good(1), not_reviewed(0), needs_improvement(-1), vetoed(-2); |
| | | approved(2), looks_good(1), not_reviewed(0), needs_improvement(-1), vetoed( |
| | | -2); |
| | | |
| | | final int value; |
| | | |
| | |
| | | public String toString() { |
| | | return name().toLowerCase().replace('_', ' '); |
| | | } |
| | | |
| | | public static Score fromScore(int score) { |
| | | for (Score s : values()) { |
| | | if (s.getValue() == score) { |
| | | return s; |
| | | } |
| | | } |
| | | throw new NoSuchElementException(String.valueOf(score)); |
| | | } |
| | | } |
| | | |
| | | public static enum Field { |
| | | title, body, responsible, type, status, milestone, mergeSha, mergeTo, |
| | | topic, labels, watchers, reviewers, voters, mentions; |
| | | topic, labels, watchers, reviewers, voters, mentions, priority, severity; |
| | | } |
| | | |
| | | public static enum Type { |
| | | Enhancement, Task, Bug, Proposal, Question; |
| | | Enhancement, Task, Bug, Proposal, Question, Maintenance; |
| | | |
| | | public static Type defaultType = Task; |
| | | |
| | | public static Type [] choices() { |
| | | return new Type [] { Enhancement, Task, Bug, Question }; |
| | | return new Type [] { Enhancement, Task, Bug, Question, Maintenance }; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | public static enum Status { |
| | | New, Open, Closed, Resolved, Fixed, Merged, Wontfix, Declined, Duplicate, Invalid, Abandoned, On_Hold; |
| | | New, Open, Closed, Resolved, Fixed, Merged, Wontfix, Declined, Duplicate, Invalid, Abandoned, On_Hold, No_Change_Required; |
| | | |
| | | public static Status [] requestWorkflow = { Open, Resolved, Declined, Duplicate, Invalid, Abandoned, On_Hold }; |
| | | public static Status [] requestWorkflow = { Open, Resolved, Declined, Duplicate, Invalid, Abandoned, On_Hold, No_Change_Required }; |
| | | |
| | | public static Status [] bugWorkflow = { Open, Fixed, Wontfix, Duplicate, Invalid, Abandoned, On_Hold }; |
| | | public static Status [] bugWorkflow = { Open, Fixed, Wontfix, Duplicate, Invalid, Abandoned, On_Hold, No_Change_Required }; |
| | | |
| | | public static Status [] proposalWorkflow = { Open, Resolved, Declined, Abandoned, On_Hold }; |
| | | public static Status [] proposalWorkflow = { Open, Resolved, Declined, Abandoned, On_Hold, No_Change_Required }; |
| | | |
| | | public static Status [] milestoneWorkflow = { Open, Closed, Abandoned, On_Hold }; |
| | | |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public static enum Priority { |
| | | Low(-1), Normal(0), High(1), Urgent(2); |
| | | |
| | | public static Priority defaultPriority = Normal; |
| | | |
| | | final int value; |
| | | |
| | | Priority(int value) { |
| | | this.value = value; |
| | | } |
| | | |
| | | public int getValue() { |
| | | return value; |
| | | } |
| | | |
| | | public static Priority [] choices() { |
| | | return new Priority [] { Urgent, High, Normal, Low }; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return name().toLowerCase().replace('_', ' '); |
| | | } |
| | | |
| | | public static Priority fromObject(Object o, Priority defaultPriority) { |
| | | if (o instanceof Priority) { |
| | | // cast and return |
| | | return (Priority) o; |
| | | } else if (o instanceof String) { |
| | | // find by name |
| | | for (Priority priority : values()) { |
| | | String str = o.toString(); |
| | | if (priority.name().equalsIgnoreCase(str) |
| | | || priority.toString().equalsIgnoreCase(str)) { |
| | | return priority; |
| | | } |
| | | } |
| | | } else if (o instanceof Number) { |
| | | |
| | | switch (((Number) o).intValue()) { |
| | | case -1: return Priority.Low; |
| | | case 0: return Priority.Normal; |
| | | case 1: return Priority.High; |
| | | case 2: return Priority.Urgent; |
| | | default: return Priority.Normal; |
| | | } |
| | | } |
| | | |
| | | return defaultPriority; |
| | | } |
| | | } |
| | | |
| | | public static enum Severity { |
| | | Unrated(-1), Negligible(1), Minor(2), Serious(3), Critical(4), Catastrophic(5); |
| | | |
| | | public static Severity defaultSeverity = Unrated; |
| | | |
| | | final int value; |
| | | |
| | | Severity(int value) { |
| | | this.value = value; |
| | | } |
| | | |
| | | public int getValue() { |
| | | return value; |
| | | } |
| | | |
| | | public static Severity [] choices() { |
| | | return new Severity [] { Unrated, Negligible, Minor, Serious, Critical, Catastrophic }; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return name().toLowerCase().replace('_', ' '); |
| | | } |
| | | |
| | | public static Severity fromObject(Object o, Severity defaultSeverity) { |
| | | if (o instanceof Severity) { |
| | | // cast and return |
| | | return (Severity) o; |
| | | } else if (o instanceof String) { |
| | | // find by name |
| | | for (Severity severity : values()) { |
| | | String str = o.toString(); |
| | | if (severity.name().equalsIgnoreCase(str) |
| | | || severity.toString().equalsIgnoreCase(str)) { |
| | | return severity; |
| | | } |
| | | } |
| | | } else if (o instanceof Number) { |
| | | |
| | | switch (((Number) o).intValue()) { |
| | | case -1: return Severity.Unrated; |
| | | case 1: return Severity.Negligible; |
| | | case 2: return Severity.Minor; |
| | | case 3: return Severity.Serious; |
| | | case 4: return Severity.Critical; |
| | | case 5: return Severity.Catastrophic; |
| | | default: return Severity.Unrated; |
| | | } |
| | | } |
| | | |
| | | return defaultSeverity; |
| | | } |
| | | } |
| | | } |