Skip to content

Instantly share code, notes, and snippets.

@saggie
Created July 19, 2023 20:07
Show Gist options
  • Save saggie/4f1309641caeafb934079f422bca20e1 to your computer and use it in GitHub Desktop.
Save saggie/4f1309641caeafb934079f422bca20e1 to your computer and use it in GitHub Desktop.
Get a list of pull request comments
import { Octokit } from "@octokit/rest"; // Required: `npm install @octokit/rest --save`
const octokit = new Octokit({
auth: "github_pat_xxxxx", // Specify your personal access token here
});
const response = await octokit.request(
"GET /repos/__OWNER__/__REPO__/pulls/comments",
{
owner: "__OWNER__",
repo: "__REPO__",
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
}
);
const result = response.data
.map((it) => {
// Extract attributes
return {
user: it.user.login,
body: it.body,
url: it.html_url,
};
})
.filter((it) => it.user === "saggie"); // Filer by user
console.log(JSON.stringify(result));
// [
// {
// "user":"saggie",
// "body":"Moi!",
// "url":"https://github.com/__OWNER__/__REPO__/pull/1#discussion_r1234567890"
// },
// ...
// ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment