Skip to content

Instantly share code, notes, and snippets.

@dmail
Created August 20, 2019 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmail/18b626c74b7996d0d98c59d44993376b to your computer and use it in GitHub Desktop.
Save dmail/18b626c74b7996d0d98c59d44993376b to your computer and use it in GitHub Desktop.
commentGithubPullRequest
// https://developer.github.com/v3/issues/comments/#create-a-comment
// https://developer.github.com/v3/issues/comments/#edit-a-comment
const fetch = require("node-fetch")
const commentGithubPullRequest = async ({
token,
repoOwner,
repoName,
issueNumber,
commentBody,
}) => {
try {
const body = JSON.stringify({ body: commentBody })
const response = await fetch(
`https://api.github.com/repos/${repoOwner}/${repoName}/issues/${issueNumber}/comments`,
{
headers: {
authorization: `token ${token}`,
"content-length": Buffer.byteLength(body),
},
method: "POST",
body,
},
)
const status = response.status
if (status !== 201) {
const responseBodyAsJSON = await response.json()
console.log({
status,
responseBodyAsJSON,
})
}
} catch (e) {
throw e
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment