Last active
September 5, 2018 14:36
-
-
Save chaspy/0e2637f62b382bcbc5000aa31c74e287 to your computer and use it in GitHub Desktop.
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 | |
set -x | |
readonly URL="https://api.github.com/search/issues" | |
usage() { | |
cat <<EOS >&2 | |
Usage: $0 -u <user> -s YYYY-MM-DD -e YYYY-MM-DD | |
-u: your github user name | |
-s: start date to get your contribution | |
-e: end date to get your contribution | |
EOS | |
exit 1 | |
} | |
parse_args() { | |
while getopts "u:s:e:" OPT; do | |
case $OPT in | |
u) AUTHOR="$OPTARG" ;; | |
s) START="$OPTARG" ;; | |
e) END="$OPTARG" ;; | |
:) echo "[ERROR] Option argument is undefined.";; | |
\?) echo "[ERROR] Undefined options.";; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
} | |
main() { | |
source ./token.sh | |
if [[ $TOKEN != "" ]]; then | |
AUTH="Authorization: token ${TOKEN}" | |
fi | |
TERMS="$START".."$END" | |
JSON=`curl -sS -H "$AUTH" "${URL}?q=type:pr+in:body+is:merged+merged:${TERMS}+author:${AUTHOR}&per_page=100"` | |
NUM=`echo $JSON | jq ".items[].title" | wc -l | tr -d ' '` | |
PR=`echo $JSON | jq -c '.items[] | {title,html_url} | .html_url |= . + "\n" ' \ | |
| jq -c 'sort_by(.html_url) | .[]' --slurp \ | |
| jq -r .[]` | |
echo "Hi ${AUTHOR}, this is your contribution report :tada: in $TERMS" | |
echo "# Pull Request" | |
echo "your created and merged pull request is ${NUM}!!" | |
echo -n "$PR" | |
} | |
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | |
parse_args "$@" | |
main | |
fi |
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
# If you get private repository, please add token | |
# export TOKEN=<your github token> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment