From 3f998b2e5cb793412a1bf6bb255fbb63dcd82f5c Mon Sep 17 00:00:00 2001 From: g_tron Date: Wed, 27 Jul 2016 20:26:02 +0200 Subject: [PATCH 1/9] 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/9] 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/9] 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 eafc519bf8fbecf923b31919cdf929ccd08cc58d Mon Sep 17 00:00:00 2001 From: g_tron Date: Thu, 25 Aug 2016 19:48:06 +0200 Subject: [PATCH 4/9] Add page on pulls list --- githubStatsPR.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/githubStatsPR.sh b/githubStatsPR.sh index 309472e..27d69d3 100755 --- a/githubStatsPR.sh +++ b/githubStatsPR.sh @@ -2,11 +2,12 @@ owner=${2:-Wallapop} repo=${1:-WallapopBackend} +page=${3:-} 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" + github.sh pulls list $owner $repo closed $page | 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" } @@ -41,4 +42,4 @@ for prLine in $(listPRsWithStats); do done ->&2 echo "Done" \ No newline at end of file +>&2 echo "Done" From ec5566d9f71e2089d49ced0e61af8b3acfd5ba56 Mon Sep 17 00:00:00 2001 From: g_tron Date: Thu, 15 Sep 2016 12:30:10 +0200 Subject: [PATCH 5/9] Add search task to Pull Requests --- lib/v3.d/pulls.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/v3.d/pulls.sh b/lib/v3.d/pulls.sh index f808339..2743112 100644 --- a/lib/v3.d/pulls.sh +++ b/lib/v3.d/pulls.sh @@ -5,7 +5,7 @@ task_list() { # http://developer.github.com/v3/pulls/#list-pull-requests - local owner=$1 repo=$2 state=$3 page=$4 + local owner=$1 repo=$2 state=$3 page=$4 call_api -X GET \ "$(base_uri)/repos/${owner}/${repo}/pulls?$(query_string \ @@ -14,6 +14,15 @@ task_list() { )" } +task_search() { + # 'https://api.github.com:443/search/issues?q=is:pr+state:open+repo:xx+head:feature/xxw' + local owner=$1 repo=$2 state=$3 head=$4 + + call_api -X GET \ + "$(base_uri)/search/issues?q=is:pr+state:$state+repo:$owner/$repo+head:$head" + +} + task_diff() { # http://developer.github.com/v3/pulls/#get-a-single-pull-request local owner=$1 repo=$2 number=$3 From 0cc5ccf39581f870cc839044756483e92f041747 Mon Sep 17 00:00:00 2001 From: g_tron Date: Mon, 19 Sep 2016 17:59:00 +0200 Subject: [PATCH 6/9] Add command to search pull requests --- lib/v3.d/pulls.sh | 2 +- test/unit/v3/t.pulls.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/v3.d/pulls.sh b/lib/v3.d/pulls.sh index 2743112..620e1a1 100644 --- a/lib/v3.d/pulls.sh +++ b/lib/v3.d/pulls.sh @@ -19,7 +19,7 @@ task_search() { local owner=$1 repo=$2 state=$3 head=$4 call_api -X GET \ - "$(base_uri)/search/issues?q=is:pr+state:$state+repo:$owner/$repo+head:$head" + "$(base_uri)/search/issues?q=is:pr+state:${state:-open}+repo:$owner/$repo+head:$head" } diff --git a/test/unit/v3/t.pulls.sh b/test/unit/v3/t.pulls.sh index aecde63..e93d9eb 100755 --- a/test/unit/v3/t.pulls.sh +++ b/test/unit/v3/t.pulls.sh @@ -28,6 +28,12 @@ function test_list() { assertEquals 0 $? } +function test_search() { + extract_args ${namespace} search + run_cmd ${COMMAND_ARGS} + assertEquals 0 $? +} + function test_get() { extract_args ${namespace} get run_cmd ${COMMAND_ARGS} From d7afdae5f0b936f34efb3ec14a571018e5661410 Mon Sep 17 00:00:00 2001 From: g_tron Date: Mon, 19 Sep 2016 18:02:26 +0200 Subject: [PATCH 7/9] Add Dockerfile --- docker/Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docker/Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..da8d8a6 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine +MAINTAINER Gianluca Mereu + + + From cb9b7173c1e0548a4de37caccd9a7a549c3690be Mon Sep 17 00:00:00 2001 From: g_tron Date: Tue, 21 Feb 2017 15:47:18 +0100 Subject: [PATCH 8/9] Add commits and repos --- githubStatsPR.sh | 2 +- lib/v3.d/commits.sh | 14 +++++++++++++ lib/v3.d/orgs.sh_new | 50 ++++++++++++++++++++++++++++++++++++++++++++ lib/v3.d/pulls.sh | 4 ++-- lib/v3.d/repos.sh | 36 +++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 lib/v3.d/commits.sh create mode 100644 lib/v3.d/orgs.sh_new create mode 100644 lib/v3.d/repos.sh diff --git a/githubStatsPR.sh b/githubStatsPR.sh index 27d69d3..ea52fd2 100755 --- a/githubStatsPR.sh +++ b/githubStatsPR.sh @@ -7,7 +7,7 @@ page=${3:-} function listPRsWithStats { - github.sh pulls list $owner $repo closed $page | 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" + github.sh pulls list $owner $repo closed $page | jsonv number,user.login,head.label,base.label,state,created_at,closed_at,merged_at,head.repo.name,comments,review_comments,commits,additions,deletions,changed_files | tr , "\t" } diff --git a/lib/v3.d/commits.sh b/lib/v3.d/commits.sh new file mode 100644 index 0000000..0c722f4 --- /dev/null +++ b/lib/v3.d/commits.sh @@ -0,0 +1,14 @@ +# -*-Shell-script-*- +# + +. ${BASH_SOURCE[0]%/*}/base.sh + + +task_get() { + # http://developer.github.com/v3/repos/hooks/#json-http + # /repos/:owner/:repo/git/commits/:sha + local owner=$1 repo=$2 id=$3 + + call_api -X GET \ + $(base_uri)/repos/${owner}/${repo}/git/commits/${id} +} diff --git a/lib/v3.d/orgs.sh_new b/lib/v3.d/orgs.sh_new new file mode 100644 index 0000000..711e5ef --- /dev/null +++ b/lib/v3.d/orgs.sh_new @@ -0,0 +1,50 @@ +# -*-Shell-script-*- +# + +. ${BASH_SOURCE[0]%/*}/base.sh + +task_user_list() { + # http://developer.github.com/v3/orgs/#list-user-organizations + local user=$1 + + call_api -X GET \ + $(base_uri)/users/${user}/orgs +} + +task_org_list() { + # http://developer.github.com/v3/orgs/#list-user-organizations + + call_api -X GET \ + $(base_uri)/user/orgs +} + +task_repos_list() { + # http://developer.github.com/v3/orgs/#list-user-organizations + + call_api -X GET \ + $(base_uri)/user/orgs +} + +task_get() { + # http://developer.github.com/v3/orgs/#get-an-organization + local org=$1 + + call_api -X GET \ + $(base_uri)/orgs/${org} +} + +task_update() { + # http://developer.github.com/v3/orgs/#edit-an-organization + local org=$1 + + call_api -X PATCH --data @- \ + $(base_uri)/orgs/${org} <<-EOS + { + "billing_email": "${billing_email}", + "company": "${company}", + "email": "${email}", + "location": "${location}", + "name": "${name}" + } + EOS +} diff --git a/lib/v3.d/pulls.sh b/lib/v3.d/pulls.sh index 620e1a1..3f5ea9c 100644 --- a/lib/v3.d/pulls.sh +++ b/lib/v3.d/pulls.sh @@ -16,10 +16,10 @@ task_list() { task_search() { # 'https://api.github.com:443/search/issues?q=is:pr+state:open+repo:xx+head:feature/xxw' - local owner=$1 repo=$2 state=$3 head=$4 + local owner=$1 repo=$2 state=$3 commitId=$4 call_api -X GET \ - "$(base_uri)/search/issues?q=is:pr+state:${state:-open}+repo:$owner/$repo+head:$head" + "$(base_uri)/search/issues?q=is:pr+state:${state:-open}+repo:$owner/$repo+$commitId" } diff --git a/lib/v3.d/repos.sh b/lib/v3.d/repos.sh new file mode 100644 index 0000000..ff1d693 --- /dev/null +++ b/lib/v3.d/repos.sh @@ -0,0 +1,36 @@ +# -*-Shell-script-*- +# + +. ${BASH_SOURCE[0]%/*}/base.sh + +task_list() { + # http://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref + local owner=$1 type=$2 sort=$3 direction=$4 + + local url="users/$owner/repos" + [ -z $owner ] && url="user/repos" + + set -x + + call_api -X GET \ + "$(base_uri)/$url?$(query_string \ + $(add_param type string optional) \ + $(add_param sort string optional) \ + $(add_param direction string optional) \ + )" + +} + +task_new() { + # http://developer.github.com/v3/repos/statuses/#create-a-status + local owner=$1 repo=$2 sha=$3 + + call_api -X POST --data @- \ + $(base_uri)/repos/${owner}/${repo}/statuses/${sha} <<-EOS + { + "state": "${state}", + "target_url": "${target_url}", + "description": "${description}" + } + EOS +} From 96311dbaa5af0faaf286867ea977b2471a41b119 Mon Sep 17 00:00:00 2001 From: g_tron Date: Tue, 21 Feb 2017 23:27:35 +0100 Subject: [PATCH 9/9] Changed from jsonv to jq --- githubStatsPR.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/githubStatsPR.sh b/githubStatsPR.sh index ea52fd2..088d4b6 100755 --- a/githubStatsPR.sh +++ b/githubStatsPR.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash owner=${2:-Wallapop} repo=${1:-WallapopBackend} @@ -6,8 +6,12 @@ page=${3:-} function listPRsWithStats { - - github.sh pulls list $owner $repo closed $page | jsonv number,user.login,head.label,base.label,state,created_at,closed_at,merged_at,head.repo.name,comments,review_comments,commits,additions,deletions,changed_files | tr , "\t" + +# >&2 echo -e "github.sh pulls list $owner $repo closed $page | jq -M -r -c '.[] | { number , login: .user.login, from: .head.label, to: .base.label, state, created_at, closed_at, merged_at, repo: .head.repo.name, commends, review_comments, commits, additions, deletions, changed_file } ' | sed 's/\"[^\"]\+\"://g;s/\"\?,\"\?/\t/g;s/^{//;s/}$//'" + +# github.sh pulls list $owner $repo closed $page | jsonv number,user.login,head.label,base.label,state,created_at,closed_at,merged_at,head.repo.name,comments,review_comments,commits,additions,deletions,changed_files | tr , "\t" +# github.sh pulls list $owner $repo closed $page | jq -M -r -c '.[] | { number , login: .user.login, from: .head.label, to: .base.label, state, created_at, closed_at, merged_at, repo: .head.repo.name, comments, review_comments, commits, additions, deletions, changed_file } ' | sed 's/\"[^\"]\+\"://g;s/\"\?,\"\?/\t/g;s/^{//;s/}$//' + github.sh pulls list $owner $repo closed $page | jq -M -r -c '.[] | { number , login: .user.login, from: .head.label, to: .base.label, state, created_at, closed_at, merged_at, repo: .head.repo.name } ' | sed 's/\"[^\"]\+\"://g;s/\"\?,\"\?/\t/g;s/^{//;s/}$//' } @@ -17,6 +21,8 @@ function getPRStatsFromDetail { [ -z $idPR ] && echo "Error ... please specify the PullRequest ID !" && exit -1 +#>&2 echo "Retrieving PR $idPR" + 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);