-
Notifications
You must be signed in to change notification settings - Fork 282
Update push and pr notification to use Cards v2. #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d50c7d3
5a8b3d5
5ab3abd
71858bd
8928a19
5886de9
341f87e
e0a8003
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,97 +4,122 @@ on: | |
| pull_request: | ||
| types: [review_requested] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| notify-pull-request: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Pull Request Details | ||
| run: | | ||
| echo "Pull Request: ${{ github.event.pull_request.number }}" | ||
| echo "Author: ${GITHUB_EVENT_PULL_REQUEST_USER_LOGIN}" | ||
| env: | ||
| GITHUB_EVENT_PULL_REQUEST_USER_LOGIN: ${{ github.event.pull_request.user.login }} | ||
| - name: Pull Request Details | ||
| run: | | ||
| echo "Pull Request: ${PR_NUMBER}" | ||
| echo "Author: ${AUTHOR}" | ||
| env: | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| AUTHOR: ${{ github.event.pull_request.user.login }} | ||
|
|
||
| - name: Google Chat Notification | ||
| shell: bash | ||
| env: | ||
| TITLE: ${{ github.event.pull_request.title }} | ||
| LABELS: ${{ join(github.event.pull_request.labels.*.name, ', ') }} | ||
| GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }} | ||
| GITHUB_EVENT_PULL_REQUEST_USER_LOGIN: ${{ github.event.pull_request.user.login }} | ||
| GITHUB_EVENT_PULL_REQUEST_HTML_URL: ${{ github.event.pull_request.html_url }} | ||
| run: | | ||
| curl --location --request POST '${{ secrets.WEBHOOK_URL }}' \ | ||
| --header 'Content-Type: application/json' \ | ||
| --data-raw '{ | ||
| "cards": [ | ||
| { | ||
| "header": { | ||
| "title": "Pull request notification", | ||
| "subtitle": "Pull request: #${{ github.event.pull_request.number }}" | ||
| }, | ||
| "sections": [ | ||
| - name: Google Chat Notification | ||
| shell: bash | ||
| env: | ||
| WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| TITLE: ${{ github.event.pull_request.title }} | ||
| LABELS: ${{ join(github.event.pull_request.labels.*.name, ', ') }} | ||
| REPO: ${{ github.event.pull_request.head.repo.full_name }} | ||
| CREATOR: ${{ github.event.pull_request.user.login }} | ||
| STATE: ${{ github.event.pull_request.state }} | ||
| ASSIGNEES: ${{ join(github.event.pull_request.assignees.*.login, ', ') }} | ||
| REVIEWERS: ${{ join(github.event.pull_request.requested_reviewers.*.login, ', ') }} | ||
| URL: ${{ github.event.pull_request.html_url }} | ||
| run: | | ||
| PAYLOAD=$(jq -n \ | ||
| --arg pr_num "$PR_NUMBER" \ | ||
| --arg title "$TITLE" \ | ||
| --arg labels "$LABELS" \ | ||
| --arg repo "$REPO" \ | ||
| --arg creator "$CREATOR" \ | ||
| --arg state "$STATE" \ | ||
| --arg assignees "$ASSIGNEES" \ | ||
| --arg reviewers "$REVIEWERS" \ | ||
| --arg url "$URL" \ | ||
| '{ | ||
| cardsV2: [ | ||
| { | ||
| "widgets": [ | ||
| { | ||
| "keyValue": { | ||
| "topLabel": "Repo", | ||
| "content": "${GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME}" | ||
| } | ||
| }, | ||
| { | ||
| "keyValue": { | ||
| "topLabel": "Title", | ||
| "content": "'"$TITLE"'" | ||
| } | ||
| }, | ||
| { | ||
| "keyValue": { | ||
| "topLabel": "Creator", | ||
| "content": "${GITHUB_EVENT_PULL_REQUEST_USER_LOGIN}" | ||
| } | ||
| }, | ||
| { | ||
| "keyValue": { | ||
| "topLabel": "State", | ||
| "content": "${{ github.event.pull_request.state }}" | ||
| } | ||
| }, | ||
| { | ||
| "keyValue": { | ||
| "topLabel": "Assignees", | ||
| "content": "- ${{ join(github.event.pull_request.assignees.*.login, ', ') }}" | ||
| } | ||
| }, | ||
| { | ||
| "keyValue": { | ||
| "topLabel": "Reviewers", | ||
| "content": "- ${{ join(github.event.pull_request.requested_reviewers.*.login, ', ') }}" | ||
| } | ||
| cardId: "prNotificationCard", | ||
| card: { | ||
| header: { | ||
| title: "Pull request notification", | ||
| subtitle: ("Pull request: #" + $pr_num) | ||
| }, | ||
| { | ||
| "keyValue": { | ||
| "topLabel": "Labels", | ||
| "content": "- '"$LABELS"'" | ||
| } | ||
| }, | ||
| { | ||
| "buttons": [ | ||
| { | ||
| "textButton": { | ||
| "text": "Open Pull Request", | ||
| "onClick": { | ||
| "openLink": { | ||
| "url": "${GITHUB_EVENT_PULL_REQUEST_HTML_URL}" | ||
| } | ||
| sections: [ | ||
| { | ||
| widgets: [ | ||
| { | ||
| decoratedText: { | ||
| topLabel: "Repo", | ||
| text: $repo | ||
| } | ||
| }, | ||
| { | ||
| decoratedText: { | ||
| topLabel: "Title", | ||
| text: $title | ||
| } | ||
| }, | ||
| { | ||
| decoratedText: { | ||
| topLabel: "Creator", | ||
| text: $creator | ||
| } | ||
| }, | ||
| { | ||
| decoratedText: { | ||
| topLabel: "State", | ||
| text: $state | ||
| } | ||
| }, | ||
| { | ||
| decoratedText: { | ||
| topLabel: "Assignees", | ||
| text: (if $assignees != "" then "- " + $assignees else "None" end) | ||
| } | ||
| }, | ||
| { | ||
| decoratedText: { | ||
| topLabel: "Reviewers", | ||
| text: (if $reviewers != "" then "- " + $reviewers else "None" end) | ||
| } | ||
| }, | ||
| { | ||
| decoratedText: { | ||
| topLabel: "Labels", | ||
| text: (if $labels != "" then "- " + $labels else "None" end) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do a little helper function to add this guard on every |
||
| } | ||
| }, | ||
| { | ||
| buttonList: { | ||
| buttons: [ | ||
| { | ||
| text: "Open Pull Request", | ||
| onClick: { | ||
| openLink: { | ||
| url: $url | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }' | ||
| }') | ||
|
|
||
| curl --location --request POST "$WEBHOOK_URL" \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want this to fail a PR, but I do think we want it to indicate that something failed. For both curl commands, you could do all of: a) add |
||
| --header 'Content-Type: application/json; charset=UTF-8' \ | ||
| --data "$PAYLOAD" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Why the change to --data instead of --data-raw? |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this will always be nil on PRs that come in from forks, can you add a quick check for
WEBHOOK_URLthat will skip the workflow if nil?