Skip to content

Commit 1828498

Browse files
committed
feature-296-bugbot-autofix: Implement getTokenUserDetails method to retrieve GitHub user details for commit author configuration, enhancing bugbot autofix commit process with proper user attribution.
1 parent 9aefa54 commit 1828498

12 files changed

Lines changed: 89 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ web_modules/
131131

132132
*.lock
133133

134+
# OpenCode runtime (created/removed by action or CLI)
135+
opencode.json
136+
134137
.idea
135138

136139
.env

build/cli/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51379,6 +51379,16 @@ class ProjectRepository {
5137951379
const { data: user } = await octokit.rest.users.getAuthenticated();
5138051380
return user.login;
5138151381
};
51382+
/** Name and email of the token user, for git commit author (e.g. bugbot autofix). */
51383+
this.getTokenUserDetails = async (token) => {
51384+
const octokit = github.getOctokit(token);
51385+
const { data: user } = await octokit.rest.users.getAuthenticated();
51386+
const name = (user.name ?? user.login ?? "GitHub Action").trim() || "GitHub Action";
51387+
const email = (typeof user.email === "string" && user.email.trim().length > 0)
51388+
? user.email.trim()
51389+
: `${user.login}@users.noreply.github.com`;
51390+
return { name, email };
51391+
};
5138251392
this.findTag = async (owner, repo, tag, token) => {
5138351393
const octokit = github.getOctokit(token);
5138451394
try {
@@ -53743,6 +53753,7 @@ exports.SingleActionUseCase = SingleActionUseCase;
5374353753
/**
5374453754
* Runs verify commands and then git add/commit/push for bugbot autofix.
5374553755
* Uses @actions/exec; intended to run in the GitHub Action runner where the repo is checked out.
53756+
* Configures git user.name and user.email from the token user so the commit has a valid author.
5374653757
*/
5374753758
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5374853759
if (k2 === undefined) k2 = k;
@@ -53780,6 +53791,7 @@ var __importStar = (this && this.__importStar) || (function () {
5378053791
Object.defineProperty(exports, "__esModule", ({ value: true }));
5378153792
exports.runBugbotAutofixCommitAndPush = runBugbotAutofixCommitAndPush;
5378253793
const exec = __importStar(__nccwpck_require__(1514));
53794+
const project_repository_1 = __nccwpck_require__(7917);
5378353795
const logger_1 = __nccwpck_require__(8836);
5378453796
/**
5378553797
* Optionally check out the branch (when event is issue_comment and we resolved the branch from an open PR).
@@ -53867,6 +53879,11 @@ async function runBugbotAutofixCommitAndPush(execution, options) {
5386753879
return { success: true, committed: false };
5386853880
}
5386953881
try {
53882+
const projectRepository = new project_repository_1.ProjectRepository();
53883+
const { name, email } = await projectRepository.getTokenUserDetails(execution.tokens.token);
53884+
await exec.exec("git", ["config", "user.name", name]);
53885+
await exec.exec("git", ["config", "user.email", email]);
53886+
(0, logger_1.logDebugInfo)(`Git author set to ${name} <${email}>.`);
5387053887
await exec.exec("git", ["add", "-A"]);
5387153888
const commitMessage = "fix: bugbot autofix - resolve reported findings";
5387253889
await exec.exec("git", ["commit", "-m", commitMessage]);

build/cli/src/data/repository/project_repository.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export declare class ProjectRepository {
2121
getRandomMembers: (organization: string, membersToAdd: number, currentMembers: string[], token: string) => Promise<string[]>;
2222
getAllMembers: (organization: string, token: string) => Promise<string[]>;
2323
getUserFromToken: (token: string) => Promise<string>;
24+
/** Name and email of the token user, for git commit author (e.g. bugbot autofix). */
25+
getTokenUserDetails: (token: string) => Promise<{
26+
name: string;
27+
email: string;
28+
}>;
2429
private findTag;
2530
private getTagSHA;
2631
updateTag: (owner: string, repo: string, sourceTag: string, targetTag: string, token: string) => Promise<void>;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* Unit tests for runBugbotAutofixCommitAndPush: no branch, branchOverride checkout, verify commands, no changes, commit/push.
2+
* Unit tests for runBugbotAutofixCommitAndPush: no branch, branchOverride checkout, verify commands, no changes, commit/push, git author.
33
*/
44
export {};

build/cli/src/usecase/steps/commit/bugbot/bugbot_autofix_commit.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Runs verify commands and then git add/commit/push for bugbot autofix.
33
* Uses @actions/exec; intended to run in the GitHub Action runner where the repo is checked out.
4+
* Configures git user.name and user.email from the token user so the commit has a valid author.
45
*/
56
import type { Execution } from "../../../../data/model/execution";
67
export interface BugbotAutofixCommitResult {

build/github_action/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46470,6 +46470,16 @@ class ProjectRepository {
4647046470
const { data: user } = await octokit.rest.users.getAuthenticated();
4647146471
return user.login;
4647246472
};
46473+
/** Name and email of the token user, for git commit author (e.g. bugbot autofix). */
46474+
this.getTokenUserDetails = async (token) => {
46475+
const octokit = github.getOctokit(token);
46476+
const { data: user } = await octokit.rest.users.getAuthenticated();
46477+
const name = (user.name ?? user.login ?? "GitHub Action").trim() || "GitHub Action";
46478+
const email = (typeof user.email === "string" && user.email.trim().length > 0)
46479+
? user.email.trim()
46480+
: `${user.login}@users.noreply.github.com`;
46481+
return { name, email };
46482+
};
4647346483
this.findTag = async (owner, repo, tag, token) => {
4647446484
const octokit = github.getOctokit(token);
4647546485
try {
@@ -48834,6 +48844,7 @@ exports.SingleActionUseCase = SingleActionUseCase;
4883448844
/**
4883548845
* Runs verify commands and then git add/commit/push for bugbot autofix.
4883648846
* Uses @actions/exec; intended to run in the GitHub Action runner where the repo is checked out.
48847+
* Configures git user.name and user.email from the token user so the commit has a valid author.
4883748848
*/
4883848849
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4883948850
if (k2 === undefined) k2 = k;
@@ -48871,6 +48882,7 @@ var __importStar = (this && this.__importStar) || (function () {
4887148882
Object.defineProperty(exports, "__esModule", ({ value: true }));
4887248883
exports.runBugbotAutofixCommitAndPush = runBugbotAutofixCommitAndPush;
4887348884
const exec = __importStar(__nccwpck_require__(1514));
48885+
const project_repository_1 = __nccwpck_require__(7917);
4887448886
const logger_1 = __nccwpck_require__(8836);
4887548887
/**
4887648888
* Optionally check out the branch (when event is issue_comment and we resolved the branch from an open PR).
@@ -48958,6 +48970,11 @@ async function runBugbotAutofixCommitAndPush(execution, options) {
4895848970
return { success: true, committed: false };
4895948971
}
4896048972
try {
48973+
const projectRepository = new project_repository_1.ProjectRepository();
48974+
const { name, email } = await projectRepository.getTokenUserDetails(execution.tokens.token);
48975+
await exec.exec("git", ["config", "user.name", name]);
48976+
await exec.exec("git", ["config", "user.email", email]);
48977+
(0, logger_1.logDebugInfo)(`Git author set to ${name} <${email}>.`);
4896148978
await exec.exec("git", ["add", "-A"]);
4896248979
const commitMessage = "fix: bugbot autofix - resolve reported findings";
4896348980
await exec.exec("git", ["commit", "-m", commitMessage]);

build/github_action/src/data/repository/project_repository.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export declare class ProjectRepository {
2121
getRandomMembers: (organization: string, membersToAdd: number, currentMembers: string[], token: string) => Promise<string[]>;
2222
getAllMembers: (organization: string, token: string) => Promise<string[]>;
2323
getUserFromToken: (token: string) => Promise<string>;
24+
/** Name and email of the token user, for git commit author (e.g. bugbot autofix). */
25+
getTokenUserDetails: (token: string) => Promise<{
26+
name: string;
27+
email: string;
28+
}>;
2429
private findTag;
2530
private getTagSHA;
2631
updateTag: (owner: string, repo: string, sourceTag: string, targetTag: string, token: string) => Promise<void>;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* Unit tests for runBugbotAutofixCommitAndPush: no branch, branchOverride checkout, verify commands, no changes, commit/push.
2+
* Unit tests for runBugbotAutofixCommitAndPush: no branch, branchOverride checkout, verify commands, no changes, commit/push, git author.
33
*/
44
export {};

build/github_action/src/usecase/steps/commit/bugbot/bugbot_autofix_commit.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Runs verify commands and then git add/commit/push for bugbot autofix.
33
* Uses @actions/exec; intended to run in the GitHub Action runner where the repo is checked out.
4+
* Configures git user.name and user.email from the token user so the commit has a valid author.
45
*/
56
import type { Execution } from "../../../../data/model/execution";
67
export interface BugbotAutofixCommitResult {

src/data/repository/project_repository.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,19 @@ export class ProjectRepository {
558558
const octokit = github.getOctokit(token);
559559
const {data: user} = await octokit.rest.users.getAuthenticated();
560560
return user.login;
561-
}
561+
};
562+
563+
/** Name and email of the token user, for git commit author (e.g. bugbot autofix). */
564+
getTokenUserDetails = async (token: string): Promise<{ name: string; email: string }> => {
565+
const octokit = github.getOctokit(token);
566+
const { data: user } = await octokit.rest.users.getAuthenticated();
567+
const name = (user.name ?? user.login ?? "GitHub Action").trim() || "GitHub Action";
568+
const email =
569+
(typeof user.email === "string" && user.email.trim().length > 0)
570+
? user.email.trim()
571+
: `${user.login}@users.noreply.github.com`;
572+
return { name, email };
573+
};
562574

563575
private findTag = async (owner: string, repo: string, tag: string, token: string): Promise<{ object: { sha: string } } | undefined> => {
564576
const octokit = github.getOctokit(token);

0 commit comments

Comments
 (0)