Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Check if branch exists (Stash) via Rest API

Nafets Kellerm July 28, 2014
final String stash_destination = "http://.../repos/dummyTest/branches?filterText=" + ticket;
		
		WebAuthentication wAuth_Stash = new WebAuthentication_Stash(stash_destination);
	
		WebResource webResource_Stash = wAuth_Stash.response();
		ClientResponse response_Stash = webResource_Stash.accept("application/json").type("application/json").get(ClientResponse.class);
		JSONObject jsonOutput_Stash = (JSONObject) JSONSerializer.toJSON(response_Stash.getEntity(String.class));
		JSONArray jsonValues = jsonOutput_Stash.getJSONArray("values");
		
		if (jsonValues.size() > 0) {
			return jsonValues.getJSONObject(0).containsValue(ticket);
		} else {
			return false;
		}

Hi,

I want to check if a branch with a certain Name already exist, what is already working. But it is so slow that it doesn't make me happy.

Does anyone know a faster method in Java?

(Sorry for the code on top of my post, but I wasn't able to get it below)

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
TimP
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 28, 2014

Hi Nafets,

You could specify the fully qualified branch name as the until parameter on the commits REST resource. If it returns a 404 you know the branch doesn't exist in the repo.

The URL you'd need to request would look something like this: https://stash.atlassian.com/rest/api/1.0/projects/PROJECT/repos/my-repo/commits?until=refs/heads/branch

cheers,

Tim

Nafets Kellerm July 29, 2014

Thank's for the answer, it's working 3 seconds faster than my solution

TAGS
AUG Leaders

Atlassian Community Events