Sun, 08 Jun 2014 17:00:52 +0300
- initial commit (added pull-request.sh)
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 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | 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
|
11 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | if [ -z "$upstream" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | then |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 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
|
15 | exit 1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | fi |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | echo "upstream is $upstream" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | 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
|
21 | i=0 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | for head in $allheads |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | 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
|
26 | then |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | heads="${heads}$(echo $head |cut -f 1 -d '@') " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | fi |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | numheads=$(echo $heads |wc -w) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | echo "There are $numheads non-merge heads:" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | for head in $heads |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | let i+=1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | bookmarksblurb="" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | tmpfile=$(tempfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | 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
|
41 | bookmarks=$(head -n1 $tmpfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | title=$(tail -n1 $tmpfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | rm $tmpfile |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | if [ -n "$bookmarks" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | then |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | bookmarksblurb=" [${bookmarks}]" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | fi |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | echo "[${i}] $(echo $head |head -c 8)${bookmarksblurb}: $title" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | head_index=-1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | 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
|
55 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | echo -n "Which head? " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | read head_index |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | head=$(echo $heads |cut -d ' ' -f $head_index) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | title=$(hg log -r ${head} -r tip --template '{desc}')yy |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | 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
|
63 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | while [ "$(echo $title |wc -c)" -gt "255" ] |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | do |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | 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
|
67 | echo -n "new title: " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | read title |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | done |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | echo "Requesting pull of $head" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | json=$(cat ~/.bin/pullreq_template.json \ |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |sed "s@{{TITLE}}@${title}@" \ |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | |sed "s@{{SOURCE_REPO}}@${source_repo}@" \ |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |sed "s@{{HEAD}}@${head}@") |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | jsonfile=$(tempfile) |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | echo $json >$jsonfile |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | echo -n "Username: " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | read username |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | echo -n "Password: " |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | read -s password |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | echo |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | response=$(tempfile) |
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 | curl -X POST -H "Content-Type: application/json" -u "${username}:${password}" \ |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" -d "$json" -o "$response" >/dev/stdout 2>&1 |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | echo "repsonse: $response" |
9a7158f91b97
- initial commit (added pull-request.sh)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | rm $jsonfile |