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

Add possibility to add/remove all labels #1303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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}"
Loading