diff --git a/.github/workflows/pr_notification.yml b/.github/workflows/pr_notification.yml index 794ad682..6eac6dc6 100644 --- a/.github/workflows/pr_notification.yml +++ b/.github/workflows/pr_notification.yml @@ -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) + } + }, + { + buttonList: { + buttons: [ + { + text: "Open Pull Request", + onClick: { + openLink: { + url: $url + } + } + } + ] } } - } - ] - } - ] + ] + } + ] + } } ] - } - ] - }' + }') + + curl --location --request POST "$WEBHOOK_URL" \ + --header 'Content-Type: application/json; charset=UTF-8' \ + --data "$PAYLOAD" + diff --git a/.github/workflows/push_notification.yml b/.github/workflows/push_notification.yml index 33e43c6e..354570f3 100644 --- a/.github/workflows/push_notification.yml +++ b/.github/workflows/push_notification.yml @@ -5,69 +5,84 @@ on: branches: - main +permissions: + contents: read + jobs: notify-push-main: runs-on: ubuntu-latest - env: - COMMIT: ${{ github.event.head_commit.message }} steps: - - name: Main Branch Push - run: | - echo "Workflow initiated by event with name: ${{ github.event_name }}" - echo "Pushing commit to main: ${GITHUB_EVENT_HEAD_COMMIT_ID}" - echo "Pushed by: ${GITHUB_EVENT_PUSHER_NAME}" - env: - GITHUB_EVENT_HEAD_COMMIT_ID: ${{ github.event.head_commit.id }} - GITHUB_EVENT_PUSHER_NAME: ${{ github.event.pusher.name }} + - name: Main Branch Push + run: | + echo "Workflow initiated by event with name: ${EVENT_NAME}" + echo "Pushing commit to main: ${HEAD_COMMIT_ID}" + echo "Pushed by: ${PUSHER_NAME}" + env: + EVENT_NAME: ${{ github.event_name }} + HEAD_COMMIT_ID: ${{ github.event.head_commit.id }} + PUSHER_NAME: ${{ github.event.pusher.name }} - - name: Push Notification to Google Chat - run: | - curl --location --request POST '${{ secrets.WEBHOOK_URL }}' \ - --header 'Content-Type: application/json' \ - --data-raw '{ - "cards": [ - { - "header": { - "title": "Push to main branch", - "subtitle": "'"$COMMIT"'" - }, - "sections": [ + - name: Push Notification to Google Chat + shell: bash + env: + WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} + COMMIT_MSG: ${{ github.event.head_commit.message }} + AUTHOR: ${{ github.event.head_commit.author.username }} + REPO: ${{ github.event.repository.full_name }} + COMPARE_URL: ${{ github.event.compare }} + run: | + PAYLOAD=$(jq -n \ + --arg commit "$COMMIT_MSG" \ + --arg author "$AUTHOR" \ + --arg repo "$REPO" \ + --arg compare "$COMPARE_URL" \ + '{ + cardsV2: [ { - "widgets": [ - { - "keyValue": { - "topLabel": "Repo", - "content": "${GITHUB_EVENT_REPOSITORY_FULL_NAME}" - } - }, - { - "keyValue": { - "topLabel": "Committed by", - "content": "${GITHUB_EVENT_HEAD_COMMIT_AUTHOR_USERNAME}" - } + cardId: "pushNotificationCard", + card: { + header: { + title: "Push to main branch", + subtitle: $commit }, - { - "buttons": [ - { - "textButton": { - "text": "Ref comparison", - "onClick": { - "openLink": { - "url": "${GITHUB_EVENT_COMPARE}" - } + sections: [ + { + widgets: [ + { + decoratedText: { + topLabel: "Repo", + text: $repo + } + }, + { + decoratedText: { + topLabel: "Committed by", + text: $author + } + }, + { + buttonList: { + buttons: [ + { + text: "Ref comparison", + onClick: { + openLink: { + url: $compare + } + } + } + ] } } - } - ] - } - ] + ] + } + ] + } } ] - } - ] - }' - env: - GITHUB_EVENT_REPOSITORY_FULL_NAME: ${{ github.event.repository.full_name }} - GITHUB_EVENT_HEAD_COMMIT_AUTHOR_USERNAME: ${{ github.event.head_commit.author.username }} - GITHUB_EVENT_COMPARE: ${{ github.event.compare }} + }') + + curl --location --request POST "$WEBHOOK_URL" \ + --header 'Content-Type: application/json; charset=UTF-8' \ + --data "$PAYLOAD"