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

Git branch name through Crucible REST API

Paul Y May 16, 2017

Hello, colleagues! I'm trying to fetch list of completed reviews with REST API - it's simple sure, but I need to extract:

  1. name of related Git branch
  2. author's emails

With 2nd i can use "users-v1" API endpoint, but not all users have emails there. But with 1st I have big problem - I can not find way to extract Git branch name! Is there any way to find Git branch name? As I understand, Crucible has this info - files were submitted, review was completed, branch is known... But how to get it from REST API of Crucible? (I use Crucible + FishEye service).

I tryed different API calls, found in documentation field "ahcnorName" - it looks like branch name, but when I try to call repositories' related endpoints with existing repositories, I get error that repository not found... 

Can somebody show an example of call/point out REST call - how to get Git branch name related to completed review?

1 answer

1 vote
Piotr Swiecicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 16, 2017

Are you using branch reviews to run the reviews?  If so, you can try using undocumented REST API to retrieve the list of all the branches tracked in particular review.  Issue a GET request to http://<CRUCIBLE_URL>/rest/branchreview/latest/trackedbranch/<REVIEW_KEY> to get document like:

[
{
"id": "<HASH>",
"repositoryName": "repositoryName",
"repositoryDisplayName": "repository display name",
"repositoryType": "git",
"reviewedBranch": "some-feature-branch",
"baseBranch": "master",
"autoUpdate": false,
"lastChangesetId": "<HASH>"
}
]

If you are not using branch reviews but are adding content to review differently (e.g. by picking up individual changesets, files, etc.) I'm afraid it might be a challenge to identify what branch those changes come from.   git doesn't really track the branch changeset was created on.

Hope that helps,  

Paul Y May 18, 2017

Hello, Piotr. It seems I also found this:

https://HOST/rest-service-fe/commit-graph-v1/slice/REPO-NAME?size=1&id=GIT-HASH

Both params I know from:

https://HOST/rest-service/reviews-v1/REVIEW-PERMA-ID/details. But with this way I have another questions:

  1. 2nd call returns a list in repositoryName JSON field, length=1. Is it 1 a fixed length? Is it correct to get 1st item always?
  2. I get GIT-HASH as toRevision field from 2nd call's response JSON. But there is also field fromRevision. Do I need toRevision actually?
  3. 1nd call's response contains branch and also list of branches. Do I need this scalar field branch only (and should ignore list of branches)?
  4. Will this method work for all kind of reviews (with diff-files) ?

--

Best regards

Piotr Swiecicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 18, 2017

 

re 1. repositoryName is returned for each individual reviewItem (file on the review), so yes, it's always scalar value, as single file is coming from at most 1 repository. repositoryName might be missing for uploaded files or patches though, so I wouldn't assume it's always there.

re 2. fromRevision and toRevision indicate versions presented on revision slider, top of the review file. Depending of what you want to achieve you might be interested in one of those fields or both

re 3. again, this depends what data you are after. Remember git doesn't store information what branch particular commit was made on, this is dynamic and relation between particular changeset and branches may change over the time, where more branches are created or merged and their ancestry start to contain particular changeset.

Paul Y May 25, 2017

Thank you, Piotr!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events