mirror of
https://github.com/peakoss/anti-slop
synced 2026-12-01 13:39:13 +08:00
feat(checks): add requireCommitAuthorMatch option
This commit is contained in:
6 files changed
+42
-2
No files matched your search
@@ -90,6 +90,10 @@ inputs:
|
|||||||
description: Require all commit messages to follow Conventional Commits format.
|
description: Require all commit messages to follow Conventional Commits format.
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
|
require-commit-author-match:
|
||||||
|
description: Require every commit in the PR to be authored by the same GitHub user who opened the PR.
|
||||||
|
required: false
|
||||||
|
default: "true"
|
||||||
blocked-commit-authors:
|
blocked-commit-authors:
|
||||||
description: Comma-separated list of blocked commit author usernames.
|
description: Comma-separated list of blocked commit author usernames.
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
+12
-1
@@ -16474,6 +16474,7 @@ let Input = /* @__PURE__ */ function(Input) {
|
|||||||
Input["BlockedTerms"] = "blocked-terms";
|
Input["BlockedTerms"] = "blocked-terms";
|
||||||
Input["BlockedIssueNumbers"] = "blocked-issue-numbers";
|
Input["BlockedIssueNumbers"] = "blocked-issue-numbers";
|
||||||
Input["RequireConventionalCommits"] = "require-conventional-commits";
|
Input["RequireConventionalCommits"] = "require-conventional-commits";
|
||||||
|
Input["RequireCommitAuthorMatch"] = "require-commit-author-match";
|
||||||
Input["BlockedCommitAuthors"] = "blocked-commit-authors";
|
Input["BlockedCommitAuthors"] = "blocked-commit-authors";
|
||||||
Input["AllowedFileExtensions"] = "allowed-file-extensions";
|
Input["AllowedFileExtensions"] = "allowed-file-extensions";
|
||||||
Input["AllowedPaths"] = "allowed-paths";
|
Input["AllowedPaths"] = "allowed-paths";
|
||||||
@@ -16539,6 +16540,7 @@ function getSettings() {
|
|||||||
blockedTerms: getMultilineInput(Input.BlockedTerms),
|
blockedTerms: getMultilineInput(Input.BlockedTerms),
|
||||||
blockedIssueNumbers: parseList(getInput(Input.BlockedIssueNumbers)),
|
blockedIssueNumbers: parseList(getInput(Input.BlockedIssueNumbers)),
|
||||||
requireConventionalCommits: getBooleanInput(Input.RequireConventionalCommits),
|
requireConventionalCommits: getBooleanInput(Input.RequireConventionalCommits),
|
||||||
|
requireCommitAuthorMatch: getBooleanInput(Input.RequireCommitAuthorMatch),
|
||||||
blockedCommitAuthors: parseList(getInput(Input.BlockedCommitAuthors)),
|
blockedCommitAuthors: parseList(getInput(Input.BlockedCommitAuthors)),
|
||||||
allowedFileExtensions: parseList(getInput(Input.AllowedFileExtensions)),
|
allowedFileExtensions: parseList(getInput(Input.AllowedFileExtensions)),
|
||||||
allowedPaths: getMultilineInput(Input.AllowedPaths),
|
allowedPaths: getMultilineInput(Input.AllowedPaths),
|
||||||
@@ -50707,7 +50709,7 @@ const CONVENTIONAL_PATTERN = /^(\w+)(?:\([^)]+\))?!?:\s.+/;
|
|||||||
const TITLE_PATTERN = /\(#\d+\)$/;
|
const TITLE_PATTERN = /\(#\d+\)$/;
|
||||||
async function runCommitChecks(settings, context, client) {
|
async function runCommitChecks(settings, context, client) {
|
||||||
const results = [];
|
const results = [];
|
||||||
if (!settings.requireConventionalCommits && settings.blockedCommitAuthors.length === 0) return results;
|
if (!settings.requireConventionalCommits && !settings.requireCommitAuthorMatch && settings.blockedCommitAuthors.length === 0) return results;
|
||||||
const commits = await client.paginate(client.rest.pulls.listCommits, {
|
const commits = await client.paginate(client.rest.pulls.listCommits, {
|
||||||
owner: context.owner,
|
owner: context.owner,
|
||||||
repo: context.repo,
|
repo: context.repo,
|
||||||
@@ -50722,6 +50724,15 @@ async function runCommitChecks(settings, context, client) {
|
|||||||
message: passed ? "All commit messages follow conventional commits format" : "Not all commit messages follow conventional commits format"
|
message: passed ? "All commit messages follow conventional commits format" : "Not all commit messages follow conventional commits format"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (settings.requireCommitAuthorMatch) {
|
||||||
|
const prAuthor = context.userLogin.toLowerCase();
|
||||||
|
const mismatchedAuthors = new Set(commits.map((commit) => commit.author?.login ?? "").filter((login) => login !== "" && login.toLowerCase() !== prAuthor));
|
||||||
|
recordCheck(results, {
|
||||||
|
name: "commit-author-match",
|
||||||
|
passed: mismatchedAuthors.size === 0,
|
||||||
|
message: mismatchedAuthors.size > 0 ? `Commit author(s) do not match PR author "${context.userLogin}": ${[...mismatchedAuthors].join(", ")}` : "All commit authors match the PR author"
|
||||||
|
});
|
||||||
|
}
|
||||||
if (settings.blockedCommitAuthors.length > 0) {
|
if (settings.blockedCommitAuthors.length > 0) {
|
||||||
const blockedAuthors = settings.blockedCommitAuthors.map((author) => author.toLowerCase());
|
const blockedAuthors = settings.blockedCommitAuthors.map((author) => author.toLowerCase());
|
||||||
const blocked = new Set(commits.map((commit) => (commit.author?.login ?? "").toLowerCase()).filter((login) => blockedAuthors.includes(login)));
|
const blocked = new Set(commits.map((commit) => (commit.author?.login ?? "").toLowerCase()).filter((login) => blockedAuthors.includes(login)));
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ export async function runCommitChecks(
|
|||||||
): Promise<CheckResult[]> {
|
): Promise<CheckResult[]> {
|
||||||
const results: CheckResult[] = [];
|
const results: CheckResult[] = [];
|
||||||
|
|
||||||
if (!settings.requireConventionalCommits && settings.blockedCommitAuthors.length === 0) {
|
if (
|
||||||
|
!settings.requireConventionalCommits &&
|
||||||
|
!settings.requireCommitAuthorMatch &&
|
||||||
|
settings.blockedCommitAuthors.length === 0
|
||||||
|
) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +45,24 @@ export async function runCommitChecks(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.requireCommitAuthorMatch) {
|
||||||
|
const prAuthor = context.userLogin.toLowerCase();
|
||||||
|
const mismatchedAuthors = new Set(
|
||||||
|
commits
|
||||||
|
.map((commit) => commit.author?.login ?? "")
|
||||||
|
.filter((login) => login !== "" && login.toLowerCase() !== prAuthor),
|
||||||
|
);
|
||||||
|
|
||||||
|
recordCheck(results, {
|
||||||
|
name: "commit-author-match",
|
||||||
|
passed: mismatchedAuthors.size === 0,
|
||||||
|
message:
|
||||||
|
mismatchedAuthors.size > 0
|
||||||
|
? `Commit author(s) do not match PR author "${context.userLogin}": ${[...mismatchedAuthors].join(", ")}`
|
||||||
|
: "All commit authors match the PR author",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.blockedCommitAuthors.length > 0) {
|
if (settings.blockedCommitAuthors.length > 0) {
|
||||||
const blockedAuthors = settings.blockedCommitAuthors.map((author) => author.toLowerCase());
|
const blockedAuthors = settings.blockedCommitAuthors.map((author) => author.toLowerCase());
|
||||||
const blocked = new Set(
|
const blocked = new Set(
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export enum Input {
|
|||||||
|
|
||||||
// Commit Message Checks
|
// Commit Message Checks
|
||||||
RequireConventionalCommits = "require-conventional-commits",
|
RequireConventionalCommits = "require-conventional-commits",
|
||||||
|
RequireCommitAuthorMatch = "require-commit-author-match",
|
||||||
BlockedCommitAuthors = "blocked-commit-authors",
|
BlockedCommitAuthors = "blocked-commit-authors",
|
||||||
|
|
||||||
// File Checks
|
// File Checks
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export function getSettings(): Settings {
|
|||||||
|
|
||||||
// Commit Message Checks
|
// Commit Message Checks
|
||||||
requireConventionalCommits: core.getBooleanInput(Input.RequireConventionalCommits),
|
requireConventionalCommits: core.getBooleanInput(Input.RequireConventionalCommits),
|
||||||
|
requireCommitAuthorMatch: core.getBooleanInput(Input.RequireCommitAuthorMatch),
|
||||||
blockedCommitAuthors: parseList(core.getInput(Input.BlockedCommitAuthors)),
|
blockedCommitAuthors: parseList(core.getInput(Input.BlockedCommitAuthors)),
|
||||||
|
|
||||||
// File Checks
|
// File Checks
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export interface Settings {
|
|||||||
|
|
||||||
// Commit Message Checks
|
// Commit Message Checks
|
||||||
requireConventionalCommits: boolean;
|
requireConventionalCommits: boolean;
|
||||||
|
requireCommitAuthorMatch: boolean;
|
||||||
blockedCommitAuthors: string[];
|
blockedCommitAuthors: string[];
|
||||||
|
|
||||||
// File Checks
|
// File Checks
|
||||||
|
|||||||
Reference in new issue
Block a user