From: michaelni <code@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Revert "forgejo/lint_commit_msg: add script for commit message linting" (PR #20147) Date: Thu, 7 Aug 2025 01:47:41 +0300 (EEST) Message-ID: <20250806224741.A7290687A19@ffbox0-bg.ffmpeg.org> (raw) PR #20147 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20147 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20147.patch This should be done by fate. This script already blocks security fixes (https://code.ffmpeg.org/FFmpeg/FFmpeg/actions/runs/1046/jobs/0) IMHO its not good 1. to add commit message formating rules, never discussed or agreed 2. to expect developers to push commits trial and error style, make fate can test this already and tell the devlopers before pushing, saving him time This reverts commit cc6ad703b41e318bd1e4cb6196defaf505dbfea3. From cf0de00019fac8f54a4cdc12473fa604d7502849 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <michael@niedermayer.cc> Date: Thu, 7 Aug 2025 00:33:02 +0200 Subject: [PATCH] Revert "forgejo/lint_commit_msg: add script for commit message linting" This should be done by fate. This script already blocks security fixes (https://code.ffmpeg.org/FFmpeg/FFmpeg/actions/runs/1046/jobs/0) IMHO its not good 1. to add commit message formating rules, never discussed or agreed 2. to expect developers to push commits trial and error style, make fate can test this already and tell the devlopers before pushing, saving him time This reverts commit cc6ad703b41e318bd1e4cb6196defaf505dbfea3. --- .forgejo/pre-commit/lint_commit_msg.py | 138 ------------------------- .forgejo/workflows/lint.yml | 11 -- 2 files changed, 149 deletions(-) delete mode 100755 .forgejo/pre-commit/lint_commit_msg.py diff --git a/.forgejo/pre-commit/lint_commit_msg.py b/.forgejo/pre-commit/lint_commit_msg.py deleted file mode 100755 index 443f7a4525..0000000000 --- a/.forgejo/pre-commit/lint_commit_msg.py +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env python3 -import json -import os -import re -import subprocess -import sys -import urllib.request as request -from collections.abc import Callable - -LintBody = list[str] -LintFunction = Callable[[LintBody], bool] -LintRule = tuple[LintFunction, str] - -def call(cmd: list[str]) -> str: - sys.stdout.flush() - ret = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, encoding="utf-8", text=True) - return ret.stdout - -lint_rules: dict[str, LintRule] = {} - -# A lint rule should return True if everything is okay -def lint_rule(description: str) -> Callable[[LintFunction], None]: - def f(func: LintFunction) -> None: - assert func.__name__ not in lint_rules - lint_rules[func.__name__] = (func, description) - return f - -def get_pr_commits() -> list[tuple[str, list[str]]]: - pr_number = os.environ["GITHUB_REF"].split("/")[2] - api_url = os.environ["GITHUB_API_URL"] - repo = os.environ["GITHUB_REPOSITORY"] - - url = f"{api_url}/repos/{repo}/pulls/{pr_number}/commits" - req = request.Request(url) - req.add_header("Accept", "application/vnd.github+json") - if "GITHUB_TOKEN" in os.environ: - req.add_header("Authorization", f"token {os.environ['GITHUB_TOKEN']}") - - with request.urlopen(req) as response: - commits = json.load(response) - - res = [] - for commit in commits: - sha = commit["sha"] - message = commit["commit"]["message"] - res.append((sha, message.splitlines())) - - return res - -def get_commits() -> list[tuple[str, list[str]]]: - if os.environ.get("GITHUB_EVENT_NAME") == "pull_request": - return get_pr_commits() - - commit_range = sys.argv[1] if len(sys.argv) > 1 else None - if not commit_range: - return [] - - commits = call(["git", "log", "-z", "--pretty=format:%H%n%B", commit_range]).split("\x00") - res = [] - for commit in commits: - if not commit.strip(): - continue - sha, message = commit.split("\n", 1) - res.append((sha, message.splitlines())) - - return res - -def lint_commit_message(body: list[str]) -> list[str]: - failed = [] - assert len(body) > 0, "Commit message must not be empty" - for k, v in lint_rules.items(): - if not v[0](body): - failed.append(f"* {v[1]} [{k}]") - - return failed - -def lint(commits: list[tuple[str, list[str]]]) -> bool: - print(f"Linting {len(commits)} commit(s):") - any_failed = False - for sha, body in commits: - if failed := lint_commit_message(body): - any_failed = True - print("-" * 40) - if os.environ.get("GITHUB_EVENT_NAME") == "pull_request": - print(f"Commit {sha[:8]}: {body[0] if body else "(empty)"}") - else: - sys.stdout.flush() - subprocess.run(["git", "-P", "show", "-s", sha]) - print("\nhas the following issues:") - print("\n".join(failed)) - print("-" * 40) - - return not any_failed - - -NO_PREFIX_WHITELIST = \ - r"^Revert \"(.*)\"|^Reapply \"(.*)\"" - -@lint_rule("Subject line must contain a prefix identifying the sub system") -def subsystem_prefix(body: LintBody) -> bool: - return bool(re.search(NO_PREFIX_WHITELIST, body[0]) or - re.search(r"^[\w/\.{},-]+: ", body[0])) - -@lint_rule("First word after : must be lower case") -def description_lowercase(body: LintBody) -> bool: - # Allow all caps for acronyms and options with -- - return bool(re.search(NO_PREFIX_WHITELIST, body[0]) or - re.search(r": (?:[A-Z]{2,} |--[a-z]|[a-z0-9])", body[0])) - -@lint_rule("Subject line must not end with a full stop") -def no_dot(body: LintBody) -> bool: - return not body[0].rstrip().endswith(".") - -@lint_rule("There must be an empty line between subject and extended description") -def empty_line(body: LintBody) -> bool: - return len(body) == 1 or body[1].strip() == "" - -@lint_rule("Do not use 'conventional commits' style") -def no_cc(body: LintBody) -> bool: - return not re.search(r"(?i)^(feat|fix|chore|refactor)[!:(]", body[0]) - -@lint_rule("Subject line should be shorter than 120 characters") -def line_too_long(body: LintBody) -> bool: - revert = re.search(r"^Revert \"(.*)\"|^Reapply \"(.*)\"", body[0]) - return bool(revert or len(body[0]) <= 120) - -@lint_rule("Prefix should not include file extension") -def no_file_exts(body: LintBody) -> bool: - return not re.search(r"[a-z0-9]\.([chm]|texi): ", body[0]) - - -if __name__ == "__main__": - commits = get_commits() - if not commits: - print("Usage: ./lint_commits.py <commit-range>") - exit(1) - if not lint(commits): - exit(2) diff --git a/.forgejo/workflows/lint.yml b/.forgejo/workflows/lint.yml index 6469ad5211..42e925ad8b 100644 --- a/.forgejo/workflows/lint.yml +++ b/.forgejo/workflows/lint.yml @@ -5,17 +5,6 @@ on: pull_request: jobs: - commit_msg: - runs-on: utilities - if: ${{ forge.event_name == 'pull_request' }} - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - sparse-checkout: .forgejo/pre-commit - - name: Lint - run: .forgejo/pre-commit/lint_commit_msg.py - lint: runs-on: utilities steps: -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2025-08-06 22:47 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-08-06 22:47 michaelni [this message] [not found] <20250806224741.7A66B68CC6E@ffbox0-bg.ffmpeg.org> 2025-08-07 8:45 ` Nicolas George
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250806224741.A7290687A19@ffbox0-bg.ffmpeg.org \ --to=code@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git