Added output (#60)

* Added output

* removed formatting changes

* more formatting changes

* Fix merge conflicts

* Small test refactoring

* tests are passing

* Add a test

* Add a small jest mock for addLabels. Not used.

* Add tests for more cases

* get rid of an unused jest mock

* fix review points

* rebuild + minor README fix

* fix review points

* update tests

* fix formatting

* add tests, fix bug

* cleanup

---------

Co-authored-by: Daniel Shteremberg <[email protected]>
Co-authored-by: Daniel Shteremberg <[email protected]>
Co-authored-by: Patrick Ellis <[email protected]>
Co-authored-by: Andrey Lobanovich <[email protected]>
This commit is contained in:
Daniel Shteremberg
2023-06-29 12:45:24 +02:00
committed by GitHub
co-authored by Daniel Shteremberg Daniel Shteremberg Patrick Ellis Andrey Lobanovich
parent 375538a703
commit 0967ca812e
5 changed files with 99 additions and 16 deletions
+11 -5
View File
@@ -43,8 +43,8 @@ export async function run() {
configPath
);
const prLabels: string[] = pullRequest.labels.map(label => label.name);
const allLabels: Set<string> = new Set(prLabels);
const preexistingLabels = pullRequest.labels.map(l => l.name);
const allLabels: Set<string> = new Set<string>(preexistingLabels);
for (const [label, globs] of labelGlobs.entries()) {
core.debug(`processing ${label}`);
@@ -55,14 +55,20 @@ export async function run() {
}
}
const labels = [...allLabels].slice(0, GITHUB_MAX_LABELS);
const labelsToAdd = [...allLabels].slice(0, GITHUB_MAX_LABELS);
const excessLabels = [...allLabels].slice(GITHUB_MAX_LABELS);
try {
if (!isListEqual(prLabels, labels)) {
await setLabels(client, prNumber, labels);
let newLabels: string[] = [];
if (!isListEqual(labelsToAdd, preexistingLabels)) {
await setLabels(client, prNumber, labelsToAdd);
newLabels = labelsToAdd.filter(l => !preexistingLabels.includes(l));
}
core.setOutput('new-labels', newLabels.join(','));
core.setOutput('all-labels', labelsToAdd.join(','));
if (excessLabels.length) {
core.warning(
`Maximum of ${GITHUB_MAX_LABELS} labels allowed. Excess labels: ${excessLabels.join(