Skip to content

Commit 6740614

Browse files
Merge pull request #14 from joshjohanning/joshjohanning/get-pull-requests
Adding get pull request scripts
2 parents 089b0a3 + f0ab380 commit 6740614

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

gh-cli/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ Retrieve the download URL for a specific version of a package in GitHub Packages
372372
> **Note:**
373373
> No longer works for GitHub.com and deprecated for GHES 3.7+. See [Changelog post](https://github.blog/changelog/2022-08-18-deprecation-notice-graphql-for-packages/), [GraphQL breaking changes](https://docs.github.com/en/graphql/overview/breaking-changes#changes-scheduled-for-2022-11-21-1), and [GHES 3.7 deprecations](https://docs.github.com/en/[email protected]/admin/release-notes#3.7.0-deprecations)
374374
375+
## get-pull-requests-in-organization.sh
376+
377+
Gets the pull requests in an organization
378+
379+
## get-pull-requests-in-repository.sh
380+
381+
Gets the pull requests in a repository
382+
375383
## get-releases.sh
376384

377385
Gets a list of releases for a repository
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
pr_states=("open" "closed" "all")
4+
5+
if [ $# -lt 1 ]
6+
then
7+
echo "usage: $(basename $0) <org> <pr_state>"
8+
exit 1
9+
fi
10+
11+
org=$1
12+
pr_state=$3
13+
14+
# set the default for pr_status to be all
15+
if [ -z "$pr_state" ]
16+
then
17+
pr_state="all"
18+
fi
19+
20+
if [[ ! " ${pr_states[*]} " =~ ${pr_state} ]]
21+
then
22+
echo "pr_state must be one of: ${pr_states[*]}"
23+
exit 1
24+
fi
25+
26+
# get all repositories in an organization
27+
repos=$(gh api /orgs/$org/repos --paginate)
28+
# loop through all repos
29+
for row in $(echo "${repos}" | jq -r '.[] | @base64'); do
30+
_jq() {
31+
echo ${row} | base64 --decode | jq -r ${1}
32+
}
33+
repo=$(_jq '.name')
34+
prs=$(gh api /repos/$org/$repo/pulls?state=$pr_state\&sort=created\&direction=asc)
35+
echo "$prs" | jq -r '.[] | [.base.repo.full_name, .number, .title, .user.login, .state] | @tsv'
36+
done
37+
38+
39+
# prs=$(gh api /repos/$org/$repo/pulls?state=$pr_state\&sort=created\&direction=asc)
40+
41+
# echo "$prs" | jq -r '.[] | [.number, .title, .user.login, .state] | @tsv'
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
pr_states=("open" "closed" "all")
4+
5+
if [ $# -lt 2 ]
6+
then
7+
echo "usage: $(basename $0) <org> <repo> <pr_state>"
8+
exit 1
9+
fi
10+
11+
org=$1
12+
repo=$2
13+
pr_state=$3
14+
15+
# set the default for pr_status to be all
16+
if [ -z "$pr_state" ]
17+
then
18+
pr_state="all"
19+
fi
20+
21+
if [[ ! " ${pr_states[*]} " =~ ${pr_state} ]]
22+
then
23+
echo "pr_state must be one of: ${pr_states[*]}"
24+
exit 1
25+
fi
26+
27+
prs=$(gh api /repos/$org/$repo/pulls?state=$pr_state\&sort=created\&direction=asc --paginate)
28+
29+
echo "$prs" | jq -r '.[] | [.base.repo.full_name, .number, .title, .user.login, .state] | @tsv'

0 commit comments

Comments
 (0)