Script Runner validation of (JQL > Script)

Gonchik Tsymzhitov Community Champion Oct 24, 2016

Hi guys, 

 

I want create a simple validator via groovy where goal is anyone can not resolve issue with resolution fixed without relations any commits with itself. 

For check, I use jql expression 

 

issue.property[development].commits > 0

But I don't know how convert to validator. 

 

Thank you.

 

 

2 answers

0 votes
Vasiliy Zverev Community Champion Oct 31, 2016

Here is code for simple script validator which makes a loop for all issue commets. Note, that a comment should be inserted before transition.

More one solution - you can make field "Comment" to be filled on transition screen with validator "fields requared" provided by JSU plugin.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser

ApplicationUser curUser = ComponentAccessor.getJiraAuthenticationContext().getUser(); 

for(Comment comment: ComponentAccessor.getCommentManager().getComments(issue)){
  if(comment.getAuthorApplicationUser().equals(curUser))
   return true;
}
return false
Gonchik Tsymzhitov Community Champion Oct 31, 2016

Many thanks, Vasiliy. 

But I mean about commit from development tab. 

https://answers.atlassian.com/questions/32535478

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.plugin.devstatus.api.DevStatusSummaryService
import com.atlassian.jira.plugin.devstatus.rest.DetailBean
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
 
@WithPlugin("com.atlassian.jira.plugins.jira-development-integration-plugin")
DevStatusSummaryService devStatusSummaryService = ComponentAccessor.getOSGiComponentInstanceOfType(DevStatusSummaryService.class)
 
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
 
DetailBean commitData = devStatusSummaryService.getDetailData(issue.id, "stash", "commit", currentUser).get()

 

But it's very I think to resolve via jql exression.

 

0 votes
Gonchik Tsymzhitov Community Champion Nov 13, 2018

This one will help

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.plugin.ComponentClassManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.gonchik.scripts.groovy.herz")
log.setLevel(Level.DEBUG)

ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()

def ccm = ComponentAccessor.getComponentClassManager()
def devStatusSummaryService = ccm.newInstance("com.atlassian.jira.plugin.devstatus.impl.DefaultDevStatusSummaryService")

def issue = issueManager.getIssueObject("TB-88165")

def pullRequestData = devStatusSummaryService.getDetailData(issue.id, "stash", "pullrequest", currentUser).right().get().getDetail()
log.debug(pullRequestData)

def buildData = devStatusSummaryService.getDetailData(issue.id, "bamboo", "build", currentUser).right().get().getDetail()
log.debug(buildData)

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Thursday in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

453 views 2 5
View question

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you