Skip to content

Instantly share code, notes, and snippets.

@namikingsoft
Last active December 4, 2018 02:28
Show Gist options
  • Save namikingsoft/69f91104f4744e231b2b1b21a0246ee0 to your computer and use it in GitHub Desktop.
Save namikingsoft/69f91104f4744e231b2b1b21a0246ee0 to your computer and use it in GitHub Desktop.
Judge Exceeded WIP Limit on Waffle.io (Experimental)
#!/bin/sh -eu
#
# required env:
# WAFFLE_ACCESS_TOKEN
# WAFFLE_ORG_NAME
# WAFFLE_PROJECT_NAME
#
# required packages:
# base64
# curl
# jq
#
# refs:
# https://docs.waffle.io/
#
# usage:
# curl --silent -L \
# https://gist.githubusercontent.com/namikingsoft/69f91104f4744e231b2b1b21a0246ee0/raw/waffle_wip_judge.sh \
# | sh
exit_code=0
columns_json_base64=$(
curl --silent \
-X GET "https://api.waffle.io/${WAFFLE_ORG_NAME}/${WAFFLE_PROJECT_NAME}/columns" \
-H "authorization: Bearer ${WAFFLE_ACCESS_TOKEN}" \
| jq -r '. | @base64'
)
cards_json_base64=$(
curl --silent \
-X GET "https://api.waffle.io/${WAFFLE_ORG_NAME}/${WAFFLE_PROJECT_NAME}/cards" \
-H "authorization: Bearer ${WAFFLE_ACCESS_TOKEN}" \
| jq -r '. | @base64'
)
limited_columns_jsons_base64=$(
echo "$columns_json_base64" \
| base64 --decode \
| jq -r '
.[]
| select(.wipLimit != null)
| @base64
'
)
for row in $limited_columns_jsons_base64; do
name=$(echo "$row" | base64 --decode | jq -r .displayName)
label=$(echo "$row" | base64 --decode | jq -r .label.name)
if [ "$label" = "null" ]; then
is_closed=$(echo "$row" | base64 --decode | jq -r .isClosed)
column_labels_base64=$(
echo "$columns_json_base64" \
| base64 --decode \
| jq -r "
.[]
| select(.label != null)
| select(.isClosed == ${is_closed})
| .label.name
| @base64
"
)
if [ "$is_closed" = "true" ]; then
filter="(.githubMetadata.state == \"closed\")"
else
filter="(.githubMetadata.state != \"closed\")"
fi
for label_base64 in $column_labels_base64; do
label=$(echo "$label_base64" | base64 --decode)
filter="${filter} and (.githubMetadata.labels | all(.name != \"$label\"))"
done
filter="select(${filter})"
else
filter="select(.githubMetadata.labels[].name == \"${label}\")"
fi
# NOTE: .relationships[] is empty => true
filter="${filter} | select(.relationships | all(.relationship != \"close\"))"
wiplimit_type=$(echo "$row" | base64 --decode | jq -r .wipLimit.type)
wiplimit_amount=$(echo "$row" | base64 --decode | jq -r .wipLimit.amount)
count=$(
echo "$cards_json_base64" \
| base64 --decode \
| jq -r "
[
.[]
| $filter
]
| length
"
)
size=$(
echo "$cards_json_base64" \
| base64 --decode \
| jq -r "
[
.[]
| $filter
| select(.size != null)
| .size
]
| add
"
)
[ "$size" = "null" ] && size=0
if [ "$wiplimit_type" = "card count" ] && [ "$count" -gt "$wiplimit_amount" ]; then
echo "\`${name}\` ${wiplimit_type} (${count}) > ${wiplimit_amount}"
exit_code=1
fi
if [ "$wiplimit_type" = "size" ] && [ "$size" -gt "$wiplimit_amount" ]; then
echo "\`${name}\` ${wiplimit_type} (${size}) > ${wiplimit_amount}"
exit_code=1
fi
done
exit $exit_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment