Skip to content

Commit 246acc0

Browse files
(config) Labels automaticos: has_conflicts, aprobado, andes (#115)
1 parent f015027 commit 246acc0

3 files changed

Lines changed: 165 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Changes requested y Aprobado label
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted, edited, dismissed]
6+
7+
jobs:
8+
changes-requested:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/github-script@v7
12+
with:
13+
script: |
14+
const { owner, repo } = context.repo;
15+
const pr = context.payload.pull_request;
16+
const issue_number = pr.number;
17+
18+
const reviews = await github.rest.pulls.listReviews({
19+
owner,
20+
repo,
21+
pull_number: issue_number
22+
});
23+
24+
// última review por usuario
25+
const latestByUser = {};
26+
for (const r of reviews.data) {
27+
latestByUser[r.user.login] = r.state;
28+
}
29+
30+
const hasChangesRequested = Object.values(latestByUser)
31+
.includes('CHANGES_REQUESTED');
32+
33+
const approvals = new Set(
34+
reviews.data
35+
.filter(r => r.state === 'APPROVED')
36+
.map(r => r.user.login)
37+
);
38+
39+
const labels = pr.labels.map(l => l.name);
40+
41+
if (hasChangesRequested) {
42+
await github.rest.issues.addLabels({
43+
owner,
44+
repo,
45+
issue_number,
46+
labels: ['Cambio Requerido']
47+
});
48+
try {
49+
await github.rest.issues.removeLabel({
50+
owner,
51+
repo,
52+
issue_number,
53+
name: 'Aprobado'
54+
});
55+
} catch (e) {
56+
// label no existía
57+
}
58+
} else {
59+
try {
60+
await github.rest.issues.removeLabel({
61+
owner,
62+
repo,
63+
issue_number,
64+
name: 'Cambio Requerido'
65+
});
66+
} catch (e) {
67+
// label no existía
68+
}
69+
if (approvals.size >= 2 && !labels.includes('En desarrollo')) {
70+
await github.rest.issues.addLabels({
71+
owner,
72+
repo,
73+
issue_number,
74+
labels: ['Aprobado']
75+
});
76+
} else {
77+
try {
78+
await github.rest.issues.removeLabel({
79+
owner,
80+
repo,
81+
issue_number,
82+
name: 'Aprobado'
83+
});
84+
} catch (e) {
85+
// label no existía
86+
}
87+
}
88+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: PR conflict label
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
conflicts:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check conflicts
12+
uses: actions/github-script@v7
13+
with:
14+
script: |
15+
const pr = context.payload.pull_request;
16+
const { owner, repo } = context.repo;
17+
const issue_number = pr.number;
18+
19+
if (pr.mergeable_state === 'dirty') {
20+
await github.rest.issues.addLabels({
21+
owner,
22+
repo,
23+
issue_number,
24+
labels: ['Conflictos']
25+
});
26+
} else {
27+
try {
28+
await github.rest.issues.removeLabel({
29+
owner,
30+
repo,
31+
issue_number,
32+
name: 'Conflictos'
33+
});
34+
} catch (e) {
35+
// label no existía
36+
}
37+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Andes linked PR label
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
jobs:
8+
andes-linked:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/github-script@v7
12+
with:
13+
script: |
14+
const pr = context.payload.pull_request;
15+
const { owner, repo } = context.repo;
16+
const issue_number = pr.number;
17+
18+
const body = pr.body || '';
19+
const regex = /https:\/\/github\.com\/andes\/(app|api)\/pull\/\d+/g;
20+
const linked = regex.test(body);
21+
22+
if (linked) {
23+
await github.rest.issues.addLabels({
24+
owner,
25+
repo,
26+
issue_number,
27+
labels: ['Andes']
28+
});
29+
} else {
30+
try {
31+
await github.rest.issues.removeLabel({
32+
owner,
33+
repo,
34+
issue_number,
35+
name: 'Andes'
36+
});
37+
} catch (e) {
38+
// label no existía
39+
}
40+
}

0 commit comments

Comments
 (0)