Sun, 08 Jun 2014 23:38:04 +0300
- removed the rest of the python thing, that doesn't work right
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #!/bin/bash |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | hg log -r tip >/dev/null || exit 1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | if [ -z "$(which curl)" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | then |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | echo "no curl installed" >/dev/stderr |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | exit 1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | fi |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
10 | # Get path to this script |
4
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
11 | pushd $(dirname $0) >/dev/null |
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
12 | selfpath=$(dirname $(readlink $0)) |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
13 | popd >/dev/null |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
14 | |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
15 | # What's the upstream? |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
16 | # TODO: can this be dynamically retrieved from bitbucket? |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | upstream=$(hg paths upstream |rev |cut -d '/' -f 1,2 |rev) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | if [ -z "$upstream" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | then |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | echo "cannot find upstream! Please set the 'upstream' path in .hg/hgrc" >/dev/stderr |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | exit 1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | fi |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | echo "upstream is $upstream" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
27 | # Get all heads and filter merges out since we don't generally want to post |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
28 | # pull requests for those. |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g') |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | i=0 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | for head in $allheads |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | if [ "$(echo $head |sed 's@#@ @g' |wc -w)" -le "1" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | then |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | heads="${heads}$(echo $head |cut -f 1 -d '@') " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | fi |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
40 | if [ -z "$heads" ] |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
41 | then |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
42 | echo "No non-merge heads. Nothing to do." |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
43 | exit 0 |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
44 | fi |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
45 | |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | numheads=$(echo $heads |wc -w) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
48 | # Ask the user which head to request pull of. We do this even if there is just |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
49 | # one head, to give the user a chance to review exactly what is being submitted. |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | echo "There are $numheads non-merge heads:" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | for head in $heads |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | let i+=1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | bookmarksblurb="" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | tmpfile=$(tempfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | hg log -r $head --template '{bookmarks}\n{desc}\n' >$tmpfile |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | bookmarks=$(head -n1 $tmpfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | title=$(tail -n1 $tmpfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | rm $tmpfile |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | if [ -n "$bookmarks" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | then |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | bookmarksblurb=" [${bookmarks}]" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | fi |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | echo "[${i}] $(echo $head |head -c 8)${bookmarksblurb}: $title" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | head_index=-1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | while [ "$head_index" -le "0" -o "$head_index" -gt "$numheads" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | echo -n "Which head? " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | read head_index |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
77 | # Data for the pull request |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | head=$(echo $heads |cut -d ' ' -f $head_index) |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
79 | title=$(hg log -r ${head} -r tip --template '{desc}') |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | while [ "$(echo $title |wc -c)" -gt "255" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | echo "Pull request title is too long, please input a new title" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | echo -n "new title: " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | read title |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | echo "Requesting pull of $head" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
91 | # Get the JSON template and fill in the values |
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
92 | json=$(cat $selfpath/pullrequest_template.json \ |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |sed "s@{{TITLE}}@${title}@" \ |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |sed "s@{{SOURCE_REPO}}@${source_repo}@" \ |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |sed "s@{{HEAD}}@${head}@") |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
97 | # Get bitbucket credentials |
0
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | echo -n "Username: " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | read username |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | echo -n "Password: " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | read -s password |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | echo |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | response=$(tempfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
3
b328fdc09692
- add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
106 | # Post the pull request. |
4
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
107 | curl \ |
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
108 | -X POST \ |
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
109 | -H "Content-Type: application/json" \ |
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
110 | -u "${username}:${password}" \ |
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
111 | -d "$json" \ |
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
112 | -o "$response" \ |
7c02e457e6ab
- added automatic tracker updating but commented it out since it also bumps timestamps on every note on said ticket...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
113 | "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" \ |
5
9d63b4f82112
- axed the python interfacing part completely..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
114 | >/dev/stdout 2>&1 |