| | |
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public static RefModel getTicketsBranch(Repository r) {
|
| | | RefModel ticgitBranch = null;
|
| | | try {
|
| | | // search for ticgit branch in local heads
|
| | | for (RefModel ref : getLocalBranches(r, -1)) {
|
| | | if (ref.displayName.endsWith("ticgit")) {
|
| | | ticgitBranch = ref;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | // search for ticgit branch in remote heads
|
| | | if (ticgitBranch == null) {
|
| | | for (RefModel ref : getRemoteBranches(r, -1)) {
|
| | | if (ref.displayName.endsWith("ticgit")) {
|
| | | ticgitBranch = ref;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (Throwable t) {
|
| | | LOGGER.error("Failed to find ticgit branch!", t);
|
| | | }
|
| | | return ticgitBranch;
|
| | | }
|
| | |
|
| | | public static List<TicketModel> getTickets(Repository r) {
|
| | | RefModel ticgitBranch = getTicketsBranch(r);
|
| | | List<PathModel> paths = getFilesInPath(r, null, ticgitBranch.commit);
|
| | | List<TicketModel> tickets = new ArrayList<TicketModel>();
|
| | | for (PathModel ticketFolder : paths) {
|
| | | if (ticketFolder.isTree()) {
|
| | | try {
|
| | | TicketModel t = new TicketModel(ticketFolder.name);
|
| | | readTicketContents(r, ticgitBranch, t);
|
| | | tickets.add(t);
|
| | | } catch (Throwable t) {
|
| | | LOGGER.error("Failed to get a ticket!", t);
|
| | | }
|
| | | }
|
| | | }
|
| | | Collections.sort(tickets);
|
| | | Collections.reverse(tickets);
|
| | | return tickets;
|
| | | }
|
| | |
|
| | | public static TicketModel getTicket(Repository r, String ticketFolder) {
|
| | | RefModel ticketsBranch = getTicketsBranch(r);
|
| | | if (ticketsBranch != null) {
|
| | | try {
|
| | | TicketModel ticket = new TicketModel(ticketFolder);
|
| | | readTicketContents(r, ticketsBranch, ticket);
|
| | | return ticket;
|
| | | } catch (Throwable t) {
|
| | | LOGGER.error("Failed to get ticket " + ticketFolder, t);
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | private static void readTicketContents(Repository r, RefModel ticketsBranch, TicketModel ticket) {
|
| | | List<PathModel> ticketFiles = getFilesInPath(r, ticket.name, ticketsBranch.commit);
|
| | | for (PathModel file : ticketFiles) {
|
| | | String content = getRawContentAsString(r, ticketsBranch.commit, file.path).trim();
|
| | | if (file.name.equals("TICKET_ID")) {
|
| | | ticket.id = content;
|
| | | } else if (file.name.equals("TITLE")) {
|
| | | ticket.title = content;
|
| | | } else {
|
| | | String[] chunks = file.name.split("_");
|
| | | if (chunks[0].equals("ASSIGNED")) {
|
| | | ticket.handler = content;
|
| | | } else if (chunks[0].equals("COMMENT")) {
|
| | | try {
|
| | | Comment c = new Comment(file.name, content);
|
| | | ticket.comments.add(c);
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | } else if (chunks[0].equals("TAG")) {
|
| | | if (content.startsWith("TAG_")) {
|
| | | ticket.tags.add(content.substring(4));
|
| | | } else {
|
| | | ticket.tags.add(content);
|
| | | }
|
| | | } else if (chunks[0].equals("STATE")) {
|
| | | ticket.state = content;
|
| | | }
|
| | | }
|
| | | }
|
| | | Collections.sort(ticket.comments);
|
| | | }
|
| | |
|
| | | public static String getTicketContent(Repository r, String filePath) {
|
| | | RefModel ticketsBranch = getTicketsBranch(r);
|
| | | if (ticketsBranch != null) {
|
| | | return getRawContentAsString(r, ticketsBranch.commit, filePath);
|
| | | }
|
| | | return "";
|
| | | }
|
| | | }
|