Skip to content

Commit 50a0ff6

Browse files
author
ADMSK\AVROGAL1
committed
docs: updates on workflows
Added information on documentation
1 parent 2c0bfab commit 50a0ff6

File tree

13 files changed

+293
-3
lines changed

13 files changed

+293
-3
lines changed

.github/scripts/close-pending.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
6+
MESSAGE=$(cat $SCRIPT_DIR/closing-message.txt)
7+
8+
while IFS= read -r number &&
9+
IFS= read -r title; do
10+
echo "Closing PR ($number): $title"
11+
curl -s -o /dev/null \
12+
-X POST \
13+
--data "$(jq --arg body "$MESSAGE" -n '{body: $body}')" \
14+
--header "authorization: Bearer $GITHUB_TOKEN" \
15+
--header 'content-type: application/json' \
16+
"https://api.github.com/repos/AlexRogalskiy/object-mappers-playground/issues/$number/comments"
17+
18+
curl -s -o /dev/null \
19+
-X PATCH \
20+
--data '{"state": "close"}' \
21+
--header "authorization: Bearer $GITHUB_TOKEN" \
22+
--header 'content-type: application/json' \
23+
"https://api.github.com/repos/AlexRogalskiy/object-mappers-playground/pulls/$number"
24+
done < <(curl -H "Content-Type: application/json" \
25+
--header "authorization: Bearer $GITHUB_TOKEN" \
26+
"https://api.github.com/search/issues?q=repo:AlexRogalskiy/object-mappers-playground+type:pr+updated:<$(date -d "-21 days" +%Y-%m-%d)+label:pending+is:open" |
27+
jq -r '.items[] | (.number,.title)')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
#doc: Close pending pull request temporary
4+
# shellcheck disable=SC2124
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
6+
MESSAGE=$(cat $SCRIPT_DIR/../closing-message.txt)
7+
8+
set +x #GITHUB_TOKEN
9+
curl -s -o /dev/null \
10+
-X POST \
11+
--data "$(jq --arg body "$MESSAGE" -n '{body: $body}')" \
12+
--header "authorization: Bearer $GITHUB_TOKEN" \
13+
--header 'content-type: application/json' \
14+
"$(jq -r '.issue.comments_url' "$GITHUB_EVENT_PATH")"
15+
16+
curl -s -o /dev/null \
17+
-X PATCH \
18+
--data '{"state": "close"}' \
19+
--header "authorization: Bearer $GITHUB_TOKEN" \
20+
--header 'content-type: application/json' \
21+
"$(jq -r '.issue.pull_request.url' "$GITHUB_EVENT_PATH")"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
#doc: Show current event json to debug problems
4+
5+
echo "\`\`\`"
6+
cat "$GITHUB_EVENT_PATH"
7+
echo "\`\`\`"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
#doc: Show all the available comment commands
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
5+
echo "Available commands:"
6+
DOCTAG="#"
7+
DOCTAG="${DOCTAG}doc"
8+
for command in "$DIR"/*.sh; do
9+
COMMAND_NAME="$(basename "$command" | sed 's/\.sh$//')"
10+
if [ "$COMMAND_NAME" != "debug" ]; then
11+
printf " * /**%s** %s\n" "$COMMAND_NAME" "$(grep $DOCTAG "$command" | sed "s/$DOCTAG//g")"
12+
fi
13+
done
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
#doc: add new label to the issue: `/label <label>`
4+
LABEL="$1"
5+
URL="$(jq -r '.issue.url' "$GITHUB_EVENT_PATH")/labels"
6+
set +x #GITHUB_TOKEN
7+
curl -s -o /dev/null \
8+
-X POST \
9+
--data "$(jq --arg value "$LABEL" -n '{labels: [ $value ]}')" \
10+
--header "authorization: Bearer $GITHUB_TOKEN" \
11+
"$URL"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
#doc: Add a REQUESTED_CHANGE type review to mark issue non-mergeable: `/pending <reason>`
4+
# shellcheck disable=SC2124
5+
MESSAGE="Marking this issue as un-mergeable as requested.
6+
Please use \`/ready\` comment when it's resolved.
7+
Please note that the PR will be closed after 21 days of inactivity from now. (But can be re-opened anytime later...)
8+
> $@"
9+
10+
URL="$(jq -r '.issue.pull_request.url' "$GITHUB_EVENT_PATH")/reviews"
11+
set +x #GITHUB_TOKEN
12+
curl -s -o /dev/null \
13+
--data "$(jq --arg body "$MESSAGE" -n '{event: "REQUEST_CHANGES", body: $body}')" \
14+
--header "authorization: Bearer $GITHUB_TOKEN" \
15+
--header 'content-type: application/json' \
16+
"$URL"
17+
18+
curl -s -o /dev/null \
19+
-X POST \
20+
--data '{"labels": [ "pending" ]}' \
21+
--header "authorization: Bearer $GITHUB_TOKEN" \
22+
"$(jq -r '.issue.url' "$GITHUB_EVENT_PATH")/labels"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
#doc: Dismiss all the blocking reviews by github-actions bot
4+
MESSAGE="Blocking review request is removed."
5+
URL="$(jq -r '.issue.pull_request.url' "$GITHUB_EVENT_PATH")/reviews"
6+
set +x #GITHUB_TOKEN
7+
curl -s "$URL" |
8+
jq -r '.[] | [.user.login, .id] | @tsv' |
9+
grep github-actions |
10+
awk '{print $2}' |
11+
xargs -n1 -IISSUE_ID curl -s -o /dev/null \
12+
-X PUT \
13+
--data "$(jq --arg message "$MESSAGE" -n '{message: $message}')" \
14+
--header "authorization: Bearer $GITHUB_TOKEN" \
15+
"$URL"/ISSUE_ID/dismissals
16+
17+
curl -s -o /dev/null \
18+
-X DELETE \
19+
--header "authorization: Bearer $GITHUB_TOKEN" \
20+
"$(jq -r '.issue.url' "$GITHUB_EVENT_PATH")/labels/pending"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
#doc: provide help on how to trigger new CI build
4+
5+
# posting a new commit from this script does not trigger CI checks
6+
# https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token
7+
8+
set -eu
9+
10+
code='```'
11+
12+
pr_url="$(jq -r '.issue.pull_request.url' "${GITHUB_EVENT_PATH}")"
13+
commenter="$(jq -r '.comment.user.login' "${GITHUB_EVENT_PATH}")"
14+
assoc="$(jq -r '.comment.author_association' "${GITHUB_EVENT_PATH}")"
15+
16+
curl -LSs "${pr_url}" -o pull.tmp
17+
source_repo="$(jq -r '.head.repo.ssh_url' pull.tmp)"
18+
branch="$(jq -r '.head.ref' pull.tmp)"
19+
pr_owner="$(jq -r '.head.user.login' pull.tmp)"
20+
maintainer_can_modify="$(jq -r '.maintainer_can_modify' pull.tmp)"
21+
22+
# PR owner
23+
# =>
24+
# has local branch, can simply push
25+
if [[ "${commenter}" == "${pr_owner}" ]]; then
26+
cat <<-EOF
27+
To re-run CI checks, please follow these steps with the source branch checked out:
28+
${code}
29+
git commit --allow-empty -m 'trigger new CI check'
30+
git push
31+
${code}
32+
EOF
33+
34+
# member AND modification allowed by PR author
35+
# OR
36+
# repo owner
37+
# =>
38+
# include steps to fetch branch
39+
elif [[ "${maintainer_can_modify}" == "true" ]] && [[ "${assoc}" == "MEMBER" ]] || [[ "${assoc}" == "OWNER" ]]; then
40+
cat <<-EOF
41+
To re-run CI checks, please follow these steps:
42+
${code}
43+
git fetch "${source_repo}" "${branch}"
44+
git checkout FETCH_HEAD
45+
git commit --allow-empty -m 'trigger new CI check'
46+
git push "${source_repo}" HEAD:"${branch}"
47+
${code}
48+
EOF
49+
50+
# other folks
51+
# =>
52+
# ping author
53+
else
54+
cat <<-EOF
55+
@${pr_owner} please trigger new CI check by following these steps:
56+
${code}
57+
git commit --allow-empty -m 'trigger new CI check'
58+
git push
59+
${code}
60+
EOF
61+
fi

.github/scripts/process-comment.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
set +x #don't show GITHUB_TOKEN
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
6+
BODY=$(jq -r .comment.body "$GITHUB_EVENT_PATH")
7+
LINES=$(printf "%s" "$BODY" | wc -l)
8+
if [ "$LINES" == "0" ]; then
9+
if [[ "$BODY" == /* ]]; then
10+
echo "Command $BODY is received"
11+
COMMAND=$(echo "$BODY" | awk '{print $1}' | sed 's/\///')
12+
ARGS=$(echo "$BODY" | cut -d ' ' -f2-)
13+
if [ -f "$SCRIPT_DIR/comment-commands/$COMMAND.sh" ]; then
14+
RESPONSE=$("$SCRIPT_DIR/comment-commands/$COMMAND.sh" "${ARGS[@]}")
15+
EXIT_CODE=$?
16+
if [[ $EXIT_CODE != 0 ]]; then
17+
# shellcheck disable=SC2124
18+
RESPONSE="> $BODY
19+
20+
Script execution has been failed with exit code $EXIT_CODE. Please check the output of the github action run to get more information.
21+
\`\`\`
22+
$RESPONSE
23+
\`\`\`
24+
"
25+
fi
26+
else
27+
RESPONSE="No such command. \`$COMMAND\` $("$SCRIPT_DIR/comment-commands/help.sh")"
28+
fi
29+
if [ "$GITHUB_TOKEN" ]; then
30+
set +x #do not display the GITHUB_TOKEN
31+
COMMENTS_URL=$(jq -r .issue.comments_url "$GITHUB_EVENT_PATH")
32+
curl -s \
33+
--data "$(jq --arg body "$RESPONSE" -n '{body: $body}')" \
34+
--header "authorization: Bearer $GITHUB_TOKEN" \
35+
--header 'content-type: application/json' \
36+
"$COMMENTS_URL"
37+
else
38+
echo "$RESPONSE"
39+
fi
40+
fi
41+
fi

.github/workflows/close-pending.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ jobs:
1616

1717
- name: Execute close-pending script
1818
if: github.repository == 'AlexRogalskiy/github-action-json-fields'
19-
run: ./.github/scripts/close-pending.sh
19+
run: .github/scripts/close-pending.sh
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)