Does ScriptRunner help to find empty projects

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2017

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

1 vote
Answer accepted
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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.

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2017

Many thanks for the help! Fantastically.

1 vote
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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);
}
});

 

0 votes
Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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.

Jose M.
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2017

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