Last active
August 29, 2015 13:56
-
-
Save mizoR/9017330 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 -e | |
command_name=`basename $0` | |
function usage() { | |
echo "Usage:" | |
echo " $command_name --username username --org org [OPTIONS]" | |
echo | |
echo " Options:" | |
echo " --filter : Indicates which sorts of issues to return. Can be one of:" | |
echo " * assigned: Issues assigned to you" | |
echo " * created: Issues created by you" | |
echo " * mentioned: Issues mentioning you" | |
echo " * subscribed: Issues you’re subscribed to updates for" | |
echo " * all: All issues the authenticated user can see, regardless of participation or creation" | |
echo " Default: assigned" | |
echo " --state : Indicates the state of the issues to return. Can be either open or closed." | |
echo " Default: close" | |
echo " --sort : What to sort results by. Can be either created, updated, comments. " | |
echo " Default: created" | |
echo " --direction : The direction of the sort. Can be either asc or desc." | |
echo " Default: asc" | |
echo " --since : Only issues updated at or after this time are returned." | |
echo " This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ." | |
} | |
function show_options() { | |
echo " [username] $username" | |
echo " [org] $org" | |
echo " [filter] $filter" | |
echo " [state] $state" | |
echo " [sort] $sort" | |
echo " [direction] $direction" | |
echo " [since] $since" | |
echo " [page] $page" | |
echo | |
} | |
function exit_or_next() { | |
echo -n "Execute ([yes], no) ? |y| " >&2 | |
read answer | |
if [ "x$answer" != "x" ] && [ "x$answer" != "xy" ] && [ "x$answer" != "xyes" ] | |
then | |
echo "Bye!" >&2 | |
exit 0 | |
fi | |
} | |
function error() { | |
echo -n -e "\033[37;41mERROR\033[00m " | |
echo $1 | |
echo | |
} | |
function command_not_found_and_exit() { | |
error="$1: Command not found" | |
error "$error" >&2 | |
exit 1 | |
} | |
function illegal_option_and_exit() { | |
error="Illegal option: $1" | |
error "$error" >&2 | |
usage | |
exit 1 | |
} | |
function missing_required_parameter_and_exit() { | |
error="Missing required parameter: $1" | |
error "$error" >&2 | |
usage | |
exit 1 | |
} | |
function date_iso_8601() { | |
local system_type=`uname -s` | |
local d=$([ "x$1" != "x" ] && echo "$1" || echo "+0") | |
case $system_type in | |
FreeBSD|Darwin) | |
date -v "${d}d" +"%Y-%m-%dT%H:%M:%SZ" | |
;; | |
Linux) | |
date --date "${d} day" +"%Y-%m-%dT%H:%M:%SZ" | |
;; | |
esac | |
} | |
filter="assigned" | |
state="close" | |
sort="created" | |
direction="asc" | |
since=`date_iso_8601 -14` | |
page=1 | |
if ! type jq >/dev/null 2>&1 | |
then | |
command_not_found_and_exit 'jq' | |
fi | |
while [ "x$1" != "x" ] | |
do | |
case $1 in | |
"--username") | |
username=$2 | |
shift 2 | |
;; | |
"--org") | |
org=$2 | |
shift 2 | |
;; | |
"--filter") | |
filter=$2 | |
shift 2 | |
;; | |
"--direction") | |
direction=$2 | |
shift 2 | |
;; | |
"--state") | |
state=$2 | |
shift 2 | |
;; | |
"--since") | |
since=$2 | |
shift 2 | |
;; | |
"--page") | |
page=$2 | |
shift 2 | |
;; | |
"--help") | |
usage | |
exit 0 | |
;; | |
*) | |
illegal_option_and_exit $1 | |
esac | |
done | |
if [ "x$username" == "x" ] | |
then | |
missing_required_parameter_and_exit 'username' | |
fi | |
if [ "x$org" == "x" ] | |
then | |
missing_required_parameter_and_exit 'org' | |
fi | |
show_options >&2 | |
request_url="https://api.github.com/orgs/$org/issues" | |
params="filter=$filter&state=$state&sort=$sort&direction=$direction&since=$since&page=$page" | |
jq_filter='.[] | ' | |
jq_filter=$jq_filter'"- " + .html_url + " " + .title, ' | |
jq_filter=$jq_filter'" - **Milestone** " + (.milestone.title // "未設定"), ' | |
jq_filter=$jq_filter'" - **state** " + .state, ' | |
jq_filter=$jq_filter'" - **labels**", ' | |
jq_filter=$jq_filter'" - " + .labels[].name' | |
exit_or_next | |
curl -s -u $username $request_url?$params | jq "$jq_filter" | sed 's/"//g' | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment