Created
February 1, 2019 06:43
-
-
Save masutaka/a99570883acd60e246381f9898c00b14 to your computer and use it in GitHub Desktop.
All in one GitHub Project using GitHub Actions
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
.github | |
├── main.workflow (01main.workflow) | |
└── project | |
├── Dockerfile | |
└── entrypoint.sh |
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
workflow "GitHub Project for issues" { | |
on = "issues" | |
resolves = ["Move an issue to GitHub Project"] | |
} | |
# workflow "New workflow2" { | |
# on = "pull_request" | |
# resolves = ["Hello World"] | |
# } | |
action "Move an issue to GitHub Project" { | |
uses = "./.github/project" | |
secrets = ["GITHUB_TOKEN"] | |
env = { | |
INITIAL_COLUMN_ID = "4281951" # "To do" | |
CLOSED_TARGET_COLUMN_IDS = "4281951,4281952" # "To do", "In progress" | |
DONE_COLUMN_ID = "4281953" # "Done" | |
} | |
args = ["hoge", "fuga"] | |
} |
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
FROM alpine:3.9 | |
LABEL "com.github.actions.icon"="github" | |
LABEL "com.github.actions.color"="yellow" | |
RUN apk add --no-cache --no-progress curl=7.63.0-r0 jq=1.6-r0 | |
COPY entrypoint.sh /entrypoint.sh | |
ENTRYPOINT ["/entrypoint.sh"] |
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/sh -ex | |
env | sort | |
jq < "$GITHUB_EVENT_PATH" | |
ACTION=$(jq -r '.action' < "$GITHUB_EVENT_PATH") | |
ISSUE_ID=$(jq -r '.issue.id' < "$GITHUB_EVENT_PATH") | |
ISSUE_URL=$(jq -r '.issue.url' < "$GITHUB_EVENT_PATH") | |
case "$ACTION" in | |
opened|reopened) | |
# [WIP] すでにどこかのカラムに追加された状態で reopen されたら、Move a project card を呼ぶ必要がある。 | |
# https://developer.github.com/v3/projects/cards/#move-a-project-card | |
# Add "To do" column | |
curl -s -X POST -u "$GITHUB_ACTOR:$GITHUB_TOKEN" \ | |
-H 'Accept: application/vnd.github.inertia-preview+json' \ | |
-d "{\"content_type\": \"Issue\", \"content_id\": $ISSUE_ID}" \ | |
"https://api.github.com/projects/columns/$INITIAL_COLUMN_ID/cards" | |
;; | |
closed) | |
# 対象のカードを探し回る。 | |
ORIG_IFS=$IFS | |
IFS=, | |
for i in $CLOSED_TARGET_COLUMN_IDS; do | |
# [WIP] Need to loop | |
CARDS=$(curl -s -X GET -u "$GITHUB_ACTOR:$GITHUB_TOKEN" \ | |
-H 'Accept: application/vnd.github.inertia-preview+json' \ | |
"https://api.github.com/projects/columns/$i/cards") | |
# Select card_id of the target issue | |
CARD_ID=$(echo "$CARDS" | jq ".[] | select(.content_url == \"$ISSUE_URL\") | .id") | |
if [ "$CARD_ID" ]; then | |
break | |
fi | |
echo "$ISSUE_URL is not found in COLUMN_ID $i" | |
done | |
IFS=$ORIG_IFS | |
if [ "$CARD_ID" ]; then | |
# Move to "Done" column | |
curl -s -X POST -u "$GITHUB_ACTOR:$GITHUB_TOKEN" \ | |
-H 'Accept: application/vnd.github.inertia-preview+json' \ | |
-d "{\"position\": \"top\", \"column_id\": $DONE_COLUMN_ID}" \ | |
"https://api.github.com/projects/columns/cards/$CARD_ID/moves" | |
else | |
echo "Finaly, $ISSUE_URL is not found in COLUMN_IDS $CLOSED_TARGET_COLUMN_IDS" | |
fi | |
;; | |
*) | |
echo "ACTION: $ACTION, ISSUE_ID: $ISSUE_ID, ISSUE_URL: $ISSUE_URL" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment