Last active
July 28, 2016 02:12
-
-
Save matts-mpg/11619c95c592e663f7608b9a2b1286e1 to your computer and use it in GitHub Desktop.
This is a build off the get-jira-issue-matchstuff script, but this one goes and starts to get Custom Field values. This should be updated to include updating those values with items matched by the matchers. This seems to be harder than it should be since some things that appear to beg for a setValue() function do not have one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.atlassian.jira.ComponentAccessor; | |
import com.atlassian.jira.issue.Issue; | |
import com.atlassian.jira.issue.CustomFieldManager; | |
import com.atlassian.jira.issue.MutableIssue; | |
import com.atlassian.jira.issue.IssueManager; | |
import com.atlassian.jira.issue.comments.Comment; | |
import com.atlassian.jira.issue.comments.MutableComment; | |
import com.atlassian.jira.issue.comments.CommentManager; | |
import com.atlassian.jira.component.ComponentAccessor; | |
import com.atlassian.jira.user.ApplicationUser; | |
import com.atlassian.jira.security.JiraAuthenticationContext; | |
import com.atlassian.jira.issue.fields.CustomField; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
//Get the current user | |
JiraAuthenticationContext userMgr = ComponentAccessor.getJiraAuthenticationContext(); | |
ApplicationUser currentUserObj = userMgr.getLoggedInUser(); | |
//Get an issue | |
IssueManager issueMgr = ComponentAccessor.getIssueManager(); | |
MutableIssue issue = issueMgr.getIssueObject("JRA-76"); | |
//Get customfields | |
CustomFieldManager fieldMgr = ComponentAccessor.getCustomFieldManager(); | |
CustomField grp1tixCF = fieldMgr.getCustomFieldObject(10602L); | |
CustomField grp2tixCF = fieldMgr.getCustomFieldObject(10603L); | |
//Get comments | |
CommentManager commentMgr = ComponentAccessor.getCommentManager(); | |
Comment comms = commentMgr.getLastComment(issue); | |
//Create the regex matchers you need | |
//Start with the Group 1 Case ID | |
def grp1tixmatcher = issue.description =~ /IR\d\d\d\d\d+/; | |
try { | |
String grp1tixres = grp1tixmatcher[0] | |
log.error "Group 1 Case ID matcher says " + grp1tixres; | |
} catch ( IndexOutOfBoundsException e ) { | |
log.error e; | |
} | |
//Then do the Group 2 Case ID | |
//This one will always be ingested into a comment from the body of an email reply | |
def grp2tixmatcher = issue.comms =~ /ABC00\d\d\d\d\d+/; | |
try { | |
String grp2tixres = grp2tixmatcher[0] | |
log.error "Group 2 Case ID matcher says " + grp2tixres; | |
} catch ( IndexOutOfBoundsException e ) { | |
log.error e; | |
} | |
log.error ""; | |
log.error "The current user is " + currentUserObj.name; | |
log.error "The current issue ID is " + issue.id; | |
log.error "The current issue key is " + issue.key; | |
log.error "The current issue description is " + issue.description; | |
log.error "The current issue Component Case ID field value is " + issue.getCustomFieldValue(grp1tixCF); | |
log.error "The current issue Legacy JSOC Case ID field value is " + issue.getCustomFieldValue(grp2tixCF); | |
log.error ""; | |
//Check to see if your CF that you retrieved is editable or not. | |
log.error grp1tixCF.isEditable(); | |
//Do all of the editing below here | |
//Just initially pasting a snippet in here. Does not work yet. | |
Options options = WebAppsCf.getOptions(null, customField.getRelevantConfig(issue), null); | |
Option newOption = options.getOptionById(newOptionId); | |
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption ); | |
customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment