| 5 then |
5 then |
| 6 echo "no curl installed" >/dev/stderr |
6 echo "no curl installed" >/dev/stderr |
| 7 exit 1 |
7 exit 1 |
| 8 fi |
8 fi |
| 9 |
9 |
| |
10 # Get path to this script |
| |
11 pushd `dirname $0` >/dev/null |
| |
12 selfpath=`pwd` |
| |
13 popd >/dev/null |
| |
14 |
| |
15 # What's the upstream? |
| |
16 # TODO: can this be dynamically retrieved from bitbucket? |
| 10 upstream=$(hg paths upstream |rev |cut -d '/' -f 1,2 |rev) |
17 upstream=$(hg paths upstream |rev |cut -d '/' -f 1,2 |rev) |
| 11 |
18 |
| 12 if [ -z "$upstream" ] |
19 if [ -z "$upstream" ] |
| 13 then |
20 then |
| 14 echo "cannot find upstream! Please set the 'upstream' path in .hg/hgrc" >/dev/stderr |
21 echo "cannot find upstream! Please set the 'upstream' path in .hg/hgrc" >/dev/stderr |
| 15 exit 1 |
22 exit 1 |
| 16 fi |
23 fi |
| 17 |
24 |
| 18 echo "upstream is $upstream" |
25 echo "upstream is $upstream" |
| 19 |
26 |
| |
27 # Get all heads and filter merges out since we don't generally want to post |
| |
28 # pull requests for those. |
| 20 allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g') |
29 allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g') |
| 21 i=0 |
30 i=0 |
| 22 |
31 |
| 23 for head in $allheads |
32 for head in $allheads |
| 24 do |
33 do |
| 26 then |
35 then |
| 27 heads="${heads}$(echo $head |cut -f 1 -d '@') " |
36 heads="${heads}$(echo $head |cut -f 1 -d '@') " |
| 28 fi |
37 fi |
| 29 done |
38 done |
| 30 |
39 |
| |
40 if [ -z "$heads" ] |
| |
41 then |
| |
42 echo "No non-merge heads. Nothing to do." |
| |
43 exit 0 |
| |
44 fi |
| |
45 |
| 31 numheads=$(echo $heads |wc -w) |
46 numheads=$(echo $heads |wc -w) |
| 32 |
47 |
| |
48 # Ask the user which head to request pull of. We do this even if there is just |
| |
49 # one head, to give the user a chance to review exactly what is being submitted. |
| 33 echo "There are $numheads non-merge heads:" |
50 echo "There are $numheads non-merge heads:" |
| 34 |
51 |
| 35 for head in $heads |
52 for head in $heads |
| 36 do |
53 do |
| 37 let i+=1 |
54 let i+=1 |
| 55 do |
72 do |
| 56 echo -n "Which head? " |
73 echo -n "Which head? " |
| 57 read head_index |
74 read head_index |
| 58 done |
75 done |
| 59 |
76 |
| |
77 # Data for the pull request |
| 60 head=$(echo $heads |cut -d ' ' -f $head_index) |
78 head=$(echo $heads |cut -d ' ' -f $head_index) |
| 61 title=$(hg log -r ${head} -r tip --template '{desc}')yy |
79 title=$(hg log -r ${head} -r tip --template '{desc}') |
| 62 source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev) |
80 source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev) |
| 63 |
81 |
| 64 while [ "$(echo $title |wc -c)" -gt "255" ] |
82 while [ "$(echo $title |wc -c)" -gt "255" ] |
| 65 do |
83 do |
| 66 echo "Pull request title is too long, please input a new title" |
84 echo "Pull request title is too long, please input a new title" |
| 68 read title |
86 read title |
| 69 done |
87 done |
| 70 |
88 |
| 71 echo "Requesting pull of $head" |
89 echo "Requesting pull of $head" |
| 72 |
90 |
| 73 json=$(cat ~/.bin/pullreq_template.json \ |
91 # Get the JSON template and fill in the values |
| |
92 json=$(cat $selfpath/pullrequest_template.json \ |
| 74 |sed "s@{{TITLE}}@${title}@" \ |
93 |sed "s@{{TITLE}}@${title}@" \ |
| 75 |sed "s@{{SOURCE_REPO}}@${source_repo}@" \ |
94 |sed "s@{{SOURCE_REPO}}@${source_repo}@" \ |
| 76 |sed "s@{{HEAD}}@${head}@") |
95 |sed "s@{{HEAD}}@${head}@") |
| 77 |
96 |
| 78 jsonfile=$(tempfile) |
97 # Get bitbucket credentials |
| 79 echo $json >$jsonfile |
|
| 80 |
|
| 81 echo -n "Username: " |
98 echo -n "Username: " |
| 82 read username |
99 read username |
| 83 echo -n "Password: " |
100 echo -n "Password: " |
| 84 read -s password |
101 read -s password |
| 85 echo |
102 echo |
| 86 |
103 |
| 87 response=$(tempfile) |
104 response=$(tempfile) |
| 88 |
105 |
| |
106 # Post the pull request. |
| 89 curl -X POST -H "Content-Type: application/json" -u "${username}:${password}" \ |
107 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 |
108 "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" -d "$json" -o "$response" >/dev/stdout 2>&1 |
| 91 |
109 |
| 92 echo "repsonse: $response" |
110 echo "response JSON: $response" |
| 93 rm $jsonfile |
|