Created
September 8, 2022 15:31
-
-
Save jechlin-adaptavist/092be4db13e690676196673a8fb79371 to your computer and use it in GitHub Desktop.
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
package com.onresolve.jira.groovy.jql | |
import com.atlassian.jira.component.ComponentAccessor | |
import com.atlassian.jira.jql.parser.JqlQueryParser | |
import com.atlassian.jira.jql.query.LuceneQueryBuilder | |
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 | |
import groovyx.net.http.ContentType | |
import groovyx.net.http.HTTPBuilder | |
import groovyx.net.http.Method | |
import org.apache.lucene.search.Query | |
class AssignedToOnCallFunction extends AbstractScriptedJqlFunction implements JqlQueryFunction { | |
def queryParser = ComponentAccessor.getComponent(JqlQueryParser) | |
def luceneQueryBuilder = ComponentAccessor.getComponent(LuceneQueryBuilder) | |
@Override | |
String getDescription() { | |
"Create release notes" | |
} | |
@Override | |
MessageSet validate(ApplicationUser user, FunctionOperand operand, TerminalClause terminalClause) { | |
// could add validation if you want | |
null | |
} | |
@Override | |
List<Map> getArguments() { | |
[] | |
} | |
@Override | |
String getFunctionName() { | |
"assignedToOnCall" | |
} | |
@Override | |
Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) { | |
// I'm using the rest api with hard-coded credentials just for testing... replace with whatever rest api you have | |
def httpBuilder = new HTTPBuilder('http://localhost:8080/jira/') | |
def response = httpBuilder.request(Method.GET, ContentType.JSON) { | |
uri.query = ['os_username': 'admin', 'os_password': 'admin'] | |
uri.path = 'rest/auth/1/session' | |
} | |
def username = response.name | |
def query = queryParser.parseQuery("assignee = $username") | |
luceneQueryBuilder.createLuceneQuery(queryCreationContext, query.whereClause) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment