Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maskaravivek/441c6ad6790fd46d4af5be08ac018f9a to your computer and use it in GitHub Desktop.
Save maskaravivek/441c6ad6790fd46d4af5be08ac018f9a to your computer and use it in GitHub Desktop.
const createGithubCommit = async (
githubAccessToken,
repoFullName,
branchName,
commitMessage,
articleFiles
) => {
const tree = await createGithubRepoTree(
githubAccessToken,
repoFullName,
branchName,
articleFiles
);
const parentSha = await getParentSha(
githubAccessToken,
repoFullName,
branchName
);
const payload = {
message: commitMessage,
tree: tree,
parents: [parentSha],
};
const response = await fetch(
`https://api.github.com/repos/${repoFullName}/git/commits`,
{
method: "POST",
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${githubAccessToken}`,
"X-GitHub-Api-Version": "2022-11-28",
},
body: JSON.stringify(payload),
}
);
const commitResp = await response.json();
const commitSha = commitResp.sha;
await updateGithubBranchRef(
githubAccessToken,
repoFullName,
branchName,
commitSha
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment