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

Mention a user in a PR comment using the Bitbucket REST API

Adding a mention to a user in a pull request comment can be a useful way to get their attention faster as well as being more visible when looking at the PR itself.

In Bitbucket, the POST Create a comment on a pull request REST API endpoint is available for adding a comment to a pull request.

If you want to mention to a user while posting the comment, you can add the reviewer Atlassian Account ID in a comment following the @{"+reviewer+"} syntax.

 

Here is an example:

const commentOnPR = async (workspaceUuid, repoUuid, pullRequestId, reviewer) => {
    const bodyData = {
        "content": {
          "raw": "The PR has been automatically assigned to @{"+reviewer+"}"
        }
    };

    try {
        const res = await api
        .asApp()
        .requestBitbucket(route`/2.0/repositories/${workspaceUuid}/${repoUuid}/pullrequests/${pullRequestId}/comments`, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(bodyData)
        });
        const data = await res.json();
        
        // the id of the comment that has been created
        return data.id;
    } catch (error) {
        throw error;
    }
}

 

Want to check a real-life example? New to Forge?

If you would like to try this logic out in a fully working app, I’ve created this one for assigning reviewers automatically when creating a PR. The list of reviewers is in defined in each repository via a configuration file that the apps read.

And if you want to know more, check out the documentation and the getting started example.

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events