Skip to content

ci: add commit message linting to ci workflow#348

Open
ayushiahjolia wants to merge 1 commit intomainfrom
ci_linter
Open

ci: add commit message linting to ci workflow#348
ayushiahjolia wants to merge 1 commit intomainfrom
ci_linter

Conversation

@ayushiahjolia
Copy link
Copy Markdown
Contributor

Issue #, if available: #345

Description of changes: Added --subject flag to lintcommit.py and 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.

@ayushiahjolia ayushiahjolia self-assigned this Apr 17, 2026
@ayushiahjolia
Copy link
Copy Markdown
Contributor Author

lint-pr-title job is skipped for this PR, because it was introduced in this PR. It will run on subsequent PRs.

@ayushiahjolia ayushiahjolia force-pushed the ci_linter branch 2 times, most recently from e660273 to 4c897b5 Compare April 24, 2026 18:48
@ayushiahjolia ayushiahjolia changed the title ci: add pr title linting to ci workflow ci: add commit message linting to ci workflow Apr 24, 2026
@ayushiahjolia ayushiahjolia force-pushed the ci_linter branch 2 times, most recently from 748814c to 2330f85 Compare April 24, 2026 18:52
Comment thread ops/lintcommit.py
skip_dirty_check: When True, skip the uncommitted changes check
(useful in CI where the worktree may be clean by definition).
"""
import subprocess
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid inline imports (import on top)


run_range("origin/main..HEAD", skip_dirty_check=True)

out = capsys.readouterr().out
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread ops/lintcommit.py
# Skip merge commits (auto-generated by git)
if subject_line.startswith("Merge "):
print(f"SKIP {sha}: {subject_line} (merge commit)")
continue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ops/lintcommit.py
# 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---"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants