With JIRA JQL I cannot find empty projects i.e. projects without issues, as from my knowledge. Does ScriptRunner support it? Would be great.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.