grep-tests-from-pull-requests
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -62,3 +62,4 @@ #!/usr/bin/env node | ||
console.log(body) | ||
const testsToRun = getTestsToRun(['@log', '@sanity'], body) | ||
const prComments = [] | ||
const testsToRun = getTestsToRun(['@log', '@sanity'], body, prComments) | ||
console.log('tests to run') | ||
@@ -65,0 +66,0 @@ console.log(testsToRun) |
{ | ||
"name": "grep-tests-from-pull-requests", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Grabs the test tags to run from the pull request text", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -59,3 +59,3 @@ # grep-tests-from-pull-requests | ||
If the pull request text has a line with just `baseUrl <URL>` the it will be extracted too. This makes it convenient to specify a custom deploy to be tested for this specific pull request. | ||
If the pull request text OR its comments have a line with just `baseUrl <URL>` the it will be extracted too. This makes it convenient to specify a custom deploy to be tested for this specific pull request. | ||
@@ -70,2 +70,11 @@ ```text | ||
The base URL is found if it is a single line of text in the pull request body or its comment in one of these formats: | ||
```text | ||
baseUrl https://preview-1.acme.co | ||
TestURL: https://preview-1.acme.co | ||
``` | ||
If the URL is present in the body and in several comments, the URL found in the latest comment wins. | ||
**Tip:** you can control if you want to set the baseUrl based on the pull request text using an option | ||
@@ -72,0 +81,0 @@ |
@@ -6,2 +6,3 @@ /// <reference types="cypress" /> | ||
getPullRequestBody, | ||
getPullRequestComments, | ||
getTestsToRun, | ||
@@ -64,3 +65,4 @@ getPullRequestNumber, | ||
const prBody = await getPullRequestBody(prOptions, envOptions) | ||
const testsToRun = getTestsToRun(options.tags, prBody) | ||
const prComments = await getPullRequestComments(prOptions, envOptions) | ||
const testsToRun = getTestsToRun(options.tags, prBody, prComments) | ||
console.log('tests to run', testsToRun) | ||
@@ -67,0 +69,0 @@ if (testsToRun) { |
@@ -17,2 +17,21 @@ // @ts-check | ||
/** | ||
* Finds and returns the test (base URL) in the given text line, if present. | ||
* @param {string} line a single line of text | ||
*/ | ||
function getBaseUrlFromTextLine(line) { | ||
// if the line is in the form of | ||
// baseUlr <url> | ||
if (line.includes('baseUrl')) { | ||
return line.split('baseUrl')[1].trim() | ||
} | ||
// if the line is in the frm of | ||
// Test URL: <url> | ||
if (line.match(/^\s*Test URL:/)) { | ||
return line.split('Test URL:')[1].trim() | ||
} | ||
// did not find the base url | ||
} | ||
// assume we do need to authenticate to fetch the pull request body | ||
@@ -52,2 +71,7 @@ async function getPullRequestBody(options, envOptions) { | ||
/** | ||
* @typedef {object} PullRequestComment | ||
* @property {string} body The text of the comment | ||
*/ | ||
/** | ||
* Return the list of comments on a specific pull request. The last | ||
@@ -57,2 +81,3 @@ * commit is the latest commit. Each returned comment is an object | ||
* assume we do need to authenticate to fetch the pull request body | ||
* @returns {Promise<PullRequestComment[]>} List of comments. | ||
*/ | ||
@@ -88,2 +113,3 @@ async function getPullRequestComments(options, envOptions) { | ||
const comments = JSON.parse(res.body) | ||
debug('found %d comments for PR %d', comments.length, options.pull) | ||
// each comment in the array is an object with a body property | ||
@@ -100,4 +126,5 @@ return comments | ||
* @param {string} pullRequestBody The pull request text with checkboxes | ||
* @param {PullRequestComment[]} pullRequestComments The pull request comments | ||
*/ | ||
function getTestsToRun(tagsToLookFor, pullRequestBody) { | ||
function getTestsToRun(tagsToLookFor, pullRequestBody, pullRequestComments) { | ||
const testsToRun = { | ||
@@ -122,5 +149,3 @@ all: false, | ||
if (line.includes('baseUrl')) { | ||
testsToRun.baseUrl = line.split('baseUrl')[1].trim() | ||
} | ||
testsToRun.baseUrl = getBaseUrlFromTextLine(line) | ||
@@ -133,2 +158,11 @@ tagsToLookFor.forEach((tag) => { | ||
}) | ||
// pull requests can overwrite the base url | ||
pullRequestComments.forEach((comment) => { | ||
const commentLines = comment.body.split('\n') | ||
commentLines.forEach((line) => { | ||
testsToRun.baseUrl = getBaseUrlFromTextLine(line) | ||
}) | ||
}) | ||
return testsToRun | ||
@@ -135,0 +169,0 @@ } |
19652
416
174