From 3f998b2e5cb793412a1bf6bb255fbb63dcd82f5c Mon Sep 17 00:00:00 2001 From: g_tron Date: Wed, 27 Jul 2016 20:26:02 +0200 Subject: [PATCH 1/5] Add command to get information of PRs as CSV --- githubStatsPR.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 githubStatsPR.sh diff --git a/githubStatsPR.sh b/githubStatsPR.sh new file mode 100755 index 0000000..309472e --- /dev/null +++ b/githubStatsPR.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +owner=${2:-Wallapop} +repo=${1:-WallapopBackend} + + +function listPRsWithStats { + + github.sh pulls list $owner $repo closed | jsonv number,user.login,head.label,state,created_at,closed_at,merged_at,head.repo.name,comments,review_comments,commits,additions,deletions,changed_files | tr , "\t" + +} + +function getPRStatsFromDetail { + + local idPR=$1 + + [ -z $idPR ] && echo "Error ... please specify the PullRequest ID !" && exit -1 + + local X=$( github.sh pulls get $owner $repo $idPR | grep "^ \"\(comments\"\|review_comments\"\|commits\"\|additions\|deletions\|changed_files\)" | sed "s/.*: //;s/ //g" ); + local A=$(echo $X); + + echo "${A// }" | tr "," "\t" ; + +} + +IFS=$'\n' + +>&2 echo "Retrieving Statistcs of the last 20 PullReques of the repo $owner/$repo" + +for prLine in $(listPRsWithStats); do + + idPR=$( echo $prLine | cut -f 1 ) + + prStats=$( getPRStatsFromDetail $idPR) + + prLine=$(echo "$prLine" | sed -e "s/\t\+$//g;" ) + + + echo -e "$prLine\t$prStats" + + +done + +>&2 echo "Done" \ No newline at end of file From c8bd071611d9113a59e5d49493bc0ec95976447c Mon Sep 17 00:00:00 2001 From: g_tron Date: Wed, 27 Jul 2016 20:27:28 +0200 Subject: [PATCH 2/5] Add state and page parameter to task list of pulls --- lib/v3.d/pulls.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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() { From 34d40e63f38cb7613d12a660516c12cd3ea7da12 Mon Sep 17 00:00:00 2001 From: g_tron Date: Wed, 27 Jul 2016 20:33:34 +0200 Subject: [PATCH 3/5] Fix real path detecting when executable is a link --- github.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/github.sh b/github.sh index 64741b9..5824586 100755 --- a/github.sh +++ b/github.sh @@ -6,12 +6,36 @@ # 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 From 4f131a34ff83fb6f3c940113554a4f34596991dc Mon Sep 17 00:00:00 2001 From: g_tron Date: Wed, 27 Jul 2016 20:50:27 +0200 Subject: [PATCH 4/5] Squashed commit of the following: commit 5bb1e5569fbf5cb65687f4356fc1bc7afc483dfc Author: g_tron Date: Wed Jul 27 20:47:37 2016 +0200 Fix --- githubStatsPR.sh | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100755 githubStatsPR.sh diff --git a/githubStatsPR.sh b/githubStatsPR.sh deleted file mode 100755 index 309472e..0000000 --- a/githubStatsPR.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -owner=${2:-Wallapop} -repo=${1:-WallapopBackend} - - -function listPRsWithStats { - - github.sh pulls list $owner $repo closed | jsonv number,user.login,head.label,state,created_at,closed_at,merged_at,head.repo.name,comments,review_comments,commits,additions,deletions,changed_files | tr , "\t" - -} - -function getPRStatsFromDetail { - - local idPR=$1 - - [ -z $idPR ] && echo "Error ... please specify the PullRequest ID !" && exit -1 - - local X=$( github.sh pulls get $owner $repo $idPR | grep "^ \"\(comments\"\|review_comments\"\|commits\"\|additions\|deletions\|changed_files\)" | sed "s/.*: //;s/ //g" ); - local A=$(echo $X); - - echo "${A// }" | tr "," "\t" ; - -} - -IFS=$'\n' - ->&2 echo "Retrieving Statistcs of the last 20 PullReques of the repo $owner/$repo" - -for prLine in $(listPRsWithStats); do - - idPR=$( echo $prLine | cut -f 1 ) - - prStats=$( getPRStatsFromDetail $idPR) - - prLine=$(echo "$prLine" | sed -e "s/\t\+$//g;" ) - - - echo -e "$prLine\t$prStats" - - -done - ->&2 echo "Done" \ No newline at end of file From 336fad073ffcf78e363c24fa1fa3a81303d33ae9 Mon Sep 17 00:00:00 2001 From: g_tron Date: Wed, 27 Jul 2016 20:53:26 +0200 Subject: [PATCH 5/5] Remove Empty lines --- github.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/github.sh b/github.sh index 5824586..4799f1c 100755 --- a/github.sh +++ b/github.sh @@ -8,10 +8,8 @@ # set -e - set -o pipefail - function get_realpath() { link="$1" @@ -26,7 +24,6 @@ function get_realpath() { echo $link return 0 # success - }