Creating Pull Request on Behalf of Team Members via API

Drew July 12, 2018

I've been attempting to create a pull request on behalf of our team members in an autonomous manner.

I'm able to create the pull request if I authenticate as the particular user with their username and password, but if I attempt to provide an alternative author username, per the swagger documentation, the field is ignored and only the administrator account is permitted.

Is there an authentication mechanism in place, short of having every team member complete the OAUTH procedure (Not practical), in which I am able to perform the desired API call and specify an author?

Sample call, which succeeds, but uses the username specified in the auth header. I have not yet attempted to setup authentication with OAUTH: 

curl -X POST -H "Content-Type: application/json" -u ...:... https://bitbucket.org/api/2.0/repositories/.../.../pullrequests -d '{
"title": "...",
"description": "...",
"source":
{
"branch":
{
"name": "..."
},
"repository":
{
"full_name": ".../..."
}
},
"destination":
{
"branch":
{
"name": "..."
}
},
"close_source_branch": false,
"author": {
"type": "user",
"username": "...",
"display_name": "...",
"account_id": "...:...-...-...-...-...",
"links":
{
"self":
{
"href": "https://bitbucket.org/!api/2.0/users/..."
},
"html":
{
"href": "https://bitbucket.org/.../"
},
"avatar":
{
"href": "https://bitbucket.org/account/.../avatar/"
}
},
"type": "user",
"uuid": "{...}"
}
}'

 ...also why was this marked as spam the first time I posted?

1 answer

0 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Hi Drew, if I understand your request correctly, you'd like to use the API so you can authenticate as the administrator and create a pull request on behalf of a different user (without the need to authenticate as such user, is that right?

If so, I'm afraid it won't be possible. The pull request author can't be changed once it's been created, and at the time of creation the author is the authenticated user. We have a feature request to make the author editable, you might be interested in voting for it at Issues #11340. You can also add a comment and watch it to receive future notifications.

Regarding the post going to spam, it happens sometimes that our spam filter sends messages with code blocks to the spam category. The Community moderators are monitoring the Spam filter daily, but we're not always that fast and sometimes it can take longer to rescue the legit messages :) 

Let us know if you have any other questions!

Kind regards,

Ana

Drew August 9, 2018

Hi Ana!

While editing an already created PR would be great, and would be one solution to address our teams issue, my question was regarding defining the pull request author at time of creation.


The swagger definition for the PR creation endpoint allows specifying an author, but it is ignored in practice, and only the authorized user is ever used. My primary question is thusly: is this is an error in the specification?

OAUTHing every single developer on a team in order for an automated PR creation tool to work on behalf of the team of an internal product is simply not practical. I'm wondering if there is an authentication protocol, perhaps using credentials that belong to the team as a whole, or another way to authenticate besides OAUTH, that makes defining the pull request author at time of creation possible.

Best,

- Drew

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events