Skip to content

Create post-an-open-role.md #18

Create post-an-open-role.md

Create post-an-open-role.md #18

Workflow file for this run

name: Compliance
on:
pull_request_target:
types:
- opened
- edited
- synchronize
- reopened
- unassigned
jobs:
check-for-linked-issue:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check for keyword and issue number
id: check-for-keyword
uses: actions/github-script@v7
with:
script: |
// Retrieve body of context.payload and search for GitHub keywords
const prBody = context.payload.pull_request.body;
const prNumber = context.payload.pull_request.number;
const prOwner = context.payload.pull_request.user.login;
const regex = /(?<!Example:\s*)(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+#(\d+)/i;
const match = prBody.match(regex);
let prComment;
if (!match) {
console.log('PR does not have a properly linked issue. Posting comment...');
prComment = `@${prOwner}, this Pull Request is not linked to a valid issue. Please provide a valid linked issue in "Related Issues" above, using the format of "Resolves #" + issue number.`;
}
else {
let [ , keyword, linkNumber ] = match;
console.log('Found a keyword: \'' + keyword + '\'. Checking for legitimate linked issue...');
try {
const response = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: linkNumber,
});
console.log('Found an issue: \'#' + linkNumber + '\' in repo. Reference is a legitimate linked issue.');
}
catch (error) {
console.log('Couldn\'t find issue #' + linkNumber + ' in repo. Posting comment...');
prComment = `@${prOwner}, the issue number referenced above as "**${keyword} #${linkNumber}**" is not found. Please replace with a valid issue number.`;
}
}
if (prComment) {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: prComment,
});
}