Find empty component

Johan Hallin April 13, 2014

Hi,

I'm trying to clean up my project and I'm looking for a way to easily find all components that is not connected to any issue. I guess I could try to delete them one-by-one and get the warnings dialog which states if a component is safe to delete (empty) or not. But that is not a very good or safe way to handle it...

Any ideas?

Thanks,

Johan

2 answers

1 accepted

2 votes
Answer accepted
Boris Georgiev _Appfire_
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.
April 13, 2014

You can use this sample JS code to delete all unused components (just replace the project key on the first line in the url):

AJS.$.getJSON( "/rest/api/2/project/SD/components", function( data) {
  AJS.$(data).each(function(i,e) {
		AJS.$.getJSON( "/rest/api/2/component/"+e.id+"/relatedIssueCounts", function(data) {
				if(data.issueCount == 0) {					
					AJS.$.ajax({
					  url: '/rest/api/2/component/'+e.id,
					  type: 'DELETE'
					});				
				}				
		});
	});
});

Johan Hallin April 13, 2014

Nice, thanks

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 13, 2014

The quick and cheap way I do this is to define a filter that lists all the issues in the project, then use it in a "filter statistics" gadget with component as the stat. That gets you a list of all the components that HAVE been used, which you can then compare with the full list of all components.

It's not ideal - subtracting "used" from "all", but I think it may be the quickest without code or trying stuff out. (Additional benefit is you find out if you've got low-usage components that might be better deleted or merged)

Johan Hallin April 13, 2014

Not an ideal way but sure, I guess that works.

An one bonus point for the "find low-used" components. :)

Thanks

Suggest an answer

Log in or Sign up to answer