@@ -41,73 +41,73 @@ jobs:
4141 labels = os.environ['labels']
4242 tags = {
4343 "infrastructure": "Infrastructure",
44+ "scripts": "Scripts",
45+ "tools": "Tools",
4446 "common": "Common",
47+ "trigger": "Trigger",
48+ "dpg": "DPG",
49+ "tutorial": "Tutorial",
4550 "alice3": "ALICE3",
4651 "pwgcf": "PWGCF",
4752 "pwgdq": "PWGDQ",
4853 "pwgem": "PWGEM",
4954 "pwghf": "PWGHF",
5055 "pwgje": "PWGJE",
5156 "pwglf": "PWGLF",
57+ "pwgmm": "PWGMM",
5258 "pwgud": "PWGUD",
53- "dpg": "DPG",
54- "trigger": "Trigger",
55- "tutorial": "Tutorial",
5659 }
5760 print(f'PR title: "{title}"')
5861 print(f'PR labels: "{labels}"')
5962 tags_relevant = [tags[label] for label in tags if label in labels.split(",")]
6063 print("Relevant title tags:", ",".join(tags_relevant))
61- passed = True
62- prefix_good = ",".join(tags_relevant)
63- prefix_good = f"[{prefix_good}] "
64- print(f"Generated prefix: {prefix_good}")
65- replace_title = 0
66- title_new = title
64+ prefix_generated = ",".join(tags_relevant)
65+ prefix_generated = f"[{prefix_generated}] "
66+ print(f"Generated prefix: {prefix_generated}")
67+ found_tags = False
68+ title_new = title.strip()
6769 # If there is a prefix which contains a known tag, check it for correct tags, and reformat it if needed.
6870 # If there is a prefix which does not contain any known tag, add the tag prefix.
6971 # If there is no prefix, add the tag prefix.
70- if match := re.match(r"\[?(\w[\w, /\+- ]+)[\]:]+ ", title):
72+ if match := re.match(r" * \[?(\w[\w,/\+\- ]+)[\]: ]+ ", title):
7173 prefix_title = match.group(1)
7274 words_prefix_title = prefix_title.replace(",", " ").replace("/", " ").split()
73- title_stripped = title[len(match.group()) :]
75+ title_stripped = title[len(match.group()) :].strip()
7476 print(f'PR title prefix: "{prefix_title}" -> tags: {words_prefix_title}')
7577 print(f'Stripped PR title: "{title_stripped}"')
7678 if any(tag in words_prefix_title for tag in tags.values()):
79+ found_tags = True
80+ passed = True
7781 for tag in tags.values():
7882 if tag in tags_relevant and tag not in words_prefix_title:
7983 print(f'::error::Relevant tag "{tag}" not found in the prefix of the PR title.')
8084 passed = False
8185 if tag not in tags_relevant and tag in words_prefix_title:
8286 print(f'::error::Irrelevant tag "{tag}" found in the prefix of the PR title.')
8387 passed = False
84- # Format a valid prefix.
85- if passed:
86- prefix_good = ",".join(w for w in prefix_title.replace(",", " ").split() if w)
87- prefix_good = f"[{prefix_good}] "
88- print(f"::notice::Reformatted prefix: {prefix_good}")
89- if match.group() != prefix_good:
90- replace_title = 1
91- title_new = prefix_good + title_stripped
88+ if not passed:
89+ print("::error::Problems were found in the PR title prefix.")
90+ print('::notice::Use the form "tags: title" or "[tags] title".')
91+ sys.exit(1)
92+ # Form a valid title with the existing prefix.
93+ prefix_good = ",".join(w for w in prefix_title.replace(",", " ").split() if w)
94+ prefix_good = f"[{prefix_good}] "
95+ print(f'::notice::Reformatted prefix: "{prefix_good}"')
96+ title_new = prefix_good + title_stripped
9297 else:
9398 print("::warning::No known tags found in the prefix.")
94- if tags_relevant:
95- replace_title = 1
96- title_new = prefix_good + title
99+ title_new = " ".join((*match.group().split(), title_stripped))
97100 else:
98101 print("::warning::No valid prefix found in the PR title.")
99- if tags_relevant:
100- replace_title = 1
101- title_new = prefix_good + title
102- if not passed:
103- print("::error::Problems were found in the PR title prefix.")
104- print('::notice::Use the form "tags: title" or "[tags] title".')
105- sys.exit(1)
106- if replace_title:
107- print("::warning::The PR title prefix with tags needs to be added or adjusted.")
108- print(f'::warning::New title: "{title_new}".')
102+ if not found_tags and tags_relevant:
103+ title_new = prefix_generated + title_new.strip()
104+ replace_title = 0
105+ if title_new == title:
106+ print("::notice::The PR title is fine.")
109107 else:
110- print("::notice::The PR title prefix is fine.")
108+ replace_title = 1
109+ print("::warning::The PR title needs to be adjusted.")
110+ print(f'::warning::New title: "{title_new}".')
111111 with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh:
112112 print(f"replace={replace_title}", file=fh)
113113 print(f"title={title_new}", file=fh)
0 commit comments