GitAction GoogleChat web hook 사용하기

 GitAction을 이용하여 Google Chat에 웹푸시를 할수 있습니다.


2024.01.26 현재 GitHub에서는 토큰을 이용하여 push/pull하기 때문에 해당 토큰이 적용이 되고 Git Action도 사용할수 있게 되어있어야 합니다.


자세한 내용은 공식 Document를 참고해 주시기 바랍니다.

GitHub : https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues

Google Web Push : https://developers.google.com/chat/how-tos/webhooks


먼저 GitHub계정과 Google 계정이 있어야 합니다.


사진1) 구글챗 화면

사진2) GitHub Repository 생성


사진3) Repository pull


사진4) git action 폴더 생성

git action을 실행하기 위해서는 루트 폴더에서 /.github/workflows 폴더 안에 .yml파일을 생성해야 합니다.


# 워크플로우의 이름을 정의합니다. GitHub Actions 로그와 UI에서 이 이름이 표시됩니다.
name: GitAction Google Chat application test
# 이 워크플로우가 어떤 GitHub 이벤트에 의해 트리거될지 정의합니다.
# 여기서는 'push' 이벤트와 'pull_request' 이벤트에 대해 워크플로우가 실행됩니다.
on: [push, pull_request]
# 워크플로우에서 실행할 작업을 정의합니다.
jobs:
build:
# 워크플로우가 실행될 가상 환경을 지정합니다. 여기서는 Ubuntu 22.04를 사용합니다.
runs-on: ubuntu-22.04
# 워크플로우에서 실행할 단계들을 정의합니다.
steps:
- name: Google Chat Notification
run: |
COMMIT_MESSAGE="${{ github.event.head_commit.message }}"
COMMIT_URL="${{ github.event.head_commit.url }}"

curl --location --request POST "${{ secrets.WEBHOOK }}" \
--header 'Content-Type: application/json' \
--data-raw "{
\"cardsV2\" : [{
\"card\" : {
\"header\": {
\"title\": \"GitHub WebPush\",
\"subtitle\": \"${COMMIT_MESSAGE}\",
\"imageUrl\": \"https://avatars.githubusercontent.com/u/74635702?v=4\",
\"imageType\": \"CIRCLE\"
},
\"sections\": [
{
\"header\": \"New Push in ${{ github.repository }}\",
\"collapsible\": true,
\"uncollapsibleWidgetsCount\": 1,
\"widgets\": [
{
\"textParagraph\": {
\"text\": \"해당 <a href='${COMMIT_URL}'>Link</a> 를 확인해 주시기 바랍니다.\"
}
},
{
\"decoratedText\": {
\"icon\": {
\"knownIcon\": \"EMAIL\"
},
\"text\": \"Pushed by ${{ github.actor }}\",
\"bottomLabel\": \"GitAction_GoogleChat_WebPush\"
}
}
]
}

]
}
}]
}"

code1) google_push.yml 


사진5) git push하기


사진6) git action 동작


사진7) 에러상황

사진6, 7에서 푸시를 보냈음에 불구하고 웹훅이 실패했다. 그 이유는 어느 구글챗에 웹훅을 보내야 할지 모르기 때문에 나온 결과 입니다.


사진8) 스페이스 생성

사진9) 생성할 스페이스 설정

푸시할려는 구글 워크 스페이스를 생성합니다.

사진10) 앱 및 통합

사진11) 웹푸시 비활성화

웹푸시는 조직에서 설정할수 있습니다. 따라서 제가 속한 조직에서 진행하도록 하겠습니다.


사진12) 웹푸시 설정 가능 조건(링크)


사진13) 웹훅 생성


사진14) Web Hook 생성


사진15) GitHub에서 Secret 설정하기


사진16) New secret생성하기

위의 WEBHOOK는 yml파일의 ${{ secrets.WEBHOOK }}을 대체합니다. 즉 Google Space의 웹훅 URL을 입력하게 됩니다.


사진17) 푸시 성공


사진18) Google Chat에 나온 메세지


모든것이 제대로 되면 사진 18과 같이 구글챗에 웹훅이 오게 됩니다.



해당 블로그 GitHub : https://github.com/Alex-Choi0/GitAction_GoogleChat_WebPush.git

GitHub에서 Discord로 웹훅 보내기 : https://engineeringshw.blogspot.com/2021/06/discord-github-repository-webhook.html


댓글

이 블로그의 인기 게시물

Lesson 12_1 프로퍼티 노드(Property Node)

DAQ로 전압 측정하기-2

Lesson 12_2 참조를 이용한 프로퍼티노드(Property Node)