Skip to content

Commit 45aaf67

Browse files
authored
Merge pull request #106 from creativecommons/message_invalid_labels
Find issues with invalid labels and export them in a report
2 parents e10becf + 614745e commit 45aaf67

File tree

6 files changed

+203
-30
lines changed

6 files changed

+203
-30
lines changed

.github/workflows/normalize_repos.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Normalize Repos
2-
on:
2+
on:
3+
workflow_dispatch:
34
schedule:
45
- cron: '0 0 * * *'
56
push:
@@ -26,3 +27,8 @@ jobs:
2627
pipenv run python normalize_repos.py
2728
env:
2829
ADMIN_GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
30+
- name: Export a report of invalid issues
31+
uses: actions/upload-artifact@v2
32+
with:
33+
name: invalid-issue-report
34+
path: /tmp/invalid_issues.yml

normalize_repos/get_labels.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
from models import Group, Label
77

88

9+
def get_groups():
10+
"""
11+
Get the list of label groups.
12+
@return: the list of label groups.
13+
"""
14+
15+
labels_dict = load_yaml_from_file("labels")
16+
groups = []
17+
for group_info in labels_dict["groups"]:
18+
group = Group(**group_info)
19+
label_names = group_info.pop("labels", [])
20+
groups.append(group)
21+
for label_info in label_names:
22+
Label(**label_info, group=group)
23+
return groups
24+
25+
926
def get_standard_labels():
1027
"""
1128
Get the list of standard labels that apply to every repository.
@@ -93,13 +110,13 @@ def get_datafile_path(file_name):
93110

94111
def get_labels():
95112
"""
96-
Get the standard list of packages and the repository-specific labels.
97-
@return: the standard list of packages and the repository-specific labels
113+
Get the list of standard and repository-specific labels.
114+
@return: the list of standard and repository-specific labels
98115
"""
99116

100117
standard_labels = get_standard_labels()
101118
repo_specific_labels = get_repo_specific_labels()
102119
return standard_labels, repo_specific_labels
103120

104121

105-
__all__ = ["get_labels"]
122+
__all__ = ["get_labels", "get_groups"]

normalize_repos/labels.yml

+24-24
Original file line numberDiff line numberDiff line change
@@ -5,116 +5,116 @@ groups:
55
- name: critical
66
color: 'UNFAVOURABLE'
77
description: Must be fixed ASAP
8-
emoji: "\uD83D\uDFE5"
8+
emoji: "🟥"
99
- name: high
1010
color: 'NEGATIVE'
1111
description: Stalls work on the project or its dependents
12-
emoji: "\uD83D\uDFE7"
12+
emoji: "🟧"
1313
- name: medium
1414
color: 'NEUTRAL'
1515
description: Not blocking but should be fixed soon
16-
emoji: "\uD83D\uDFE8"
16+
emoji: "🟨"
1717
- name: low
1818
color: 'POSITIVE'
1919
description: Low priority and doesn't need to be rushed
20-
emoji: "\uD83D\uDFE9"
20+
emoji: "🟩"
2121

2222
- name: status
2323
is_required: true
2424
labels:
2525
- name: ready for work
2626
color: 'LIGHT'
2727
description: Ready for work
28-
emoji: "\uD83C\uDFC1"
28+
emoji: "🏁"
2929
- name: blocked
3030
color: 'MEDIUM'
3131
description: Blocked & therefore, not ready for work
32-
emoji: "\uD83D\uDEA7"
32+
emoji: "🚧"
3333
- name: ticket work required
3434
color: 'DARK'
3535
description: Needs more details before it can be worked on
36-
emoji: "\uD83E\uDDF9"
36+
emoji: "🧹"
3737
- name: discarded
3838
color: 'LIGHTER'
3939
description: Will not be worked on
40-
emoji: '⛔️'
40+
emoji: "⛔️"
4141
- name: awaiting triage
4242
color: 'DARKER'
4343
description: Has not been triaged & therefore, not ready for work
44-
emoji: "\uD83D\uDEA6"
44+
emoji: "🚦"
4545

4646
- name: goal
4747
color: 'ffffff'
4848
is_required: true
4949
labels:
5050
- name: addition
5151
description: Addition of new feature
52-
emoji: "\uD83C\uDF1F"
52+
emoji: "🌟"
5353
- name: improvement
5454
description: Improvement to an existing feature
55-
emoji: ''
55+
emoji: ""
5656
- name: fix
5757
description: Bug fix
58-
emoji: "\uD83D\uDEE0"
58+
emoji: "🛠"
5959

6060
- name: aspect
6161
color: '04338c'
6262
is_required: true
6363
labels:
6464
- name: text
6565
description: Concerns the textual material in the repository
66-
emoji: "\uD83D\uDCC4"
66+
emoji: "📄"
6767
- name: code
6868
description: Concerns the software code in the repository
69-
emoji: "\uD83D\uDCBB"
69+
emoji: "💻"
7070
- name: interface
7171
description: Concerns end-users' experience with the software
72-
emoji: "\uD83D\uDD79"
72+
emoji: "🕹"
7373
- name: dx
7474
description: Concerns developers' experience with the codebase
75-
emoji: "\uD83E\uDD16"
75+
emoji: "🤖"
7676

7777
- name: talk
7878
color: 'f9bbe5'
7979
labels:
8080
- name: question
8181
description: Can be resolved with an answer
82-
emoji: ''
82+
emoji: ""
8383
- name: discussion
8484
description: Open for discussions and feedback
85-
emoji: "\uD83D\uDCAC"
85+
emoji: "💬"
8686

8787
- name: friendliness
8888
color: '7f0799'
8989
is_prefixed: false
9090
labels:
9191
- name: good first issue
9292
description: New-contributor friendly
93-
emoji: "\uD83E\uDD17"
93+
emoji: "🤗"
9494
has_emoji_name: false
9595
- name: help wanted
9696
description: Open to participation from the community
97-
emoji: "\uD83D\uDE4F"
97+
emoji: "🙏"
9898
has_emoji_name: false
9999
- name: staff only
100100
description: Restricted to CC staff members
101-
emoji: "\uD83D\uDD12"
101+
emoji: "🔒"
102102

103103
standalone:
104104
- name: 'ノಠ益ಠノ彡┻━┻'
105105
color: '000000'
106106
description: Aaargh!
107-
emoji: "\uD83E\uDD2F"
107+
emoji: "🤯"
108108

109109
- name: Hacktoberfest
110110
color: '883255'
111111
description: Ideal for Hacktoberfest participation
112-
emoji: "\uD83C\uDF83"
112+
emoji: "🎃"
113113
has_emoji_name: false
114114

115115
- name: invalid
116116
color: 'LIGHTER'
117117
description: Inappropriate or invalid (ex. Hacktoberfest spam)
118-
emoji: '⛔️'
118+
emoji: "⛔️"
119119
has_emoji_name: false
120120

normalize_repos/models.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ class Group:
88
- name, which may be prefixed to all child label names
99
- color, which acts as a fallback for child labels that do not specify one
1010
- is_prefixed, which determines if group name is prefixed on child labels
11+
- is_required, which determines if >=1 sub-label must be applied on issues
1112
"""
1213

13-
def __init__(self, color=None, is_prefixed=True, **kwargs):
14+
def __init__(
15+
self, color=None, is_prefixed=True, is_required=False, **kwargs
16+
):
1417
self.name = kwargs["name"]
1518
self.color = color
1619
self.is_prefixed = is_prefixed
20+
self.is_required = is_required
21+
22+
self.labels = [] # This may or may not be populated, do not rely
1723

1824
def __str__(self):
1925
return self.name
@@ -42,6 +48,8 @@ def __init__(self, group=None, color=None, has_emoji_name=True, **kwargs):
4248
self.has_emoji_name = has_emoji_name
4349

4450
self.group = group
51+
if group and self not in group.labels:
52+
group.labels.append(self)
4553

4654
@property
4755
def color(self):

normalize_repos/normalize_repos.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import yaml # For converting .cc-metadata.yml to Python dictionary
1818

1919
# Local/library specific
20-
from get_labels import get_labels
20+
from get_labels import get_labels, get_groups
2121
from set_labels import set_labels
22+
from validate_issues import validate_issues
2223
from utils import get_cc_organization, set_up_github_client
2324
import branch_protections
2425
import log
@@ -62,6 +63,9 @@ def setup():
6263
action="store_true",
6364
help="skip labels update",
6465
)
66+
ap.add_argument(
67+
"--skip-issues", action="store_true", help="skip issue labels check"
68+
)
6569
args = ap.parse_args()
6670
return args
6771

@@ -97,6 +101,15 @@ def set_repo_labels(args, repos):
97101
logger.log(log.SUCCESS, "done.")
98102

99103

104+
def validate_issue_labels(args, repos):
105+
if args.skip_issues:
106+
return
107+
logger.log(logging.INFO, "Checking issues...")
108+
groups = get_groups()
109+
validate_issues(repos, groups)
110+
logger.log(log.SUCCESS, "done.")
111+
112+
100113
def is_engineering_project(repo):
101114
try:
102115
contents = repo.get_contents(".cc-metadata.yml")
@@ -160,6 +173,7 @@ def main():
160173
logger.log(logging.INFO, "Starting normalization")
161174
repos = get_select_repos(args)
162175
set_repo_labels(args, repos)
176+
validate_issue_labels(args, repos)
163177
update_branches(args, repos)
164178

165179

0 commit comments

Comments
 (0)