Skip to content

Commit

Permalink
Add possibility to add/remove all labels
Browse files Browse the repository at this point in the history
* "accepted" labels have been removed

* if "all" or "!all" mentioned, take precedence over specific labels

* "all" takes precedence over "!all"

* do not add and remove labels at the same time, adding labels takes
  precedence
  • Loading branch information
Benedikt Volkel committed Jun 17, 2024
1 parent 91cc88e commit 94ac395
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/async-auto-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,40 @@ jobs:
review.dismiss('Labels updated; please review again.')
possible_labels = {label.name: label for label in repo.get_labels() if label.name.startswith('async-')}
add_labels, invalid_labels = [], []
add_labels, remove_labels, invalid_labels = [], [], []
# "all" or "!all" takes precedence over specific labels
if 'all' in labels:
labels = list(possible_labels.keys())
elif '!all' in labels:
labels = [f'!{name}' for name in possible_labels.keys()]
for label_name in labels:
delete = label_name.startswith('!')
label_name = label_name.lstrip('!')
try:
label = possible_labels[label_name]
except KeyError:
print(f'::warning::Ignoring unknown label {label_name!r}')
invalid_labels.append(label_name)
continue
if delete:
pr.remove_from_labels(label)
else:
add_labels.append(label)
remove_labels.append(label)
continue
add_labels.append(label)
# adding labels takes precedence, so remove from this list the ones that should in fact be added
remove_labels = [label for label in remove_labels if label not in add_labels]
for label in remove_labels:
# to be done label-by-label
pr.remove_from_labels(label)
pr.add_to_labels(*add_labels)
if add_labels:
pr.add_to_labels(*add_labels)
if invalid_labels:
pr.create_issue_comment(
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/async-list-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
+async-label <label1>, <label2>, !<label3> ...\n \
\`\`\`\n \
This will add \`<label1>\` and \`<label2>\` and removes \`<label3>\`.\n\n \
To add all labels, comment with \n \
\`\`\`\n \
+async-label all\n \
\`\`\`\n \
To remove all labels, comment with \n \
\`\`\`\n \
+async-label !all\n \
\`\`\`\n \
**The following labels are available**\n${labels_line_break}"
# read the body text from stdin
echo -e "${body_text}" | gh pr comment "${nr}" --body-file - --repo "${GITHUB_REPOSITORY}"

0 comments on commit 94ac395

Please sign in to comment.