Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label Improvements #280

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions __tests__/functions/label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ test('adds two labels to a pull request and removes none', async () => {
})
})

test('adds a single label to a pull request and tries to remove a label but it is not on the PR to begin with', async () => {
expect(
await label(context, octokit, ['read-for-review'], ['unknown-label'])
).toStrictEqual({
added: ['read-for-review'],
removed: []
})
})

test('does not add or remove any labels', async () => {
expect(await label(context, octokit, [], [])).toStrictEqual({
added: [],
Expand Down
11 changes: 6 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/functions/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export async function label(context, octokit, labelsToAdd, labelsToRemove) {
// Get the owner, repo, and issue number from the context
const {owner, repo} = context.repo
const issueNumber = context.issue.number
var addedLabels = []
var removedLabels = []
var addedLabels = [] // an array of labels that were actually added
var removedLabels = [] // an array of labels that were actually removed

// exit early if there are no labels to add or remove
if (labelsToAdd.length === 0 && labelsToRemove.length === 0) {
Expand Down Expand Up @@ -45,11 +45,12 @@ export async function label(context, octokit, labelsToAdd, labelsToRemove) {
issue_number: issueNumber,
name: label
})
core.info(`🏷️ label removed: ${label}`)
removedLabels.push(label)
} else {
core.debug(`🏷️ label not found: '${label}' so it was not removed`)
}
}
core.info(`🏷️ labels removed: ${labelsToRemove}`)

removedLabels = labelsToRemove
}

// now, add the labels if any are provided
Expand Down