3

what is the command to create a new pull request in Bitbucket.

I am automating the check-in the code to Bitbucket and create pull request.

I referred many documents and found the curl command. but it is also not working and I don't know the what is the use of each module in that command.

see the below command that I have tried.

curl -u username:Password -H "Content-Type: application/jso https://bitbucket.server.com/rest/api/1.0/projects/myProject/repos/myRepo/pull-requests -X POST --data @req.json

created the req.json file, copied the content to file see the below content that I copied.

{"title":"test","description":"test","fromRef":{"id":"refs/heads/del","repository":{"slug":"BB_repo","name":null}},"toRef":{"id":"refs/heads/master","repository":{"slug":"BB_repo","name":null}}}

can anyone suggest me the better way to create pull request? I need some explanation as I'm new to Bitbucket

dubru
  • 142
  • 10

1 Answers1

1

Using a bitbucket personal access token, you could create an alias or adapt these to a script.

Global Config

[bitbucket]
        url = https://bitbucket.<domain>/rest/api/latest/projects/<proj>/repos/<repo>/pull-requests
        token = <Enter PAT Here>
[alias "pr"]
        m = "!f() { B=$(git branch-name);D=$(git pr.data $B master);U=$(git config --get bitbucket.url);J=$(git pr.json);T=$(git pr.token);C=$(echo curl -X POST $U -H $T -H $J -d $D;); eval $C; }; f"
        d = "!f() { B=$(git branch-name);D=$(git pr.data $B develop);U=$(git config --get bitbucket.url);J=$(git pr.json);T=$(git pr.token);C=$(echo curl -X POST $U -H $T -H $J -d $D;); eval $C; }; f"
        json = "!echo '\"Content-Type: application/json\"'"
        token = "!echo '\"Authorization: Bearer '$(git config --get bitbucket.token)'\"'"
        data = !sh -c 'echo -e \"\\x27{\\\"title\\\":\\\"$1 - $2\\\",\\\"fromRef\\\":{\\\"id\\\":\\\"refs/heads/$1\\\"},\\\"toRef\\\":{\\\"id\\\":\\\"refs/heads/$2\\\"""}}\\x27\"' -
[alias]
        branch-name = !git rev-parse --abbrev-ref HEAD

Usage:

git pr.m
git pr.d
Brantley Blanchard
  • 1,208
  • 3
  • 14
  • 23