feat(pr): validate #42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR is valid? | |
on: | |
pull_request_target: | |
types: [ edited, synchronize, opened, reopened ] | |
jobs: | |
validate-has-valid-issue: | |
permissions: write-all | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Issue Validator | |
uses: HarshCasper/[email protected] | |
id: validator | |
with: | |
prbody: ${{ github.event.pull_request.body }} | |
prurl: ${{ github.event.pull_request.url }} | |
- name: PR has a valid Issue | |
if: ${{ steps.validator.outputs.valid == 1 }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PRNUM: ${{ github.event.pull_request.number }} | |
run: | | |
gh pr edit $PRNUM --add-label "PR:Ready-to-Review" | |
gh pr edit $PRNUM --remove-label "PR:No-Issue" | |
- name: PR has no valid Issue | |
if: ${{ steps.validator.outputs.valid == 0 }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PRNUM: ${{ github.event.pull_request.number }} | |
run: | | |
gh pr comment $PRNUM --body "❗PR não está vinculado a nenhuma issue, faça as alterações correspondentes no corpo.." | |
gh pr edit $PRNUM --add-label "PR:No-Issue" | |
validate-title-and-comment: | |
permissions: write-all | |
runs-on: ubuntu-latest | |
needs: validate-has-valid-issue | |
steps: | |
- name: Checkout code from PR (Safe Checkout) | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Validate PR | |
uses: thehanimo/[email protected] | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
remote_configuration_path: "https://raw.githubusercontent.com/leoviana00/lab-k8s-prep-cks/main/.github/pr-title-checker-config.json" | |
- name: Comment PR on Success and Add Label | |
if: success() | |
run: | | |
AUTHOR_NAME=${{ github.event.pull_request.user.login }} | |
cat <<EOT > message.txt | |
Aí sim hein $AUTHOR_NAME ! Seu PR foi aprovado 🥳 | |
Faremos o merge aqui em breve. Muito obrigado pela contribuição 🚀 | |
EOT | |
gh pr comment ${{ github.event.pull_request.number }} --body-file=message.txt | |
gh pr edit ${{ github.event.pull_request.number }} --add-label "PR:Is-valid" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Comment PR on Failure | |
if: failure() | |
run: | | |
AUTHOR_NAME=${{ github.event.pull_request.user.login }} | |
cat <<EOT > message.txt | |
Olá $AUTHOR_NAME ! 🚫 Parece que houve um problema com o seu PR 🧐 Aqui estão algumas coisas para verificar: | |
- Seu PR deve seguir a [convenção de commits](https://www.conventionalcommits.org/pt-br/v1.0.0-beta.4/). | |
Agradecemos sua contribuição e compreensão 👊😉 | |
EOT | |
gh pr comment ${{ github.event.pull_request.number }} --body-file=message.txt | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |