diff --git a/.github/workflows/label01_changes_requested_&_approved.yaml b/.github/workflows/label01_changes_requested_&_approved.yaml new file mode 100644 index 0000000..4adbfff --- /dev/null +++ b/.github/workflows/label01_changes_requested_&_approved.yaml @@ -0,0 +1,88 @@ +name: Changes requested y Aprobado label + +on: + pull_request_review: + types: [submitted, edited, dismissed] + +jobs: + changes-requested: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const pr = context.payload.pull_request; + const issue_number = pr.number; + + const reviews = await github.rest.pulls.listReviews({ + owner, + repo, + pull_number: issue_number + }); + + // última review por usuario + const latestByUser = {}; + for (const r of reviews.data) { + latestByUser[r.user.login] = r.state; + } + + const hasChangesRequested = Object.values(latestByUser) + .includes('CHANGES_REQUESTED'); + + const approvals = new Set( + reviews.data + .filter(r => r.state === 'APPROVED') + .map(r => r.user.login) + ); + + const labels = pr.labels.map(l => l.name); + + if (hasChangesRequested) { + await github.rest.issues.addLabels({ + owner, + repo, + issue_number, + labels: ['Cambio Requerido'] + }); + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number, + name: 'Aprobado' + }); + } catch (e) { + // label no existía + } + } else { + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number, + name: 'Cambio Requerido' + }); + } catch (e) { + // label no existía + } + if (approvals.size >= 2 && !labels.includes('En desarrollo')) { + await github.rest.issues.addLabels({ + owner, + repo, + issue_number, + labels: ['Aprobado'] + }); + } else { + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number, + name: 'Aprobado' + }); + } catch (e) { + // label no existía + } + } + } diff --git a/.github/workflows/label02_has_conflicts.yaml b/.github/workflows/label02_has_conflicts.yaml new file mode 100644 index 0000000..ed25db1 --- /dev/null +++ b/.github/workflows/label02_has_conflicts.yaml @@ -0,0 +1,37 @@ +name: PR conflict label + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + conflicts: + runs-on: ubuntu-latest + steps: + - name: Check conflicts + uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + const { owner, repo } = context.repo; + const issue_number = pr.number; + + if (pr.mergeable_state === 'dirty') { + await github.rest.issues.addLabels({ + owner, + repo, + issue_number, + labels: ['Conflictos'] + }); + } else { + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number, + name: 'Conflictos' + }); + } catch (e) { + // label no existía + } + } \ No newline at end of file diff --git a/.github/workflows/label04_andes.yaml b/.github/workflows/label04_andes.yaml new file mode 100644 index 0000000..a5423a4 --- /dev/null +++ b/.github/workflows/label04_andes.yaml @@ -0,0 +1,40 @@ +name: Andes linked PR label + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + +jobs: + andes-linked: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + const { owner, repo } = context.repo; + const issue_number = pr.number; + + const body = pr.body || ''; + const regex = /https:\/\/github\.com\/andes\/(app|api)\/pull\/\d+/g; + const linked = regex.test(body); + + if (linked) { + await github.rest.issues.addLabels({ + owner, + repo, + issue_number, + labels: ['Andes'] + }); + } else { + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number, + name: 'Andes' + }); + } catch (e) { + // label no existía + } + }