grep-tests-from-pull-requests
Advanced tools
Comparing version 1.5.0 to 1.6.0
{ | ||
"name": "grep-tests-from-pull-requests", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Grabs the test tags to run from the pull request text", | ||
@@ -15,3 +15,4 @@ "main": "src/index.js", | ||
"alias": { | ||
"get-pr-body": "./bin/get-pr-body.js" | ||
"get-pr-body": "./bin/get-pr-body.js", | ||
"get-pr-comments": "./bin/get-pr-comments.js" | ||
}, | ||
@@ -18,0 +19,0 @@ "repository": { |
@@ -101,2 +101,22 @@ # grep-tests-from-pull-requests | ||
## Aliases | ||
This package includes several scripts that let you find the pull request body and the test tags and the base URL of a given pull request. | ||
### get-pr-body | ||
Prints the test tags found in the pull request text | ||
``` | ||
$ npx get-pr-body --owner bahmutov --repo todomvc-no-tests-vercel --pull 12 | ||
``` | ||
### get-pr-comments | ||
Prints all pull request comments | ||
``` | ||
$ npx get-pr-comments --owner bahmutov --repo todomvc-no-tests-vercel --pull 12 | ||
``` | ||
## Debugging | ||
@@ -103,0 +123,0 @@ |
@@ -50,2 +50,41 @@ // @ts-check | ||
/** | ||
* Return the list of comments on a specific pull request. The last | ||
* commit is the latest commit. Each returned comment is an object | ||
* with "body", and other properties. | ||
* assume we do need to authenticate to fetch the pull request body | ||
*/ | ||
async function getPullRequestComments(options, envOptions) { | ||
if (options.token) { | ||
console.error('you have accidentally included the token in the options') | ||
console.error('please use the second environment options object instead') | ||
delete options.token | ||
} | ||
debug('getting pull request comments: %o', options) | ||
validateCommonOptions(options, envOptions) | ||
if (!options.pull) { | ||
throw new Error('options.pull number is required') | ||
} | ||
// https://docs.github.com/en/rest/reference/pulls#get-a-pull-request | ||
// https://api.github.com/repos/bahmutov/todomvc-no-tests-vercel/issues/10/comments | ||
const url = `https://api.github.com/repos/${options.owner}/${options.repo}/issues/${options.pull}/comments` | ||
debug('url: %s', url) | ||
// @ts-ignore | ||
const res = await got.get(url, { | ||
headers: { | ||
authorization: `Bearer ${envOptions.token}`, | ||
accept: 'application/vnd.github.v3+json', | ||
}, | ||
}) | ||
const comments = JSON.parse(res.body) | ||
// each comment in the array is an object with a body property | ||
return comments | ||
} | ||
function isLineChecked(line) { | ||
@@ -165,2 +204,3 @@ return line.includes('[x]') | ||
getPullRequestBody, | ||
getPullRequestComments, | ||
getTestsToRun, | ||
@@ -167,0 +207,0 @@ getPullRequestForHeadCommit, |
18164
6
384
165
7