pull-request.sh

changeset 0
9a7158f91b97
child 3
b328fdc09692
equal deleted inserted replaced
-1:000000000000 0:9a7158f91b97
1 #!/bin/bash
2 hg log -r tip >/dev/null || exit 1
3
4 if [ -z "$(which curl)" ]
5 then
6 echo "no curl installed" >/dev/stderr
7 exit 1
8 fi
9
10 upstream=$(hg paths upstream |rev |cut -d '/' -f 1,2 |rev)
11
12 if [ -z "$upstream" ]
13 then
14 echo "cannot find upstream! Please set the 'upstream' path in .hg/hgrc" >/dev/stderr
15 exit 1
16 fi
17
18 echo "upstream is $upstream"
19
20 allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g')
21 i=0
22
23 for head in $allheads
24 do
25 if [ "$(echo $head |sed 's@#@ @g' |wc -w)" -le "1" ]
26 then
27 heads="${heads}$(echo $head |cut -f 1 -d '@') "
28 fi
29 done
30
31 numheads=$(echo $heads |wc -w)
32
33 echo "There are $numheads non-merge heads:"
34
35 for head in $heads
36 do
37 let i+=1
38 bookmarksblurb=""
39 tmpfile=$(tempfile)
40 hg log -r $head --template '{bookmarks}\n{desc}\n' >$tmpfile
41 bookmarks=$(head -n1 $tmpfile)
42 title=$(tail -n1 $tmpfile)
43 rm $tmpfile
44
45 if [ -n "$bookmarks" ]
46 then
47 bookmarksblurb=" [${bookmarks}]"
48 fi
49
50 echo "[${i}] $(echo $head |head -c 8)${bookmarksblurb}: $title"
51 done
52
53 head_index=-1
54 while [ "$head_index" -le "0" -o "$head_index" -gt "$numheads" ]
55 do
56 echo -n "Which head? "
57 read head_index
58 done
59
60 head=$(echo $heads |cut -d ' ' -f $head_index)
61 title=$(hg log -r ${head} -r tip --template '{desc}')yy
62 source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev)
63
64 while [ "$(echo $title |wc -c)" -gt "255" ]
65 do
66 echo "Pull request title is too long, please input a new title"
67 echo -n "new title: "
68 read title
69 done
70
71 echo "Requesting pull of $head"
72
73 json=$(cat ~/.bin/pullreq_template.json \
74 |sed "s@{{TITLE}}@${title}@" \
75 |sed "s@{{SOURCE_REPO}}@${source_repo}@" \
76 |sed "s@{{HEAD}}@${head}@")
77
78 jsonfile=$(tempfile)
79 echo $json >$jsonfile
80
81 echo -n "Username: "
82 read username
83 echo -n "Password: "
84 read -s password
85 echo
86
87 response=$(tempfile)
88
89 curl -X POST -H "Content-Type: application/json" -u "${username}:${password}" \
90 "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" -d "$json" -o "$response" >/dev/stdout 2>&1
91
92 echo "repsonse: $response"
93 rm $jsonfile

mercurial