Skip to content

Commit fc84259

Browse files
committed
Working with pull requests in hook
1 parent 4a39125 commit fc84259

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

send.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ COMMIT_URL="https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
3939
# Then this sed command returns: feature/example-branch
4040
BRANCH_NAME="$(echo $GITHUB_REF | sed 's/^[^/]*\/[^/]*\///g')"
4141
REPO_URL="https://github.com/$GITHUB_REPOSITORY"
42-
BRANCH_URL="$REPO_URL/tree/$BRANCH_NAME"
42+
BRANCH_OR_PR="Branch"
43+
BRANCH_OR_PR_URL="$REPO_URL/tree/$BRANCH_NAME"
4344
ACTION_URL="$COMMIT_URL/checks"
4445

4546
if [ "$AUTHOR_NAME" == "$COMMITTER_NAME" ]; then
@@ -48,6 +49,14 @@ else
4849
CREDITS="$AUTHOR_NAME authored & $COMMITTER_NAME committed"
4950
fi
5051

52+
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
53+
BRANCH_OR_PR="Pull Request"
54+
55+
PR_NUM=$(echo $BRANCH_NAME | sed 's/^\([0-9]\+\).*/\1/g')
56+
BRANCH_OR_PR_URL="$REPO_URL/pull/$PR_NUM"
57+
BRANCH_NAME="#${PR_NUM}"
58+
fi
59+
5160
TIMESTAMP=$(date --utc +%FT%TZ)
5261
WEBHOOK_DATA='{
5362
"username": "",
@@ -69,8 +78,8 @@ WEBHOOK_DATA='{
6978
"inline": true
7079
},
7180
{
72-
"name": "Branch",
73-
"value": "'"[\`${BRANCH_NAME}\`](${BRANCH_URL})"'",
81+
"name": "'"$BRANCH_OR_PR"'",
82+
"value": "'"[\`${BRANCH_NAME}\`](${BRANCH_OR_PR_URL})"'",
7483
"inline": true
7584
}
7685
],

testing_utils/local_env_run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export GITHUB_REPOSITORY="DiscordHooks/github-actions-discord-webhook"
77
export GITHUB_REF="refs/heads/feature/example-branch"
88
export HOOK_OS_NAME="Windows"
99
export WORKFLOW_NAME="Main Pipeline"
10+
export GITHUB_EVENT_NAME = "pull_request" # Could also be push, ext.
1011
./send.sh Success $DISCORD_URL

0 commit comments

Comments
 (0)