diff --git a/github.sh b/github.sh index 64741b9..4799f1c 100755 --- a/github.sh +++ b/github.sh @@ -6,12 +6,33 @@ # description: # GitHub API Client # + set -e set -o pipefail +function get_realpath() { + + link="$1" + while [ -L "$link" ]; do + lastLink="$link" + link=$(/bin/ls -ldq "$link") + link="${link##* -> }" + link=$(realpath "$link") + [ "$link" == "$lastlink" ] && >&2 echo -e "ERROR: link loop detected on $link" && return 1 # error + done + + echo $link + + return 0 # success +} + + # include files -. ${BASH_SOURCE[0]%/*}/lib/initializer.sh +BASENAME=$(cd $(dirname "$(get_realpath $0)") && pwd -P) + + +. ${BASENAME}/lib/initializer.sh # main diff --git a/lib/v3.d/pulls.sh b/lib/v3.d/pulls.sh index a4a0ec5..f808339 100644 --- a/lib/v3.d/pulls.sh +++ b/lib/v3.d/pulls.sh @@ -5,10 +5,21 @@ task_list() { # http://developer.github.com/v3/pulls/#list-pull-requests - local owner=$1 repo=$2 + local owner=$1 repo=$2 state=$3 page=$4 + + call_api -X GET \ + "$(base_uri)/repos/${owner}/${repo}/pulls?$(query_string \ + $(add_param state string optional) \ + $(add_param page string optional) \ + )" +} + +task_diff() { + # http://developer.github.com/v3/pulls/#get-a-single-pull-request + local owner=$1 repo=$2 number=$3 call_api -X GET \ - $(base_uri)/repos/${owner}/${repo}/pulls?state=${state:-open} + $(base_uri)/repos/${owner}/${repo}/pulls/${number}/files } task_get() {