Created
November 28, 2024 03:16
-
-
Save sunng87/4b3725b3d8711afbe9f977fb9fcf31f8 to your computer and use it in GitHub Desktop.
gh-issue-fetch.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#!/usr/bin/env bash | |
# Fetch contributors | |
contributors=$(gh api -X GET repos/$1/$2/contributors --jq '.[].login' | tr '\n' '|' | sed 's/|$//') | |
echo $contributors | |
# Export the CONTRIBUTORS environment variable | |
export CONTRIBUTORS="$contributors" | |
# Fetch issues not created by contributors | |
#gh api graphql --paginate -F name="$2" -F owner="$1" -F count=100 -f query=' | |
gh api graphql -F name="$2" -F owner="$1" -F count=10 -f query=' | |
query($name: String!, $owner: String!, $count: Int!, $endCursor: String) { | |
repository(name: $name, owner: $owner) { | |
issues(first: $count, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}) { | |
pageInfo { | |
hasNextPage | |
endCursor | |
} | |
edges { | |
node { | |
title | |
labels(first: 3) { | |
nodes { | |
name | |
} | |
} | |
author { | |
... on User { | |
name | |
company | |
login | |
location | |
} | |
} | |
createdAt | |
state | |
number | |
url | |
} | |
} | |
} | |
} | |
}' --jq ' | |
.data.repository.issues.edges | |
| map(.node) | |
| map(select((.author.login // "") | test(env.CONTRIBUTORS; "i") | not)) | |
| map({ | |
title: (.title // ""), | |
createdAt: (.createdAt // ""), | |
state: (.state // ""), | |
company: (.author?.company // ""), | |
location: (.author?.location // ""), | |
login: (.author?.login // ""), | |
email: (.author?.email // ""), | |
name: (.author?.name // ""), | |
labels: (.labels.nodes // [] | map(.name) | join(",")), | |
number: (.number // ""), | |
url: (.url // "") | |
}) | |
| (map(keys) | add | unique) as $cols | |
| map(. as $row | $cols | map($row[.] // "")) | |
| .[] | |
| @csv | |
' | |
# gh api graphql --paginate -F name="$2" -F owner="$1" -F count=100 -f query=' | |
# query($name: String!, $owner: String!, $count: Int!, $endCursor: String) { | |
# repository(name: $name, owner: $owner) { | |
# issues(first: $count, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}){ | |
# pageInfo { | |
# hasNextPage | |
# endCursor | |
# } | |
# edges { | |
# node { | |
# title | |
# labels (first: 3) { | |
# nodes { | |
# name | |
# } | |
# } | |
# author { | |
# ... on User { | |
# name, | |
# company, | |
# login, | |
# email, | |
# location | |
# } | |
# } | |
# createdAt | |
# state | |
# number | |
# url | |
# } | |
# } | |
# } | |
# } | |
# }' --jq '.data.repository.issues.edges | [.[].node | {title,createdAt,state,company:.author.company,location:.author.location,login:.author.login,email:.author.email,name:.author.name,labels:[.labels.nodes.[].name]|join(","),number,url}] | (map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) | @csv' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment