Closed jsfour closed 1 year ago
@imwalterbot what do you think the best approach is here?
@imwalterbot what do you think the best approach is here?
Queued for processing...
@imwalterbot what do you think the best approach is here?
Processing this now
To update the hardcoded 'main' branch to the primary branch fetched from the GitHub API, you can follow these steps:
async function getPrimaryBranch(repository: Repository): Promise<string> {
const response = await octokit.rest.repos.get({
owner: repository.owner.login,
repo: repository.name,
});
return response.data.default_branch;
}
createNewPullRequest
function to fetch the primary branch before creating a pull request.export const createNewPullRequest = async (
result: psg.CodeEdit[],
repo: Repository,
issueNumber?: number
) => {
console.log("creating branch");
const primaryBranch = await getPrimaryBranch(repo);
const newBranch = await createBranch(repo, primaryBranch);
console.log("committing");
await commitCode(repo, newBranch, result);
console.log("creating pull request");
await createPullRequest(repo, newBranch, issueNumber, primaryBranch);
};
createBranch
function to accept the primary branch as a parameter.async function createBranch(
repository: Repository,
primaryBranch: string
): Promise<string> {
const baseBranch = await octokit.rest.git.getRef({
owner: repository.owner.login,
repo: repository.name,
ref: `heads/${primaryBranch}`,
});
const newBranchName = `bot-generated-code-${Date.now()}`;
await octokit.rest.git.createRef({
owner: repository.owner.login,
repo: repository.name,
ref: `refs/heads/${newBranchName}`,
sha: baseBranch.data.commit.sha,
});
return newBranchName;
}
With these changes, the primary branch will be fetched from the GitHub API and used instead of the hardcoded 'main' branch.
@imwalterbot APPROVED edits on https://github.com/octaviuslabs/walter/blob/main/src/code-committer.ts#L43
@imwalterbot APPROVED edits on https://github.com/octaviuslabs/walter/blob/main/src/code-committer.ts#L43
Queued for processing...
@imwalterbot APPROVED edits on https://github.com/octaviuslabs/walter/blob/main/src/code-committer.ts#L43
Processing this now
Right now we have the base branch hard coded to 'main' here: https://github.com/octaviuslabs/walter/blob/main/src/code-committer.ts#L43 when in reality we should be pulling the primary branch for the repo from the giithhub api.