ci: add commit message linting to ci workflow#348
Conversation
|
|
e660273 to
4c897b5
Compare
748814c to
2330f85
Compare
c55fe7d to
7f7fbfa
Compare
| skip_dirty_check: When True, skip the uncommitted changes check | ||
| (useful in CI where the worktree may be clean by definition). | ||
| """ | ||
| import subprocess |
There was a problem hiding this comment.
avoid inline imports (import on top)
|
|
||
| run_range("origin/main..HEAD", skip_dirty_check=True) | ||
|
|
||
| out = capsys.readouterr().out |
There was a problem hiding this comment.
this would test a lot easier if you refactor the logic into a function that returns an errs and/or warnings collection.
then you dont have to capture stdout/stderr.
You could maybe have a separate write_output(info: list, errs: list) method?
| # Skip merge commits (auto-generated by git) | ||
| if subject_line.startswith("Merge "): | ||
| print(f"SKIP {sha}: {subject_line} (merge commit)") | ||
| continue |
There was a problem hiding this comment.
we don't want merge commits.
so maybe just remove this section.
gh has "Require linear history - Prevent merge commits from being pushed to matching refs." enabled..
can prob pass --no-merges.
| # Get all commit messages in the range | ||
| result: subprocess.CompletedProcess[str] = subprocess.run( | ||
| ["git", "log", "origin/main..HEAD", "--format=%H%n%B%n---END---"], | ||
| ["git", "log", git_range, "--format=%H%n%B%n---END---"], |
There was a problem hiding this comment.
rather than magic string to split, use null char. (i.e it's possible a commit msg has a legit ---END--- in it)
result = subprocess.run(
["git", "log", "--no-merges", git_range, "-z", "--format=%H%n%B"],
capture_output=True, text=True,
)
if result.returncode != 0:
print(f"git log failed: {result.stderr}", file=sys.stderr)
sys.exit(1)
commits: list[tuple[str, str]] = []
for r in result.stdout.split("\0"):
if not r.strip():
continue
sha, _, message = r.partition("\n")
commits.append((sha, message.strip()))
Issue #, if available: #345
Description of changes: Added
--subjectflag tolintcommit.pyand a lint-pr-title CI job that validates PR titles against conventional commits on pull requests.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.