diff --git a/.github/workflows/pr-to-gchat.yml b/.github/workflows/pr-to-gchat.yml index de54841..713e8a4 100644 --- a/.github/workflows/pr-to-gchat.yml +++ b/.github/workflows/pr-to-gchat.yml @@ -5,18 +5,22 @@ on: types: [opened, reopened, synchronize] jobs: - notify: + notify-gchat: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Send PR details to Google Chat + - name: Enviar PR para Google Chat env: GCHAT_WEBHOOK_URL: ${{ secrets.GCHAT_WEBHOOK_URL }} PR_TITLE: ${{ github.event.pull_request.title }} + PR_BODY: ${{ github.event.pull_request.body }} PR_URL: ${{ github.event.pull_request.html_url }} PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_STATUS: ${{ github.event.action }} run: | - pip install requests - python send_to_gchat.py + MESSAGE="{ + \"text\": \"*Novo evento de Pull Request*: \`${PR_STATUS}\`\n\n📌 *Título:* ${PR_TITLE}\n📝 *Descrição:* ${PR_BODY}\n👤 *Autor:* ${PR_AUTHOR}\n🔗 *Link:* ${PR_URL}\" + }" + + curl -X POST -H 'Content-Type: application/json' \ + -d "${MESSAGE}" \ + "$GCHAT_WEBHOOK_URL" diff --git a/.github/workflows/scripts/send_to_gchat.py b/.github/workflows/scripts/send_to_gchat.py new file mode 100644 index 0000000..ba3cee2 --- /dev/null +++ b/.github/workflows/scripts/send_to_gchat.py @@ -0,0 +1,31 @@ +import os +import requests + +# Lê variáveis de ambiente +webhook_url = os.environ['GCHAT_WEBHOOK_URL'] +title = os.environ.get('PR_TITLE', '(sem título)') +body = os.environ.get('PR_BODY', '(sem descrição)') +author = os.environ.get('PR_AUTHOR', 'desconhecido') +url = os.environ.get('PR_URL', '') +status = os.environ.get('PR_STATUS', 'desconhecido') + +# Formata a mensagem +message = { + "text": ( + f"*Novo evento de Pull Request*: `{status}`\n\n" + f"📌 *Título:* {title}\n" + f"📝 *Descrição:* {body}\n" + f"👤 *Autor:* {author}\n" + f"🔗 *Link:* {url}" + ) +} + +# Envia a mensagem +response = requests.post(webhook_url, json=message) + +# Verifica sucesso +if response.status_code != 200: + print(f"Erro ao enviar para Google Chat: {response.status_code} - {response.text}") + response.raise_for_status() +else: + print("Mensagem enviada com sucesso para o Google Chat.") diff --git a/.github/workflows/send_to_gchat.py b/.github/workflows/send_to_gchat.py index 140a293..f6fc3c4 100644 --- a/.github/workflows/send_to_gchat.py +++ b/.github/workflows/send_to_gchat.py @@ -1,6 +1,6 @@ import os import requests - +#teste GCHAT_WEBHOOK_URL = os.environ['GCHAT_WEBHOOK_URL'] PR_TITLE = os.environ['PR_TITLE'] PR_URL = os.environ['PR_URL']