fix: attribute conflict commits to app bot
This commit is contained in:
1 parent
351d3148aa
commit
5a00aa48b6
2 files changed
+50
-7
No files matched your search
@@ -136,14 +136,11 @@ export async function resolvePullRequestConflicts(
|
||||
return false;
|
||||
}
|
||||
|
||||
await runCommand("git", ["config", "user.name", config.botName], worktree, gitEnv);
|
||||
const botCommitIdentity = await resolveBotCommitIdentity(octokit, config.botName);
|
||||
await runCommand("git", ["config", "user.name", botCommitIdentity.name], worktree, gitEnv);
|
||||
await runCommand(
|
||||
"git",
|
||||
[
|
||||
"config",
|
||||
"user.email",
|
||||
`${config.githubAppId ?? "41898282"}+${config.botName}@users.noreply.github.com`
|
||||
],
|
||||
["config", "user.email", botCommitIdentity.email],
|
||||
worktree,
|
||||
gitEnv
|
||||
);
|
||||
@@ -451,6 +448,26 @@ export async function resolvePullRequestConflicts(
|
||||
}
|
||||
}
|
||||
|
||||
export async function resolveBotCommitIdentity(
|
||||
octokit: Octokit,
|
||||
configuredBotName: string
|
||||
): Promise<{ name: string; email: string }> {
|
||||
const username = configuredBotName.trim().replace(/^@/, "");
|
||||
if (!username) {
|
||||
throw new Error("The configured bot name cannot be used as a GitHub commit identity.");
|
||||
}
|
||||
|
||||
const { data: botUser } = await octokit.rest.users.getByUsername({ username });
|
||||
if (!Number.isSafeInteger(botUser.id) || botUser.id <= 0 || !botUser.login) {
|
||||
throw new Error("GitHub returned an invalid bot user identity for conflict-resolution commits.");
|
||||
}
|
||||
|
||||
return {
|
||||
name: botUser.login,
|
||||
email: `${botUser.id}+${botUser.login}@users.noreply.github.com`
|
||||
};
|
||||
}
|
||||
|
||||
export function buildConflictPushArgs(params: {
|
||||
baseRepository: string;
|
||||
headRepository: string;
|
||||
|
||||
@@ -12,7 +12,8 @@ import {
|
||||
isValidationInfrastructureFailure,
|
||||
parseDiffCheckWhitespaceDiagnostics,
|
||||
parseFinalConfirmation,
|
||||
repairDiffCheckContent
|
||||
repairDiffCheckContent,
|
||||
resolveBotCommitIdentity
|
||||
} from "../src/review/conflictResolver.js";
|
||||
|
||||
const eligible = {
|
||||
@@ -198,6 +199,31 @@ test("external fork conflict pushes use a head-SHA force lease", () => {
|
||||
}), /Unsafe PR head branch/);
|
||||
});
|
||||
|
||||
test("conflict commits use the GitHub bot user id for avatar attribution", async () => {
|
||||
const requestedUsernames: string[] = [];
|
||||
const identity = await resolveBotCommitIdentity({
|
||||
rest: {
|
||||
users: {
|
||||
async getByUsername({ username }: { username: string }) {
|
||||
requestedUsernames.push(username);
|
||||
return {
|
||||
data: {
|
||||
id: 316580078,
|
||||
login: "forumlify[bot]"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} as never, "@forumlify[bot]");
|
||||
|
||||
assert.deepEqual(requestedUsernames, ["forumlify[bot]"]);
|
||||
assert.deepEqual(identity, {
|
||||
name: "forumlify[bot]",
|
||||
email: "316580078+forumlify[bot]@users.noreply.github.com"
|
||||
});
|
||||
});
|
||||
|
||||
test("snapshot inventory detects related file additions, changes, and deletions", () => {
|
||||
const before = new Map([
|
||||
["conflicted.ts", { hash: "old", size: 10 }],
|
||||
|
||||
Reference in new issue
Block a user