Skip to content

Commit

Permalink
feat: add blocklist option
Browse files Browse the repository at this point in the history
Sometimes people will work around not providing a proper reproduction
by adding any GitHub link.

This new option lets you disallow some potentially invalid links
like a simple fork of an example.
  • Loading branch information
balazsorban44 committed Nov 29, 2023
1 parent 6114e48 commit eb4bf4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ inputs:
reproduction-hosts:
description: 'Comma-separated list of hostnames that are allowed for reproductions. Example: "github.com,codesandbox.io"'
default: github.com
reproduction-blocklist:
description: 'Comma-separated list of URLs that are not allowed for reproductions. They can be regular expression string. Example: "github.com/.*/fork-of-example"'
default: ''
reproduction-invalid-label:
description: 'Label to apply to issues without a valid reproduction. Example: "invalid-reproduction"'
default: 'invalid-reproduction'
Expand Down Expand Up @@ -64,6 +67,7 @@ runs:
"INPUT_LABEL_COMMENTS": ${{inputs.label-comments}}
"INPUT_REPRODUCTION_COMMENT": ${{inputs.reproduction-comment}}
"INPUT_REPRODUCTION_HOSTS": ${{inputs.reproduction-hosts}}
"INPUT_REPRODUCTION_BLOCKLIST": ${{inputs.reproduction-blocklist}}
"INPUT_REPRODUCTION_INVALID_LABEL": ${{inputs.reproduction-invalid-label}}
"INPUT_REPRODUCTION_ISSUE_LABELS": ${{inputs.reproduction-issue-labels}}
"INPUT_REPRODUCTION_LINK_SECTION": ${{inputs.reproduction-link-section}}
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const config = {
hosts: (getInput("reproduction_hosts") || "github.com")
.split(",")
.map((h) => h.trim()),
blocklist: (getInput("reproduction_blocklist") || "")
.split(",")
.map((h) => new RegExp(h.trim())),
label: getInput("reproduction_invalid_label") || "invalid-reproduction",
linkSection:
getInput("reproduction_link_section") ||
Expand Down Expand Up @@ -121,7 +124,9 @@ async function checkValidReproduction() {
}

/**
* Determine if an issue contains a valid/accessible link to a reproduction
* Determine if an issue contains a valid/accessible link to a reproduction.
*
* Returns `true` if the link is valid.
* @param {string} body
*/
async function isValidReproduction(body) {
Expand All @@ -140,6 +145,9 @@ async function isValidReproduction(body) {
if (!config.invalidLink.hosts.includes(url.hostname))
return info("Link did not match allowed reproduction hosts")

if (config.invalidLink.blocklist.some((r) => r.test(link)))
return info("Link matched blocklist for reproduction URLs")

try {
// Verify that the link can be opened
// We allow 500, in case it's a downtime
Expand Down

0 comments on commit eb4bf4b

Please sign in to comment.