generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathlabel-zero-impact.js
78 lines (72 loc) · 1.99 KB
/
label-zero-impact.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const { getLocalConfigs } = require('./helpers.js');
const zeroImpactDirs = [
'.github',
'.kodiak',
'.vscode',
'.test',
'.browserslistrc',
'.gitignore',
'.eslintrc.js',
'CODEOWNERS',
'web-test-runner.config.mjs',
'LICENSE',
'codecov.yaml',
'package.json',
'package-lock.json',
'test',
'libs/mep',
'nala'
];
const zeroImpactLabel = 'zero-impact';
// Run from the root of the project for local testing: node --env-file=.env .github/workflows/label-zero-impact.js
const main = async ({ github, context }) => {
const number = context.issue?.number || process.env.ISSUE;
const owner = context.repo.owner;
const repo = context.repo.repo;
try {
const { data: files } = await github.rest.pulls.listFiles({
owner,
repo,
pull_number: number,
});
const isZeroImpactPR = files.every(({ filename }) =>
zeroImpactDirs.some((dir) => filename.startsWith(dir))
);
console.log(`PR ${number} is zero impact: ${isZeroImpactPR}.`);
if (isZeroImpactPR) {
console.log('Adding zero-impact label to PR.');
await github.rest.issues.addLabels({
owner,
repo,
issue_number: number,
labels: [zeroImpactLabel],
});
} else {
console.log('Removing zero-impact label from PR.');
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: number,
name: zeroImpactLabel,
});
console.log('Posting a comment on the PR.');
await github.rest.issues.createComment({
owner,
repo,
issue_number: number,
body: 'This PR does not qualify for the zero-impact label as it touches code outside of the allowed areas. The label is auto applied, do not manually apply the label.',
});
}
console.log('Process successfully executed.');
} catch (error) {
console.error(error);
}
};
if (process.env.LOCAL_RUN) {
const { github, context } = getLocalConfigs();
main({
github,
context,
});
}
module.exports = main;