Created
August 20, 2019 09:11
-
-
Save dmail/18b626c74b7996d0d98c59d44993376b to your computer and use it in GitHub Desktop.
commentGithubPullRequest
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
// 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