pull-request.sh

changeset 9
7e8ccf76a84d
parent 7
7dbc04a61376
equal deleted inserted replaced
8:90cb48cd977f 9:7e8ccf76a84d
24 24
25 echo "upstream is $upstream" 25 echo "upstream is $upstream"
26 26
27 # Get all heads and filter merges out since we don't generally want to post 27 # Get all heads and filter merges out since we don't generally want to post
28 # pull requests for those. 28 # pull requests for those.
29 allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g') 29 # allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g')
30 heads=$(hg heads --template '{node}\n')
30 i=0 31 i=0
31 32
32 for head in $allheads 33 #for head in $allheads
33 do 34 #do
34 if [ "$(echo $head |sed 's@#@ @g' |wc -w)" -le "1" ] 35 # if [ "$(echo $head |sed 's@#@ @g' |wc -w)" -le "1" ]
35 then 36 # then
36 heads="${heads}$(echo $head |cut -f 1 -d '@') " 37 # heads="${heads}$(echo $head |cut -f 1 -d '@') "
37 fi 38 # fi
38 done 39 #done
39 40
40 if [ -z "$heads" ] 41 #if [ -z "$allheads" ]
41 then 42 #then
42 echo "No non-merge heads. Nothing to do." 43 # echo "No non-merge heads. Nothing to do."
43 exit 0 44 # exit 0
44 fi 45 #fi
45 46
46 numheads=$(echo $heads |wc -w) 47 numheads=$(echo $heads |wc -w)
47 48
48 # Ask the user which head to request pull of. We do this even if there is just 49 # 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. 50 # one head, to give the user a chance to review exactly what is being submitted.
50 echo "There are $numheads non-merge heads:" 51 echo "There are $numheads heads:"
51 52
52 for head in $heads 53 for head in $heads
53 do 54 do
54 let i+=1 55 let i+=1
55 bookmarksblurb="" 56 bookmarksblurb=""
77 # Data for the pull request 78 # Data for the pull request
78 head=$(echo $heads |cut -d ' ' -f $head_index) 79 head=$(echo $heads |cut -d ' ' -f $head_index)
79 title=$(hg log -r ${head} -r tip --template '{desc}') 80 title=$(hg log -r ${head} -r tip --template '{desc}')
80 source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev) 81 source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev)
81 82
82 while [ "$(echo $title |wc -c)" -gt "255" ] 83 titlefile=$(tempfile)
83 do 84 echo "$title" >$titlefile
84 echo "Pull request title is too long, please input a new title" 85 vim $titlefile
85 echo -n "new title: " 86 title=$(cat $titlefile)
86 read title 87
87 done 88 if [ -z "$title" ]
89 then
90 echo "no title given"
91 exit 1
92 fi
93
94 # Ensure history is compressed..
95 upstream_tip=$(hg log -r upstream_tip --template '{node}\n')
96 parents=$(hg log -r $head --debug --template '{parents}\n')
97 p1=$(hg log -r $(echo $parents |cut -f 1 -d ' ') --template '{node}\n')
98 p2=$(hg log -r $(echo $parents |cut -f 2 -d ' ') --template '{node}\n')
99
100 if [ "$p1" != "$upstream_tip" -a "$p2" != "$upstream_tip" ]
101 then
102 echo -n "history isn't compressed! compress now? [y/n] "
103 read answer
104 if [ "$answer" = "y" ]
105 then
106 bookmarks=$(hg log -r $head --template '{bookmarks}')
107 oldhead=$head
108 hg up -r upstream_tip &&
109 hg revert --all -r $head &&
110 hg commit -m "$title" || exit 1
111 head=$(hg id -i)
112 hg bookmarks -f $bookmarks
113 hg up -r $oldhead && hg commit -m "- closed head $oldhead" --close-branch && hg up -r $head
114 fi
115 fi
116
117 # Ensure the head is pushed!
118 if [ -n $( hg outgoing --template '{node}\n' 2>/dev/null |grep $head ) ]
119 then
120 echo -en "$head is not pushed!\npush now? [y/n] "
121 read answer
122 if [ "$answer" != "y" ]
123 then
124 echo "abort: head is not pushed"
125 exit 1
126 fi
127
128 hg push -r $head -f
129 fi
88 130
89 echo "Requesting pull of $head" 131 echo "Requesting pull of $head"
90 132
91 # Get the JSON template and fill in the values 133 # Get the JSON template and fill in the values
92 json=$(cat $selfpath/pullrequest_template.json \ 134 json=$(cat $selfpath/pullrequest_template.json \
93 |sed "s@{{TITLE}}@${title}@" \ 135 |sed "s@{{TITLE}}@${title}@" \
94 |sed "s@{{SOURCE_REPO}}@${source_repo}@" \ 136 |sed "s@{{SOURCE_REPO}}@${source_repo}@" \
95 |sed "s@{{HEAD}}@${head}@") 137 |sed "s@{{HEAD}}@${head}@")
96 138
97 # Get bitbucket credentials 139 # Get bitbucket credentials
98 echo -n "Username: " 140 echo -n "username: "
99 read username 141 read username
100 echo -n "Password: " 142 echo -n "password: "
101 read -s password 143 read -s password
102 echo 144 echo
103 145
104 response=$(tempfile) 146 response=$(tempfile)
105 147

mercurial