Missed Team ’24? Catch up on announcements here.

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

How can I change the creator/author of a pull request?

Patrick Flood January 14, 2015

Is there a way for an admin user to change the creator/author of a pull request? 

We're trying to configure an environment where our build system will automatically create pull requests (long story), but we want each pull request to be 'owned' by a specific user (determined by the system).  I haven't found anything in the API that looks like it would support this, but I'm hoping there's a way.

The goal is to ensure that comments and action items get directed to the appropriate person.  If there's no way to change the creator/author field directly, is there another way to accomplish the same goal?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Marcin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 14, 2015

You can't change the author of a pull request once it's been created, and at create time the author is the authenticated user.

A simple approach could be just to add the "owner" user as a watcher on the pull request, this can be done via the REST API: https://developer.atlassian.com/static/rest/stash/3.6.0/stash-rest.html#idp2136400 They would then receive all comments and notifications.  This however doesn't make it easy to work out who the owner of the Pull Request is for reviewers or other participants.

A "proper" solution would be to write a Stash plugin that provides some a servlet for the build system to call, and uses the SecurityService to impersonate the desired author when creating the Pull Request:

StashUser author = userService.getUserByName("user");
securityService.impersonating(author, "Creating pull request for " + author.getDisplayName()).call(new UncheckedOperation<PullRequest>() {
    @Override
    public PullRequest perform() {       
        return pullRequestService.create("Pull Request Title", "This is the description", ImmutableSet.<String>of(/* reviewers */), repo, "feature/new", repo, "master");
    }
});

While this lets the plugin code impersonate a user, it doesn't give them any permissions they don't already have, however you'd need to ensure you appropriately secured the servlet to ensure that only (say) the user that your build server uses could access this functionality. 

Patrick Flood January 15, 2015

Thanks Marcin, I think this impersonation approach is exactly what we're looking for. I'll see if we can put together a plugin.

TAGS
AUG Leaders

Atlassian Community Events