Skip to content

Commit

Permalink
ci(*:skip) Fix PR title check regex (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbvll authored May 23, 2024
1 parent 14deafd commit 97d1d4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
pr_title_check:
runs-on: ubuntu-22.04
name: Title format
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4
- name: Bootstrap
Expand Down
2 changes: 1 addition & 1 deletion dev/changelog_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project = ["framework", "baselines", "datasets", "examples"]

scope = "skip"

pattern_template = "^({types})\\(({projects})(?::({scope}))?\\) ([A-Z][^\\.\\n]*(?:\\.(?=[^\\.\\n]))*[^\\.\\n]*)$"
pattern_template = "^({types})\\(({projects})(?::({scope}))?\\) ([A-Z][^\\n]*[^\\.\\n])$"

allowed_verbs=[
"Abandon",
Expand Down
29 changes: 16 additions & 13 deletions dev/check_pr_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""This module is used to check a given PR title format."""
"""Used to check a given PR title format."""

import pathlib
import re
Expand Down Expand Up @@ -46,10 +46,13 @@
valid = True
error = "it doesn't have the correct format"

if not match:
# This check is there to ignore dependabot PRs from title checks
if pr_title.startswith("chore"):
sys.exit(0)
elif not match:
valid = False
else:
if not match.group(4).split()[0] in allowed_verbs:
if match.group(4).split()[0] not in allowed_verbs:
valid = False
error = "the <PR_SUBJECT> doesn't start with a verb in the imperative mood"
elif match.group(2) == "*" and match.group(3) is None:
Expand All @@ -58,16 +61,16 @@

if not valid:
print(
f"PR title `{pr_title}` is invalid, {error}.\n\n"
"A PR title should be of the form:\n\n\t<PR_TYPE>(<PR_PROJECT>) "
f"<PR_SUBJECT>\n\nOr, if the PR shouldn't appear in the changelog:\n\n\t"
f"<PR_TYPE>(<PR_PROJECT>:skip) <PR_SUBJECT>\n\nwith <PR_TYPE> in [{types}],\n"
f"<PR_PROJECT> in [{'|'.join(config['project']) + '|*'}] (where '*' is used "
"when modifying multiple projects and should be used in "
f"PR title `{pr_title}` is invalid, {error}.\n\nA PR title should "
"be of the form:\n\n\t<PR_TYPE>(<PR_PROJECT>) <PR_SUBJECT>\n\n"
f"Or, if the PR shouldn't appear in the changelog:\n\n\t<PR_TYPE>"
f"(<PR_PROJECT>:skip) <PR_SUBJECT>\n\nwith <PR_TYPE> in [{types}],\n"
f"<PR_PROJECT> in [{'|'.join(config['project']) + '|*'}] "
"(where '*' is used when modifying multiple projects and should be used in "
"conjunction with the ':skip' flag),\nand <PR_SUBJECT> starting with "
"a capitalized verb in the imperative mood and without any punctuation at the end.\n\n"
"A valid example is:\n\n\t`feat(framework) Add flwr build CLI command`\n\n"
"Or, if the PR shouldn't appear in the changelog:\n\n\t"
"`feat(framework:skip) Add new option to build CLI`\n"
"a capitalized verb in the imperative mood and without any punctuation "
"at the end.\n\nA valid example is:\n\n\t`feat(framework) "
"Add flwr build CLI command`\n\nOr, if the PR shouldn't appear in "
"the changelog:\n\n\t`feat(framework:skip) Add new option to build CLI`\n"
)
sys.exit(1)

0 comments on commit 97d1d4d

Please sign in to comment.