It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Runner validation of (JQL > Script)

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

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

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

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted Oct 09, 2018 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

488 views 6 0
Join discussion

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