aboutsummaryrefslogtreecommitdiff
path: root/number-of-pr-in
blob: a32e4b5b2ee0b6277e6c2588278a24d48d4ad555 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
#
# number-of-pr-in
# Author : Clyhtsuriva

usage () {
	echo "Usage: number-of-pr-in <repository>"
	exit 1
}

number-of-pr-in () {

	[ $# -eq 1 ] || usage

	GH_REPO=void-linux/$1
	LIMIT=1000 # Search API => 1000 results max

	gh repo view "$GH_REPO" 1> /dev/null || exit 1

	GH_PR_LIST=$(gh pr list \
		--repo "$GH_REPO" \
		--author "@me" \
		--state merged \
		--limit $LIMIT)

	PARSED=$(echo "$GH_PR_LIST" | \
		awk '{ print $2 }' | \
		sed 's/://g' | \
		sort | \
		uniq -c | \
		sort -nr | \
		sed 's/      //g')


	COLOR_ON=$(tput setaf 3; tput bold)
	COLOR_OFF=$(tput sgr0)

	# shellcheck disable=SC2001
	echo "$PARSED" | sed "s/[^[:blank:]]\{1,\}/$COLOR_ON&$COLOR_OFF/1"
}

number-of-pr-in "$@"