Skip to content

Add RFC automation workflow with auto-create Issue #1

Add RFC automation workflow with auto-create Issue

Add RFC automation workflow with auto-create Issue #1

name: "RFC Automation"
on:
pull_request:
types: [opened, edited, synchronize]
paths:
- 'rfcs/**'
jobs:
rfc-automation:
name: RFC PR Automation
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Add RFC label to PR
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['rfc']
});
- name: Check for linked Issue and create if missing
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const prBody = pr.body || '';
const prTitle = pr.title;
// Patterns to detect linked issues
const issuePatterns = [
/(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s*#(\d+)/gi,
/(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+https:\/\/github\.com\/[^\/]+\/[^\/]+\/issues\/(\d+)/gi,
/#(\d+)/g,
/https:\/\/github\.com\/[^\/]+\/[^\/]+\/issues\/(\d+)/gi
];
// Check if PR references any existing issue
let linkedIssue = null;
for (const pattern of issuePatterns) {
const match = pattern.exec(prBody);
if (match) {
linkedIssue = match[1];
console.log(`Found linked issue: #${linkedIssue}`);
break;
}
}
if (linkedIssue) {
console.log(`PR already references issue #${linkedIssue}, skipping issue creation`);
return;
}
// Extract RFC number from files changed
const files = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number
});
let rfcNumber = null;
for (const file of files.data) {
const match = file.filename.match(/rfcs\/(\d{4})-/);
if (match) {
rfcNumber = match[1];
break;
}
}
// Create tracking issue
const issueTitle = rfcNumber
? `RFC-${rfcNumber}: ${prTitle.replace(/^\[?RFC[:\s\-]*\]?\s*/i, '')}`
: `RFC: ${prTitle}`;
const issueBody = `## RFC Tracking Issue
This issue tracks the RFC proposed in #${pr.number}.

Check failure on line 88 in .github/workflows/rfc-automation.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/rfc-automation.yml

Invalid workflow file

You have an error in your yaml syntax on line 88
**Author:** @${pr.user.login}
**PR:** #${pr.number}
---
*This issue was automatically created to track RFC progress on the Projects board.*
`;
const newIssue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
labels: ['rfc', 'auto-created']
});
console.log(`Created tracking issue #${newIssue.data.number}`);
// Add comment to PR linking to the new issue
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: `**RFC Tracking Issue Created:** #${newIssue.data.number}\n\nThis issue will be used to track RFC progress on the Projects board.`
});