Skip to content

Commit

Permalink
enable reattach for non-owned tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Mar 20, 2020
1 parent c666edc commit d9661f8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/hu/rxd/toolbox/TicketUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hu.rxd.toolbox;

import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -48,7 +49,9 @@ public static void reattach(String ticketKey) throws Exception {
File patchFile = new File(attachment.get().getFileName());
FileUtils.copyURLToFile(patchURL, patchFile);

t.getIssue().addAttachment(patchFile);
try (Closeable c = t.withAssignedToCurrentUser()) {
t.getIssue().addAttachment(patchFile);
}
}

private static void jiraLogin() {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/hu/rxd/toolbox/jira/HiveTicket.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package hu.rxd.toolbox.jira;

import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -31,6 +33,7 @@
import net.rcarz.jiraclient.Attachment;
import net.rcarz.jiraclient.BasicCredentials;
import net.rcarz.jiraclient.Comment;
import net.rcarz.jiraclient.Field;
import net.rcarz.jiraclient.Issue;
import net.rcarz.jiraclient.Issue.SearchResult;
import net.rcarz.jiraclient.JiraClient;
Expand Down Expand Up @@ -153,4 +156,36 @@ public boolean canBeSubmitted() {
return (getReviewComments().size() > 0);
}

public Closeable withAssignedToCurrentUser() throws Exception {
final String origUser = getIssue().getAssignee().getName();
String currentUser = ToolboxSettings.instance().getJiraUserId();

if (currentUser.equals(origUser)) {
// no need
return () -> {
};
}

System.out.println("Taking over ticket from :" + origUser);
getIssue().update()
.field(Field.ASSIGNEE, currentUser)
.execute();

return new Closeable() {

@Override
public void close() throws IOException {
try {
System.out.println("Assigning back to origUser:" + origUser);
getIssue().update()
.field(Field.ASSIGNEE, origUser)
.execute();
} catch (JiraException e) {
throw new RuntimeException("can't assign back to " + origUser, e);
}
}
};

}

}

0 comments on commit d9661f8

Please sign in to comment.