Skip to content

Commit dbc0e1b

Browse files
committed
Update close-invalid-link.cjs
1 parent a42eb45 commit dbc0e1b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

.github/scripts/close-invalid-link.cjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ async function closeIssue(github, owner, repo, number) {
1717
owner: owner,
1818
repo: repo,
1919
issue_number: number,
20-
body: 'Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node)'
20+
body: "Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node)"
2121
});
2222
await github.rest.issues.update({
2323
owner: owner,
2424
repo: repo,
2525
issue_number: number,
26-
state: 'closed'
26+
state: "closed"
2727
});
2828
}
29-
module.exports = async ({github, context}) => {
29+
module.exports = async ({ github, context }) => {
3030
const owner = context.repo.owner;
3131
const repo = context.repo.repo;
3232
const number = context.issue.number;
@@ -37,12 +37,15 @@ module.exports = async ({github, context}) => {
3737
issue_number: number,
3838
});
3939

40-
const isBugTemplate = issue.data.body.includes('Link to the code that reproduces this issue');
40+
const isBugTemplate = issue.data.body.includes("Link to the code that reproduces this issue");
4141

4242
if (isBugTemplate) {
43+
console.log(`Issue ${number} is a bug template`)
4344
try {
44-
const link = issue.data.body.split('\n')[18].match(/(https?:\/\/g?i?s?t?\.?github.com\/.*)/);
45+
const link = issue.data.body.split("\n")[18].match(/(https?:\/\/(gist\.)?github.com\/.*)/)[0];
46+
console.log(`Issue ${number} contains this link: ${link}`)
4547
const isValidLink = (await fetch(link)).ok;
48+
console.log(`Issue ${number} has a ${isValidLink ? "valid" : "invalid"} link`)
4649
if (!isValidLink) {
4750
await closeIssue(github, owner, repo, number);
4851
}

0 commit comments

Comments
 (0)