Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created December 13, 2016 20:12
Show Gist options
  • Save jechlin/08b6b73d6e2be52ddad5d3f37736a63d to your computer and use it in GitHub Desktop.
Save jechlin/08b6b73d6e2be52ddad5d3f37736a63d to your computer and use it in GitHub Desktop.
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.JiraDataType
import com.atlassian.jira.JiraDataTypes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.MessageSet
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
class PriorityOf extends AbstractScriptedJqlFunction implements JqlValuesFunction {
IssueManager issueManager = ComponentAccessor.getIssueManager()
@Override
MessageSet validate(ApplicationUser user, FunctionOperand operand, TerminalClause terminalClause) {
def messageSet = super.validate(user, operand, terminalClause)
if (! getIssue(operand)) {
messageSet.addErrorMessage("Can't find this issue")
}
return messageSet
}
@Override
String getDescription() {
"Gets issue with the same priority as the provided issue"
}
@Override
List<Map> getArguments() {
[
[
"description": "Comparison issue",
"optional" : false
],
]
}
@Override
String getFunctionName() {
"priorityOf"
}
@Override
JiraDataType getDataType() {
JiraDataTypes.PRIORITY
}
@Override
List<QueryLiteral> getValues(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
MutableIssue issue = getIssue(operand)
[new QueryLiteral(operand, issue.priority.id)]
}
@Override
boolean isList() {
false
}
private MutableIssue getIssue(FunctionOperand operand) {
def issueKey = operand.args[0]
def issue = issueManager.getIssueObject(issueKey)
issue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment