diff --git a/src/github.ts b/src/github.ts index 54553463..20444d49 100644 --- a/src/github.ts +++ b/src/github.ts @@ -97,6 +97,31 @@ export class GitHub { if (this.commitMode === "github-api") { return; } + // Check the exact identities that Git would use for commits without + // allowing Git to fall back to auto-detected values like user@hostname. + // This covers explicit GIT_AUTHOR_* / GIT_COMMITTER_* env vars, local + // config, and global config. A partial identity, with only a name or only + // an email, does not pass this check. If either identity is missing, set + // our default bot user so CLI commits don't fail or use host-derived data. + const authorIdentity = await getExecOutput( + "git", + ["-c", "user.useConfigOnly=true", "var", "GIT_AUTHOR_IDENT"], + { + cwd: this.cwd, + ignoreReturnCode: true, + }, + ); + const committerIdentity = await getExecOutput( + "git", + ["-c", "user.useConfigOnly=true", "var", "GIT_COMMITTER_IDENT"], + { + cwd: this.cwd, + ignoreReturnCode: true, + }, + ); + if (authorIdentity.exitCode === 0 && committerIdentity.exitCode === 0) { + return; + } await exec("git", ["config", "user.name", `"github-actions[bot]"`], { cwd: this.cwd, });