Skip to content

Commit

Permalink
updated to look at markdown links
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsdennis committed Feb 28, 2021
1 parent d562bfa commit 7b79f67
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/self-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [pull_request]
on: [pull_request, workflow_dispatch]

jobs:
self_test_job:
Expand Down
38 changes: 28 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
const core = require('@actions/core');
const github = require('@actions/github');

const keyPhrases = 'depends on|blocked by';
const plainTextRegex = new RegExp(`(${keyPhrases}) #(\d+)`, 'gmi');
const markdownRegex = new RegExp(`(${keyPhrases}) \[.*\]\((.*\/\d+)\)`, 'gmi');
const prRegex = /https:\/\/github\.com\/(\w+)\/([-._a-z0-9]+)\/pull\/(\d+)/gmi

function getDependency(line) {
var rx = /(depends on|blocked by) #(\d+)/gmi;
var match = rx.exec(line);
if (match !== null)
return parseInt(match[2], 10);
var match = plainTextRegex.exec(line);
if (match !== null) {
return {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: parseInt(match[2], 10)
};
}

match = plainTextRegex.exec(line);
if (match !== null) {
var url = match[3];
match = prRegex.exec(url);
return {
owner: match[1],
repo: match[2],
pull_number: parseInt(match[3], 10)
};
}

return null;
};

Expand All @@ -31,12 +52,9 @@ async function run() {

var dependencyPullRequests = [];
for (var d of dependencies) {
core.info(`Fetching '${github.context.repo.owner}/${github.context.repo.repo}/pulls/${d}'`)
const { data: pr } = await octokit.pulls.get({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: d,
}).catch(error => core.error(error));
core.info(`Fetching '${d}'`)
const { data: pr } = await octokit.pulls.get(d).catch(error => core.error(error));
if (!pr) continue;
if (!pr.merged && !pr.closed_at)
dependencyPullRequests.push(pr);
}
Expand Down

0 comments on commit 7b79f67

Please sign in to comment.