Skip to content

Refactor feedback type select and add submitted state #49

Refactor feedback type select and add submitted state

Refactor feedback type select and add submitted state #49

name: PR Label Inheritance
on:
pull_request_target:
types: [opened, edited, reopened]
permissions:
issues: read
pull-requests: write
jobs:
inherit-labels:
runs-on: ubuntu-latest
steps:
- name: Inherit Labels from Linked Issues
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.issue.number;
const prBody = context.payload.pull_request.body || '';
const prCreatedAt =
new Date(context.payload.pull_request.created_at);
console.log(`Processing PR #${prNumber}`);
console.log(`PR created at: ${prCreatedAt}`);
// Extract issue numbers from PR body
// Matches patterns like:
// Fixes #123, Closes #456, Resolves #789, etc.
const issuePattern =
/(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)/gi;
const matches = [...prBody.matchAll(issuePattern)];
const issueNumbers = matches.map(match => parseInt(match[1]));
const foundIssues = issueNumbers.join(', ') || 'none';
console.log(`Found linked issues: ${foundIssues}`);
// Collect all labels to add
const labelsToAdd = new Set();
// Fetch labels from linked issues
for (const issueNumber of issueNumbers) {
try {
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
const issueLabels = issue.data.labels.map(label =>
typeof label === 'string' ? label : label.name
);
const labelsList = issueLabels.join(', ') || 'none';
console.log(`Issue #${issueNumber} has labels: ${labelsList}`);
issueLabels.forEach(label => labelsToAdd.add(label));
} catch (error) {
console.log(`Could not fetch issue #${issueNumber}: ${error.message}`);
}
}
// Add hacktoberfest-accepted label for PRs in October
const month = prCreatedAt.getMonth(); // 0-indexed (9 = Oct)
if (month === 9) { // October
labelsToAdd.add('hacktoberfest-accepted');
console.log('PR in October - adding hacktoberfest-accepted');
}
// Get current PR labels
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
const currentLabels = new Set(
pr.data.labels.map(label =>
typeof label === 'string' ? label : label.name
)
);
// Filter out labels that are already on the PR
const newLabels = [...labelsToAdd].filter(
label => !currentLabels.has(label)
);
if (newLabels.length > 0) {
console.log(`Adding labels to PR: ${newLabels.join(', ')}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: newLabels
});
console.log('Labels added successfully!');
} else {
console.log('No new labels to add');
}