Created
July 15, 2023 07:30
-
-
Save maskaravivek/441c6ad6790fd46d4af5be08ac018f9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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