Skip to content

Commit 20ec940

Browse files
Refactor Github Action per b/485167538 (#581)
Co-authored-by: Ben Knutson <benknutson@google.com>
1 parent 9e354be commit 20ec940

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

.github/workflows/pr_notification.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ jobs:
1010
steps:
1111
- name: Pull Request Details
1212
run: |
13-
echo "Pull Request: ${{ github.event.pull_request.title }}"
14-
echo "Author: ${{ github.event.pull_request.user.login }}"
13+
echo "Pull Request: ${GITHUB_EVENT_PULL_REQUEST_TITLE}"
14+
echo "Author: ${GITHUB_EVENT_PULL_REQUEST_USER_LOGIN}"
15+
env:
16+
GITHUB_EVENT_PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
17+
GITHUB_EVENT_PULL_REQUEST_USER_LOGIN: ${{ github.event.pull_request.user.login }}
1518

1619
- name: Google Chat Notification
1720
run: |
@@ -30,19 +33,19 @@ jobs:
3033
{
3134
"keyValue": {
3235
"topLabel": "Repo",
33-
"content": "${{ github.event.pull_request.head.repo.full_name }}"
36+
"content": "${GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME}"
3437
}
3538
},
3639
{
3740
"keyValue": {
3841
"topLabel": "Title",
39-
"content": "${{ github.event.pull_request.title }}"
42+
"content": "${GITHUB_EVENT_PULL_REQUEST_TITLE}"
4043
}
4144
},
4245
{
4346
"keyValue": {
4447
"topLabel": "Creator",
45-
"content": "${{ github.event.pull_request.user.login }}"
48+
"content": "${GITHUB_EVENT_PULL_REQUEST_USER_LOGIN}"
4649
}
4750
},
4851
{
@@ -76,7 +79,7 @@ jobs:
7679
"text": "Open Pull Request",
7780
"onClick": {
7881
"openLink": {
79-
"url": "${{ github.event.pull_request.html_url }}"
82+
"url": "${GITHUB_EVENT_PULL_REQUEST_HTML_URL}"
8083
}
8184
}
8285
}
@@ -89,3 +92,8 @@ jobs:
8992
}
9093
]
9194
}'
95+
env:
96+
GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
97+
GITHUB_EVENT_PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
98+
GITHUB_EVENT_PULL_REQUEST_USER_LOGIN: ${{ github.event.pull_request.user.login }}
99+
GITHUB_EVENT_PULL_REQUEST_HTML_URL: ${{ github.event.pull_request.html_url }}

.github/workflows/push_notification.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ jobs:
1212
- name: Main Branch Push
1313
run: |
1414
echo "Workflow initiated by event with name: ${{ github.event_name }}"
15-
echo "Pushing commit to main: ${{ github.event.head_commit.id }}"
16-
echo "Pushed by: ${{ github.event.pusher.name }}"
15+
echo "Pushing commit to main: ${GITHUB_EVENT_HEAD_COMMIT_ID}"
16+
echo "Pushed by: ${GITHUB_EVENT_PUSHER_NAME}"
17+
env:
18+
GITHUB_EVENT_HEAD_COMMIT_ID: ${{ github.event.head_commit.id }}
19+
GITHUB_EVENT_PUSHER_NAME: ${{ github.event.pusher.name }}
1720

1821
- name: Push Notification to Google Chat
1922
run: |
@@ -24,21 +27,21 @@ jobs:
2427
{
2528
"header": {
2629
"title": "Push to main branch",
27-
"subtitle": "${{ github.event.head_commit.message }}"
30+
"subtitle": "${GITHUB_EVENT_HEAD_COMMIT_MESSAGE}"
2831
},
2932
"sections": [
3033
{
3134
"widgets": [
3235
{
3336
"keyValue": {
3437
"topLabel": "Repo",
35-
"content": "${{ github.event.repository.full_name }}"
38+
"content": "${GITHUB_EVENT_REPOSITORY_FULL_NAME}"
3639
}
3740
},
3841
{
3942
"keyValue": {
4043
"topLabel": "Committed by",
41-
"content": "${{ github.event.head_commit.author.username }}"
44+
"content": "${GITHUB_EVENT_HEAD_COMMIT_AUTHOR_USERNAME}"
4245
}
4346
},
4447
{
@@ -48,7 +51,7 @@ jobs:
4851
"text": "Ref comparison",
4952
"onClick": {
5053
"openLink": {
51-
"url": "${{ github.event.compare }}"
54+
"url": "${GITHUB_EVENT_COMPARE}"
5255
}
5356
}
5457
}
@@ -61,4 +64,9 @@ jobs:
6164
}
6265
]
6366
}'
67+
env:
68+
GITHUB_EVENT_HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
69+
GITHUB_EVENT_REPOSITORY_FULL_NAME: ${{ github.event.repository.full_name }}
70+
GITHUB_EVENT_HEAD_COMMIT_AUTHOR_USERNAME: ${{ github.event.head_commit.author.username }}
71+
GITHUB_EVENT_COMPARE: ${{ github.event.compare }}
6472

0 commit comments

Comments
 (0)