From f8cf63cbc3aa1181030e566027e5da762bb42417 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 21 May 2021 10:31:55 -0400 Subject: [PATCH 1/2] Add GitHub action to check for bug repro This action can be tested at https://github.com/bvaughn/test-github-issue-template --- .github/workflows/devtools_check_repro.yml | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 .github/workflows/devtools_check_repro.yml diff --git a/.github/workflows/devtools_check_repro.yml b/.github/workflows/devtools_check_repro.yml new file mode 100644 index 00000000000..f4d8e04f6c7 --- /dev/null +++ b/.github/workflows/devtools_check_repro.yml @@ -0,0 +1,127 @@ +name: DevTools Check for bug repro +on: + issues: + types: [opened, edited] + issue_comment: + types: [created, edited] + +jobs: + check-repro: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const user = context.payload.sender.login; + const body = context.payload.comment + ? context.payload.comment.body + : context.payload.issue.body; + + function debug(...args) { + core.info(args.map(JSON.stringify).join(' ')); + } + + const URL_REGEXP = /### Website or app[\r\n]+([^#]+)###/m; + const REPRO_STEPS_REGEXP = /### Repro steps[\r\n]+([^#]+)###/m; + + const urlMatch = body.match(URL_REGEXP); + const reproStepsMatch = body.match(REPRO_STEPS_REGEXP); + + const url = urlMatch !== null ? urlMatch[1].trim() : null; + const reproSteps = reproStepsMatch !== null ? reproStepsMatch[1].trim() : null; + + if (!url || !reproSteps) { + debug('This issue is not a DevTools bug report.'); + return; + } + + debug(`found URL "${url}"`); + debug(`found repro steps "${reproSteps}"`); + + const PROBABLY_NOT_A_URL_REGEX = /(^Chrome$|^Firefox$| Website)/i; + + const COMMENT_HEADER = ` + @${user}: We're sorry you've seen this error. ❤️ + `.trim(); + + const COMMENT_FOOTER = ` + Please help us by providing a link to a CodeSandbox (https://codesandbox.io/s/new), a repository on GitHub, or a minimal code example that reproduces the problem. (Screenshots or videos can also be helpful if they help provide context on how to repro the bug.) + + Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve + + Issues without repros are automatically closed but we will re-open if you update with repro info. + `.trim(); + + let commentToAdd = null; + + if (url.includes("/localhost")) { + commentToAdd = ` + ${COMMENT_HEADER} + + Unfortunately the URL you provided ("localhost") is not publicly accessible. (This means that we will not be able to reproduce the problem you're reporting.) + + ${COMMENT_FOOTER} + `; + } else if (url.length < 10 || url.match(PROBABLY_NOT_A_URL_REGEX)) { + commentToAdd = ` + ${COMMENT_HEADER} + + It looks like you forgot to specify a valid URL. (This means that we will not be able to reproduce the problem you're reporting.) + + ${COMMENT_FOOTER} + `; + } else if (reproSteps.length < 25) { + commentToAdd = ` + ${COMMENT_HEADER} + + Unfortunately, it doesn't look like this issue has enough info for one of us to reproduce and fix it though. + + ${COMMENT_FOOTER} + `; + } + + debug(`Missing required information? ${!!commentToAdd}`); + + if (commentToAdd !== null) { + const comments = await github.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + debug(`Searching ${comments.data.length} existing comments...`); + + if (comments.data.some(comment => { + debug(`comment by user: "${comment.user.login}"`); + + return comment.user.login === 'github-actions[bot]'; + })) { + return; + } + + await github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentToAdd + .split("\n") + .map((line) => line.trim()) + .join("\n") + .trim(), + }); + + await github.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ["Resolution: Needs More Information"], + }); + + await github.issues.update({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + state: 'closed', + }); + } From e877b592ad14a4ec03a3c9eda35db814e537e423 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 21 May 2021 13:52:07 -0400 Subject: [PATCH 2/2] Tweaked DevTools bug report Workflow --- .github/workflows/devtools_check_repro.yml | 190 +++++++++++++++------ 1 file changed, 136 insertions(+), 54 deletions(-) diff --git a/.github/workflows/devtools_check_repro.yml b/.github/workflows/devtools_check_repro.yml index f4d8e04f6c7..0a32ff691f7 100644 --- a/.github/workflows/devtools_check_repro.yml +++ b/.github/workflows/devtools_check_repro.yml @@ -13,17 +13,23 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const user = context.payload.sender.login; - const body = context.payload.comment - ? context.payload.comment.body - : context.payload.issue.body; + const URL_REGEXP = /### Website or app[\r\n]+([^#]+)###/m; + const REPRO_STEPS_REGEXP = /### Repro steps[\r\n]+([^#]+)###/m; + const LABEL_NEEDS_MORE_INFORMATION = "Resolution: Needs More Information"; + const LABEL_UNCONFIRMED = "Status: Unconfirmed"; function debug(...args) { core.info(args.map(JSON.stringify).join(' ')); } - const URL_REGEXP = /### Website or app[\r\n]+([^#]+)###/m; - const REPRO_STEPS_REGEXP = /### Repro steps[\r\n]+([^#]+)###/m; + if (context.payload.comment) { + debug('Ignoring comment update.'); + return; + } + + const user = context.payload.sender.login; + const issue = context.payload.issue; + const body = issue.body; const urlMatch = body.match(URL_REGEXP); const reproStepsMatch = body.match(REPRO_STEPS_REGEXP); @@ -39,89 +45,165 @@ jobs: debug(`found URL "${url}"`); debug(`found repro steps "${reproSteps}"`); - const PROBABLY_NOT_A_URL_REGEX = /(^Chrome$|^Firefox$| Website)/i; - - const COMMENT_HEADER = ` - @${user}: We're sorry you've seen this error. ❤️ - `.trim(); - - const COMMENT_FOOTER = ` - Please help us by providing a link to a CodeSandbox (https://codesandbox.io/s/new), a repository on GitHub, or a minimal code example that reproduces the problem. (Screenshots or videos can also be helpful if they help provide context on how to repro the bug.) + function formatComment(comment) { + return comment + .split("\n") + .map((line) => line.trim()) + .join("\n") + .trim(); + } - Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve + async function getGitHubActionComments() { + debug(`Loading existing comments...`); - Issues without repros are automatically closed but we will re-open if you update with repro info. - `.trim(); + const comments = await github.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); - let commentToAdd = null; + return comments.data.filter(comment => { + debug(`comment by user: "${comment.user.login}"`); + return comment.user.login === 'github-actions[bot]'; + }); + } - if (url.includes("/localhost")) { - commentToAdd = ` - ${COMMENT_HEADER} + async function getIssueLabels() { + const issues = await github.issues.listLabelsOnIssue({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); - Unfortunately the URL you provided ("localhost") is not publicly accessible. (This means that we will not be able to reproduce the problem you're reporting.) + return issues.data; + } - ${COMMENT_FOOTER} - `; - } else if (url.length < 10 || url.match(PROBABLY_NOT_A_URL_REGEX)) { - commentToAdd = ` - ${COMMENT_HEADER} + async function closeWithComment(comment) { + if (issue.state !== 'open') { + debug(`Issue is not open`); + return; + } - It looks like you forgot to specify a valid URL. (This means that we will not be able to reproduce the problem you're reporting.) + const labels = await getIssueLabels(); + const label = labels.find(label => label.name === LABEL_UNCONFIRMED); + if (!label) { + debug(`Issue was not opened via DevTools bug report template`); + return; + } - ${COMMENT_FOOTER} - `; - } else if (reproSteps.length < 25) { - commentToAdd = ` - ${COMMENT_HEADER} + const comments = await getGitHubActionComments(); + if (comments.length > 0) { + debug(`Already commented on issue; won't comment again`); + return; + } - Unfortunately, it doesn't look like this issue has enough info for one of us to reproduce and fix it though. + debug(`Missing required information`); - ${COMMENT_FOOTER} - `; - } + await github.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: [LABEL_NEEDS_MORE_INFORMATION], + }); - debug(`Missing required information? ${!!commentToAdd}`); + await github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: formatComment(comment), + }); - if (commentToAdd !== null) { - const comments = await github.issues.listComments({ + await github.issues.update({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, + state: 'closed', }); + } - debug(`Searching ${comments.data.length} existing comments...`); + async function openWithComment(comment) { + if (issue.state !== 'closed') { + debug(`Issue is already open`); + return; + } - if (comments.data.some(comment => { - debug(`comment by user: "${comment.user.login}"`); + const labels = await getIssueLabels(); + const label = labels.find(label => label.name === LABEL_NEEDS_MORE_INFORMATION); + if (!label) { + debug(`Issue was not tagged as needs information`); + return; + } - return comment.user.login === 'github-actions[bot]'; - })) { + const comments = await getGitHubActionComments(); + if (comments.length === 0) { + debug(`Issue was closed by someone else; won't reopen`); return; } - await github.issues.createComment({ + debug(`Re-opening closed issue`); + + await github.issues.removeLabel({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: commentToAdd - .split("\n") - .map((line) => line.trim()) - .join("\n") - .trim(), + name: LABEL_NEEDS_MORE_INFORMATION, }); - await github.issues.addLabels({ + await github.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - labels: ["Resolution: Needs More Information"], + body: formatComment(comment), }); await github.issues.update({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - state: 'closed', + state: 'open', }); } + + const PROBABLY_NOT_A_URL_REGEX = /(^Chrome$|^Firefox$| Website)/i; + + const COMMENT_HEADER = ` + @${user}: We're sorry you've seen this error. ❤️ + `.trim(); + + const COMMENT_FOOTER = ` + Please help us by providing a link to a CodeSandbox (https://codesandbox.io/s/new), a repository on GitHub, or a minimal code example that reproduces the problem. (Screenshots or videos can also be helpful if they help provide context on how to repro the bug.) + + Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve + + Issues without repros are automatically closed but we will re-open if you update with repro info. + `.trim(); + + if (url.includes("/localhost")) { + closeWithComment(` + ${COMMENT_HEADER} + + Unfortunately the URL you provided ("localhost") is not publicly accessible. (This means that we will not be able to reproduce the problem you're reporting.) + + ${COMMENT_FOOTER} + `); + } else if (url.length < 10 || url.match(PROBABLY_NOT_A_URL_REGEX)) { + closeWithComment(` + ${COMMENT_HEADER} + + It looks like you forgot to specify a valid URL. (This means that we will not be able to reproduce the problem you're reporting.) + + ${COMMENT_FOOTER} + `); + } else if (reproSteps.length < 25) { + closeWithComment(` + ${COMMENT_HEADER} + + Unfortunately, it doesn't look like this issue has enough info for one of us to reproduce and fix it though. + + ${COMMENT_FOOTER} + `); + } else { + openWithComment(` + Thank you for providing repro steps! Re-opening issue now for triage. + `); + }