Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created October 12, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jechlin/106ca5ce42ea80fd9a4c to your computer and use it in GitHub Desktop.
Save jechlin/106ca5ce42ea80fd9a4c to your computer and use it in GitHub Desktop.
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
// text field containing tiny url *name*
def textFieldName = "Tiny URL"
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentManager = ComponentAccessor.getCommentManager()
def resolvedIssue = issue
def cf = customFieldManager.getCustomFieldObjectByName(textFieldName)
def tinyUrl = resolvedIssue.getCustomFieldValue(cf)
// update this query with the project(s) you want to search for the matching url
def query = jqlQueryParser.parseQuery("issueFunction in issueFieldExactMatch('project in (JRTWO)', '$textFieldName', '$tinyUrl')")
def searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
searchResults.issues.each { issue ->
def commentBody = """${resolvedIssue.key} has been resolved:
{quote}
${resolvedIssue.summary}
{quote}
"""
commentManager.create(issueManager.getIssueObject(issue.id), user, commentBody, true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment