# HG changeset patch # User Santeri Piippo # Date 1402237042 -10800 # Node ID b328fdc09692c9ed27bb0a96d7ea9319966bad3c # Parent 9eaddccce1ce3919e5d49eee33758abda7aed150 - add commentary to pull-request.sh, added missing template JSON, fixed copyright year in LICENSE diff -r 9eaddccce1ce -r b328fdc09692 LICENSE --- a/LICENSE Sun Jun 08 17:04:26 2014 +0300 +++ b/LICENSE Sun Jun 08 17:17:22 2014 +0300 @@ -1,5 +1,5 @@ - Copyright 2012-2014 Santeri Piippo + Copyright 2014 Santeri Piippo All rights reserved. Redistribution and use in source and binary forms, with or without diff -r 9eaddccce1ce -r b328fdc09692 pull-request.sh --- a/pull-request.sh Sun Jun 08 17:04:26 2014 +0300 +++ b/pull-request.sh Sun Jun 08 17:17:22 2014 +0300 @@ -7,6 +7,13 @@ exit 1 fi +# Get path to this script +pushd `dirname $0` >/dev/null + selfpath=`pwd` +popd >/dev/null + +# What's the upstream? +# TODO: can this be dynamically retrieved from bitbucket? upstream=$(hg paths upstream |rev |cut -d '/' -f 1,2 |rev) if [ -z "$upstream" ] @@ -17,6 +24,8 @@ echo "upstream is $upstream" +# Get all heads and filter merges out since we don't generally want to post +# pull requests for those. allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g') i=0 @@ -28,8 +37,16 @@ fi done +if [ -z "$heads" ] +then + echo "No non-merge heads. Nothing to do." + exit 0 +fi + numheads=$(echo $heads |wc -w) +# Ask the user which head to request pull of. We do this even if there is just +# one head, to give the user a chance to review exactly what is being submitted. echo "There are $numheads non-merge heads:" for head in $heads @@ -57,8 +74,9 @@ read head_index done +# Data for the pull request head=$(echo $heads |cut -d ' ' -f $head_index) -title=$(hg log -r ${head} -r tip --template '{desc}')yy +title=$(hg log -r ${head} -r tip --template '{desc}') source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev) while [ "$(echo $title |wc -c)" -gt "255" ] @@ -70,14 +88,13 @@ echo "Requesting pull of $head" -json=$(cat ~/.bin/pullreq_template.json \ +# Get the JSON template and fill in the values +json=$(cat $selfpath/pullrequest_template.json \ |sed "s@{{TITLE}}@${title}@" \ |sed "s@{{SOURCE_REPO}}@${source_repo}@" \ |sed "s@{{HEAD}}@${head}@") -jsonfile=$(tempfile) -echo $json >$jsonfile - +# Get bitbucket credentials echo -n "Username: " read username echo -n "Password: " @@ -86,8 +103,8 @@ response=$(tempfile) +# Post the pull request. curl -X POST -H "Content-Type: application/json" -u "${username}:${password}" \ "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" -d "$json" -o "$response" >/dev/stdout 2>&1 -echo "repsonse: $response" -rm $jsonfile +echo "response JSON: $response" diff -r 9eaddccce1ce -r b328fdc09692 pullrequest_template.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pullrequest_template.json Sun Jun 08 17:17:22 2014 +0300 @@ -0,0 +1,18 @@ +{ + "title": "{{TITLE}}", + "source": + { + "branch": + { + "name": "default" + }, + "repository": + { + "full_name": "{{SOURCE_REPO}}" + }, + "commit": + { + "hash": "{{HEAD}}" + } + } +}