Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Pull request from command line: reviewers by other than UUID

Oliver Schoenborn
Contributor
July 24, 2019 edited

I am able to create a pull request from command line, the only thing I find painful is the reviewers are specified by UUID, I can see why that is safest but is there another way? Right now: 

"reviewers": [
{
"uuid": "{4ebe61bf-...-a368a41c78f6}"
},
{
"uuid": "{2ce53e84-...-fff39d658b49}"
}
]

This is not very user-friendly, and I can't even put comments to indicate who those people are at least for whoever reads the PR.json that contains the above.

3 answers

1 accepted

0 votes
Answer accepted
Oliver Schoenborn
Contributor
July 24, 2019

For 2.0 API:

In my case the main reason I use CLI is because I have a bunch of identical PR's to make on dozen repos, so the way I handle this now is I create one PR programmatically, use the CLI to get the PR, pare down the JSON so only title, description, reviewers, and source remain, and POST the file to as many repos as I need. 

1 vote
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 24, 2019

Hello @Oliver Schoenborn,

In the payload you send to the API endpoints you actually can refer to users using their usernames — you obviously need to know them in advance.

"reviewers": [
{
"username": "<username>"
}
]

In the API responses, however, usernames are not returned anymore due to requirements introduced by GDPR.

Note that a user might change their username at any time, and this will break a request with the payload mentioned above. Unlike username, UUID and Atlassian ID (uuid and account_id in JSON, respectively) would remain same in that case.

Hope this helps.

Cheers,
Daniil

Oliver Schoenborn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 26, 2019 edited

Thanks Daniil I tried username and got bad request error. I can use username if I also include uuid. Which is useful to document who the uuid is, but I still have to know the uuid. 

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 27, 2019

Hm, did you get any error description in the response payload?

I'm able to create a PR using API with reviewers resolved by username:

❯ curl -X POST -H "Content-Type: application/json" -u detouched:pEPcSZYDpP4SmgDMbkL9 "https://api.bitbucket.org/2.0/repositories/detouched/docker-spb/pullrequests" -d '{
"title": "Test Pull Request",
"source": {
"branch": {
"name": "1.3.8"
}
},
"destination": {
"branch": {
"name": "master"
}
},
"reviewers": [
{
"username": "dpenkin"
}
]
}'

I get 201 back and PR object JSON.

So I'm wondering maybe you get bad request because of some other problem?

Cheers,
Daniil

Oliver Schoenborn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 27, 2019

No info beyond bad request. Likely because username invalid. I went to the user's page and could see the uuid in the link and their name on the page so I used that but that's probably their display name (and I tried with display_name instead of uuid or username but also got bad request). How can I find a user's username? 

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 28, 2019

Usernames are not exposed anymore as they are personal data and hence are covered by the data protection regulations (GDPR). So the only way to get someone's username is by asking that person IRL.

Meanwhile I checked that although resolution by username still works right now, it is also deprecated and can be taken down at any time, see "Replace username fields with Atlassian Account ID (account_id)" section in the deprecation notice.

As for the case when you use username together with UUID, the former is simply ignored as the latter has a preference. So a hacky workaround for inability to leave comments in JSON would be to use username for a hint of who does the uuid refers to. Interestingly, account_id has lower preference than username, so same trick wouldn't work if you decide to use it as identifier. I'll raise a change to fix that as it now makes more sense I believe.

All in all, this definitely complicates your workflow but is the inevitable tradeoff for privacy aspect on the other hand. Let me know if you have any questions.

Cheers,
Daniil

Oliver Schoenborn
Contributor
July 29, 2019

Thanks for the info and following up. I must say I think the privacy issue is inadvertently tied to this, and should not be tied to it by design; if you pick a reviewer, you should have a way of identifying them by name; if you're not allowed to use username, then a nickname, or just their display name since that is what is available in the interface, something that is not a UUID! Anyway, at least I can get the mapping by generating a PR from the GUI with the reviewers I want, although this is a bit of a pain it si better than nothing. Thanks for all your support. 

0 votes
thinksabin July 24, 2019

in rest api 1.0, we can use username in the api call.

Oliver Schoenborn
Contributor
July 24, 2019

thanks, good to know (unfortunately I'm using 2.0)

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 24, 2019

Hi @thinksabin,

Just a heads up that REST API 1.0 has been deprecated around a year ago and currently is in a phase of gradual termination. So the endpoints you might still be able to use now will likely stop working in the future. Please consider migrating to API 2.0.

Let me know if you have any questions.

Cheers,
Daniil

thinksabin July 25, 2019

hi @Daniil Penkin ,

thanks for the heads up, I was unaware about the termination of the api 1.0. Thanks i will try to modify my automation script.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events