-
Notifications
You must be signed in to change notification settings - Fork 113
Added Workflow for Sync in issue and PR #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,92 @@ | ||||||||||||
name: Sync PR data from Linked Issues | ||||||||||||
|
||||||||||||
on: | ||||||||||||
pull_request: | ||||||||||||
types: [opened, edited, synchronize] | ||||||||||||
|
||||||||||||
jobs: | ||||||||||||
sync-metadata: | ||||||||||||
runs-on: ubuntu-latest | ||||||||||||
|
||||||||||||
permissions: | ||||||||||||
issues: write | ||||||||||||
|
||||||||||||
steps: | ||||||||||||
- name: Extract Linked Issues | ||||||||||||
id: extract | ||||||||||||
uses: actions/github-script@v7 | ||||||||||||
with: | ||||||||||||
script: | | ||||||||||||
const body = context.payload.pull_request.body || ""; | ||||||||||||
const issuePattern = /#(\d+)/g; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex pattern will match any '#' followed by digits, potentially capturing false positives like '#123' in code snippets or unrelated contexts. Consider using a more specific pattern that looks for common issue linking phrases like 'fixes #123', 'closes #123', or 'resolves #123'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex pattern
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
let matches = []; | ||||||||||||
let m; | ||||||||||||
while ((m = issuePattern.exec(body)) !== null) { | ||||||||||||
matches.push(parseInt(m[1])); | ||||||||||||
} | ||||||||||||
core.setOutput("issues", JSON.stringify(matches)); | ||||||||||||
|
||||||||||||
- name: Post or Update data Comment | ||||||||||||
if: steps.extract.outputs.issues && steps.extract.outputs.issues != '[]' | ||||||||||||
uses: actions/github-script@v7 | ||||||||||||
with: | ||||||||||||
script: | | ||||||||||||
const issuesInput = core.getInput("issues") || "[]"; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script tries to get input 'issues' but it should use the output from the previous step. Use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
const issues = JSON.parse(issuesInput); | ||||||||||||
const prNumber = context.payload.pull_request.number; | ||||||||||||
|
||||||||||||
let combinedLabels = []; | ||||||||||||
let combinedAssignees = []; | ||||||||||||
let combinedMilestones = []; | ||||||||||||
|
||||||||||||
for (const number of issues) { | ||||||||||||
try { | ||||||||||||
const issue = await github.rest.issues.get({ | ||||||||||||
...context.repo, | ||||||||||||
issue_number: number | ||||||||||||
}); | ||||||||||||
|
||||||||||||
combinedLabels.push(...issue.data.labels.map(l => l.name)); | ||||||||||||
combinedAssignees.push(...issue.data.assignees.map(a => a.login)); | ||||||||||||
if (issue.data.milestone) combinedMilestones.push(issue.data.milestone.title); | ||||||||||||
|
||||||||||||
} catch (err) { | ||||||||||||
console.log(`Could not fetch issue #${number}: ${err.message}`); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
// Deduplicate | ||||||||||||
combinedLabels = [...new Set(combinedLabels)]; | ||||||||||||
combinedAssignees = [...new Set(combinedAssignees)]; | ||||||||||||
combinedMilestones = [...new Set(combinedMilestones)]; | ||||||||||||
|
||||||||||||
const commentBody = | ||||||||||||
`### Synced data from Linked Issues\n\n` + | ||||||||||||
`**Labels:**\n${combinedLabels.length ? combinedLabels.map(l => `- ${l}`).join("\n") : "- None"}\n\n` + | ||||||||||||
`**Assignees:**\n${combinedAssignees.length ? combinedAssignees.map(a => `- ${a}`).join("\n") : "- None"}\n\n` + | ||||||||||||
`**Milestones:**\n${combinedMilestones.length ? combinedMilestones.map(m => `- ${m}`).join("\n") : "- None"}\n`; | ||||||||||||
|
||||||||||||
// Get existing comments | ||||||||||||
const comments = await github.rest.issues.listComments({ | ||||||||||||
...context.repo, | ||||||||||||
issue_number: prNumber | ||||||||||||
}); | ||||||||||||
|
||||||||||||
// Find existing workflow comment | ||||||||||||
const existingComment = comments.data.find(c => c.body.includes("### Synced data from Linked Issues")); | ||||||||||||
|
||||||||||||
if (existingComment) { | ||||||||||||
// Update existing comment | ||||||||||||
await github.rest.issues.updateComment({ | ||||||||||||
...context.repo, | ||||||||||||
comment_id: existingComment.id, | ||||||||||||
body: commentBody | ||||||||||||
}); | ||||||||||||
} else { | ||||||||||||
// Create new comment | ||||||||||||
await github.rest.issues.createComment({ | ||||||||||||
...context.repo, | ||||||||||||
issue_number: prNumber, | ||||||||||||
body: commentBody | ||||||||||||
}); | ||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.