x

Programs, configuration and documentation that don't fit anywhere else
Log | Files | Refs | README | LICENSE

bbpr (937B)


      1 #!/bin/sh
      2 
      3 # https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests
      4 
      5 confpath="$HOME/.config/atlassian/bitbucket.org"
      6 if ! test -f $confpath
      7 then
      8 	echo "load auth from $confpath: no such file"
      9 	exit 1
     10 fi
     11 auth=`sed 1q $confpath`
     12 
     13 repo=`git remote get-url origin | awk -F : '{print $2}' | sed 's/\.git$//'`
     14 
     15 dest=main
     16 if git branch --list master | grep master > /dev/null
     17 then
     18 	dest=master
     19 elif test -n $1
     20 then
     21 	dest=$1
     22 fi
     23 
     24 cover=`mktemp`
     25 git log $dest.. | grep -v '^commit' > $cover
     26 
     27 if test -n $EDITOR
     28 then
     29 	EDITOR=ed
     30 fi
     31 $EDITOR $cover
     32 title=`sed -n 1p $cover`
     33 description=`awk 'NR > 2 { print }' $cover`
     34 rm $cover
     35 
     36 source=`git branch | grep '^\*' | awk '{print $2}'`
     37 body=`jq -c <<EOF
     38 {
     39 	"title": "$title",
     40 	"description": "$description",
     41 	"source": {
     42 		"branch": { "name": "$source" }
     43 	}
     44 }
     45 EOF`
     46 
     47 curl -s -u "$auth" --json "$body" https://api.bitbucket.org/2.0/repositories/$repo/pullrequests | jq .links.html.href