export async function createChangeBranch()

in eng/copilot/octokitFunctions.js [74:103]


export async function createChangeBranch(owner, repo, mainSha, originSha) {
    try {
        const { data } = await octokit.rest.git.getRef({
            owner,
            repo,
            ref: `refs/${branchRef}${originSha}`,
        });
        console.log("Branch already exists, using existing branch SHA:", data.object.sha);
        return data.object.sha;
    } catch (error) {
        if (error.status === 404) {
            try {
                const { data: newData } = await octokit.rest.git.createRef({
                    owner,
                    repo,
                    ref: `refs/${branchRef}`,
                    mainSha,
                });
                console.log("Branch auto-generated-integration-test created successfully, new branch SHA:", newData.object.sha);
                return newData.object.sha;
            } catch (error) {
                console.error("Failed to create branch:", error.message);
                throw error;
            }
        } else {
            console.error("Failed to check branch existence:", error.message);
            throw error;
        }
    }
}