Does ScriptRunner help to find empty projects

With JIRA JQL I cannot find empty projects i.e. projects without issues, as from my knowledge. Does ScriptRunner support it? Would be great.

3 answers

1 accepted

This widget could not be displayed.
Stephen Deutsch Community Champion Jul 24, 2017

I'm not sure what you meant by needing to learn to use the REST API, as the script that I provided uses the REST API to do all the work for you, so there's no need to learn how to use it.

The script that I provided doesn't work in the Scriptrunner console, it works in the browser console. However, I spent some time writing a script that you can run in the Scriptrunner console:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.ProjectManager

ProjectManager projectManager = ComponentAccessor.getProjectManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()

return projectManager.getProjects().findAll { issueManager.getIssueCountForProject(it.id) == 0 }.collect { it.name + " - " + it.key }

It will return a list of projects that don't have any issues.

Many thanks for the help! Fantastically.

This widget could not be displayed.
Stephen Deutsch Community Champion Jul 21, 2017

You don't necessarily need scriptrunner for this. Here's a script that you can paste into your browser console that uses the REST API to search all projects for the number of issues. If the project is empty, then it also displays the URL for the project (shows as link in Google Chrome):

var searchProjects = function(projects, size) {
var project = projects.pop();
jQuery.ajax({
url: contextPath + '/rest/api/2/search?jql=project="' + project.key + '"&maxResults=0',
success: function( response ) {
console.log("Project " + project.name + " - " + (size - projects.length) + " of " + size + " contains " + response.total + " issues.");
if (response.total === 0) {
console.log(AJS.params.baseURL + "/browse/" + project.key);
}
if (projects.length) {
searchProjects(projects, size);
}
},
error: function() {
console.log("Error loading project " + project.name + " - " + (size - projects.length) + " of " + size)
if (projects.length) {
searchProjects(projects, size);
}
}
});
}

jQuery.ajax({
url: contextPath + '/rest/api/2/project?expand=url',
success: function( response ) {
delete response["length"];
searchProjects(response, response.length);
}
});

 

This widget could not be displayed.

Thanks for the answer, but I am looking for the possibitlity to use the Jira adavanced search, since I am more familiar with that. So I thought, with ScriptRunner it could work.

Stephen Deutsch Community Champion Jul 21, 2017

Unfortunately there's no easy way to do this, because JQL is designed to return issues, not projects. You may be able to script something with scriptrunner and run it in the script console, but by that point you'd probably just be better off using the script I provided.

I got your point, but as mentioned, I have to learn to use the REST API. With ScriptRunner there is a Script Console, but the try was not successful:

startup failed: Script5.groovy: 1: expecting EOF, found 'searchProjects' @ line 1, column 5. var searchProjects = function(projects, size) { ^ 1 error

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

95 views 0 3
Read article

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