Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
evanwinter committed Apr 30, 2018
1 parent 8c4ccf7 commit 6b330c1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 29 deletions.
26 changes: 10 additions & 16 deletions misc/deprecated/addPrimaryUserAsParticipant.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/*
* Name: addPrimaryUserAsParticipant.groovy
* Author: Evan Winter
*
* @brief Post function to get user in custom field "Primary User" and add them as a Request Participant
*
* @name addPrimaryUserAsParticipant.groovy
* @type Script Post Function
* @brief Adds the user in custom field "Primary User" to the field "Request Participants"
*/

import com.atlassian.jira.component.ComponentAccessor
Expand All @@ -23,33 +21,29 @@ def PRIMARY_USER_FIELD = "customfield_10913"

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issue // FOR TESTING IN CONSOLE replace `issue` with `issueManager.getIssueObject("{issuekey}")`

MutableIssue myIssue = issue // FOR TESTING IN CONSOLE -> issueManager.getIssueObject("KEY-000")

/* Get custom field objects */
/* Get field objects */
def requestParticipantsField = customFieldManager.getCustomFieldObject(REQUEST_PARTICIPANTS_FIELD)
def primaryUserField = customFieldManager.getCustomFieldObject(PRIMARY_USER_FIELD)

/* Get Primary User */
ApplicationUser primaryUser = myIssue.getCustomFieldValue(primaryUserField) as ApplicationUser
ApplicationUser primaryUser = issue.getCustomFieldValue(primaryUserField) as ApplicationUser

if (primaryUser) {

/* Add Primary User to array */
/* Create an empty arraylist and add Primary User */
ArrayList<ApplicationUser> participants = []
participants.add(primaryUser)

/* Update the Request Participants field */
myIssue.setCustomFieldValue(
requestParticipantsField,
participants
)
/* Assign the arraylist to the Request Participants field */
issue.setCustomFieldValue(requestParticipantsField, participants)

/* Store to database. */
try {
issueManager.updateIssue(
currentUser,
myIssue,
issue,
EventDispatchOption.ISSUE_UPDATED,
false
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* @name AT_mergeIssueIntoExisting_prod.groovy
* @type Post function
* @type Post function
* @brief Merges current issue into target issue by appending the current issue's
* description, comments and Reporter to the target issue's corresponding
* fields. The current issue's Reporter is added to the target issue as
* a Request Participant.
* description, comments and Reporter to the target issue's corresponding
* fields. The current issue's Reporter is added to the target issue as
* a Request Participant.
*/

import com.atlassian.jira.component.ComponentAccessor
Expand All @@ -30,6 +30,11 @@ ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().
def linkedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(thisIssue.getId())
MutableIssue mainIssue = linkedIssues[0].getDestinationObject() as MutableIssue

if (mainIssue.getKey() == thisIssue.getKey()) {
log.debug "Can't merge with self."
return false
}

/* Merge descriptions (this -> main) */
def mainDescription = mainIssue.getDescription()
def thisDescription = thisIssue.getDescription()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @name AT_raiseOnBehalfOf_prod.groovy
* @type Post function
* @brief Sets the user in custom field "Raise on behalf of" as Reporter,
* and adds the initial Reporter as a Request Participant.
* @brief Adds initial Reporter to Request Participants field, and assigns user
* in "Raise on behalf of" field to the Reporter field.
*/

import com.atlassian.jira.component.ComponentAccessor
Expand All @@ -15,12 +15,14 @@ import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Logger
def log = Logger.getLogger("com.acme.XXX")

/* Initialize variables */
def REQUEST_PARTICIPANTS_FIELD = "customfield_10600"
def RAISE_ON_BEHALF_OF_FIELD = "customfield_12131"

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
MutableIssue thisIssue = issue

def requestParticipantsField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10600")
def raiseOnBehalfOfField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12131")
def requestParticipantsField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(REQUEST_PARTICIPANTS_FIELD)
def raiseOnBehalfOfField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(RAISE_ON_BEHALF_OF_FIELD)

ApplicationUser thisReporter = thisIssue.getReporter()
ApplicationUser newReporter = thisIssue.getCustomFieldValue(raiseOnBehalfOfField) as ApplicationUser
Expand Down
56 changes: 56 additions & 0 deletions script-postfunctions/addPrimaryUserAsParticipant.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* @name addPrimaryUserAsParticipant.groovy
* @type Script Post Function
* @brief Adds the user in custom field "Primary User" to the field "Request Participants"
*/

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import java.util.ArrayList
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger

def log = Logger.getLogger("com.acme.XXX")

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def REQUEST_PARTICIPANTS_FIELD = "customfield_10600"
def PRIMARY_USER_FIELD = "customfield_10913"

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issue // FOR TESTING IN CONSOLE replace `issue` with `issueManager.getIssueObject("{issuekey}")`

/* Get field objects */
def requestParticipantsField = customFieldManager.getCustomFieldObject(REQUEST_PARTICIPANTS_FIELD)
def primaryUserField = customFieldManager.getCustomFieldObject(PRIMARY_USER_FIELD)

/* Get Primary User */
ApplicationUser primaryUser = issue.getCustomFieldValue(primaryUserField) as ApplicationUser

if (primaryUser) {

/* Create an empty arraylist and add Primary User */
ArrayList<ApplicationUser> participants = []
participants.add(primaryUser)

/* Assign the arraylist to the Request Participants field */
issue.setCustomFieldValue(requestParticipantsField, participants)

/* Store to database. */
try {
issueManager.updateIssue(
currentUser,
issue,
EventDispatchOption.ISSUE_UPDATED,
false
)
} catch (Exception e) {
log.debug "Exception: " + e
}

} else {
log.debug "No Primary User specified."
}
8 changes: 4 additions & 4 deletions script-snippets/jqlSearch.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @name jqlSearch.groovy
* @type script snippet
* @brief Gets all issues which match a JQL query and print out each summary.
* @brief Gets all issues which match a JQL query and print out each summary.
*/

import com.atlassian.jira.component.ComponentAccessor
Expand Down Expand Up @@ -36,8 +36,8 @@ if (results.total > 0) {

}
} else {
log.debug('No issues matched this query')
return "No issues matched this query. Please try another or contact a JIRA administrator."
log.debug("No issues matched this query. Please try another or contact a JIRA administrator.")
return false
}

return "Execution completed without error."
return true

0 comments on commit 6b330c1

Please sign in to comment.