Last active
January 17, 2022 00:50
-
-
Save Lycolia/8ba5db0e1923b82d294ab2e8515b0f69 to your computer and use it in GitHub Desktop.
Get progress of specified in GitHub Issues
This file contains 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
#!/bin/bash | |
getProgress() { | |
local issueNo=$1 | |
local issue=$(curl -sS \ | |
-H "Authorization: token $GH_TOKEN" \ | |
-H "Accept: 'application/vnd.github.v3+json'" \ | |
https://api.github.com/repos/$TARGET_REPO/issues/$issueNo \ | |
| perl -lpe 's/\n//') | |
local no=$(echo "#$issueNo") | |
local title=$(echo "$issue" | jq -r '.title') | |
local body=$(echo "$issue" | jq -r '.body') | |
local state=$(echo "$issue" | jq -r '.state') | |
if [ "$body" = null ]; then | |
echo "Issue $no is not found" | |
exit 1 | |
fi | |
local total=$(echo "$body" | grep -- '- \[.\] ' | wc -l) | |
local done=$(echo "$body" | grep -- '- \[x\] ' | wc -l) | |
# for has not tasks | |
if [ $total -eq 0 ]; then | |
total=1 | |
if [ "$state" = 'closed' ]; then | |
done=1 | |
fi | |
fi | |
echo "$title $no" | |
echo "Done $done/$total" | |
} | |
# usage | |
# 1. Configure environment variables | |
# GH_TOKEN=XXXXXXXXXXXXXXXXXXXX | |
# TARGET_REPO=owner/repository | |
# 2. Call function below | |
# getProgress <issue-no> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment