https://github.com/mailru/jira-scripts
https://github.com/mailru/jira-scripts
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mailru/jira-scripts
- Owner: mailru
- Created: 2017-04-19T15:33:09.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-27T13:01:23.000Z (about 3 years ago)
- Last Synced: 2025-04-15T11:25:04.969Z (6 months ago)
- Language: Groovy
- Size: 1.47 MB
- Stars: 120
- Watchers: 22
- Forks: 54
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Atlassian JIRA MyGroovy templates / examples
Template of quick writing groovy scripts for the plugin [Groovy Amigo] (https://marketplace.atlassian.com/1218755).
The template uses the usual java-api in easy-to-use wrappers.
You can just to copy the code and apply it in the right order.[Groovy language docs is here] (http://groovy-lang.org/documentation.html)
[MyGroovy source code] (https://github.com/atlascommunity/jira-plugins-groovy)
[MyGroovy documentation] (https://github.com/atlascommunity/jira-plugins-groovy/wiki)
Additions and wishes are welcome.
#### Example 1
Receiving issue
```groovy
ComponentAccessor.issueManager.getIssueObject(key)
```The template is represented by a method that is copied with the import.
```groovy
def getIssue(String key){
ComponentAccessor.issueManager.getIssueObject(key)
}
```#### Example 2
Calling a transition at issue. The transition.groovy file contains the doTransition (issue, actionId, user) method.
It passes the issue with which you want to call the transition, the transition id, user - the user on whose behalf the transition is made
```groovy
def doTransition(issue, int actionId, user){
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters();
def transitionValidationResult = issueService.validateTransition(user, issue.id, actionId, issueInputParameters);
if (transitionValidationResult.isValid()){
issueService.transition(user, transitionValidationResult);
return true
} else {
return false
}
}
```#### Example 3
To execute a query in the database, call the select ("select * from ...") method from the sql.groovy file```groovy
select("select ...")def select(String query){
OfBizDelegator delegator = ComponentAccessor.getOfBizDelegator();
DelegatorInterface delegatorInterface = delegator.getDelegatorInterface();
String helperName = delegatorInterface.getGroupHelperName("default");
Connection connection = ConnectionFactory.getConnection(helperName);
Sql sql = new Sql(connection);List resultRows = []
try{
resultRows.addAll(sql.rows(query));
} finally {
connection.close()
}
return resultRows
}
```