feat: sync linked issue labels to pull requests#1815
feat: sync linked issue labels to pull requests#1815cheese-cakee wants to merge 10 commits intohiero-ledger:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1815 +/- ##
=======================================
Coverage 93.35% 93.35%
=======================================
Files 141 141
Lines 9119 9119
=======================================
Hits 8513 8513
Misses 606 606 🚀 New features to boost your workflow:
|
|
Warning Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories. WalkthroughAdds a GitHub Actions workflow and a Node.js action script that trigger on PR events or manual dispatch, find linked issues referenced in the PR body, aggregate their labels (skipping PR refs and bot-authored PRs), and apply any missing labels to the PR (supports dry-run, logs 404s and other conditions). Changes
Sequence DiagramsequenceDiagram
participant GHA as GHA (Workflow)
participant Script as sync-issue-labels.js
participant API as GitHub REST API
participant Logs as Console/Workflow Logs
GHA->>Script: Invoke script (PR_NUMBER, DRY_RUN)
Script->>API: Get PR details (author, body, labels)
API-->>Script: PR data
Script->>Script: If bot author -> Logs & exit
Script->>Script: Extract linked issue numbers from PR body
loop per linked issue
Script->>API: Fetch issue by number
alt issue found & is issue
API-->>Script: Issue labels
Script->>Script: Normalize & collect labels
else not found / is PR
API-->>Script: 404 or PR -> Logs & continue
end
end
Script->>Script: Compute labels missing from PR
alt DRY_RUN = false
Script->>API: Add missing labels to PR
API-->>Script: Confirm applied
Script->>Logs: Log result
else DRY_RUN = true
Script->>Logs: Log intended labels (no-op)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
aceppaluni
left a comment
There was a problem hiding this comment.
@cheese-cakee Thank you for this!
Codacy is reporting issues. Take a look at here
Right now the exported async function is handling multiple responsibilities:
Resolving PR context, Fetching PR data, Skipping bot-authored PRs, Extracting linked issue numbers, Fetching each linked issue, Collecting labels from issues, Comparing PR labels vs issue labels, Handling dry-run logic, and Adding labels via the GitHub API.
Because all of this logic lives in one function, the cyclomatic complexity has grown to 31 (limit is 12). A clean way to address this would be to extract smaller, single-responsibility functions. For example:
resolveExecutionContext(...)
shouldSkipPR(...)
collectLabelsFromLinkedIssues(...)
computeLabelsToAdd(...)
addLabelsToPullRequest(...)The exported function would then mainly orchestrate the workflow, which should significantly reduce complexity and make the logic easier to follow and test.
What do you think?
98d5de7 to
51327bc
Compare
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
51327bc to
40b03f9
Compare
|
I've refactored the script as suggested - extracted 5 single-responsibility functions:
The main exported function now mainly orchestrates these. Ready for re-review. |
e91da8a to
40b03f9
Compare
|
Hi, this is MergeConflictBot. Please resolve these conflicts locally and push the changes. Quick Fix for CHANGELOG.md ConflictsIf your conflict is only in CHANGELOG.md, you can resolve it easily using the GitHub web editor:
For all other merge conflicts, please read: Thank you for contributing! |
|
Thanks for notifying this is ready to review again, @cheese-cakee could you please rebase meanwhile, you have some hard conflicts |
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
exploreriii
left a comment
There was a problem hiding this comment.
Thanks for your local testing, any chance you could also test this on a fokr?
- create beginner / etc labels
- create issue with labels
- create PR
- link PR to issue
- see what happens
|
Hello, this is the OfficeHourBot. This is a reminder that the Hiero Python SDK Office Hours are scheduled in approximately 4 hours (14:00 UTC). This session provides an opportunity to ask questions regarding this Pull Request. Details:
Disclaimer: This is an automated reminder. Please verify the schedule here for any changes. From, |
exploreriii
left a comment
There was a problem hiding this comment.
@cheese-cakee i do not think this will be able to write the labels
https://github.com/exploreriii/hiero_sdk_python/actions/runs/22376870704/job/64768985498?pr=226
One idea is to use two workflows,
- workflow to read and save labels
i think you can use https://github.com/actions/download-artifact - workflow to take read labels to write labels
does not use pull request target e.g
on:
workflow_run:
workflows: ["Compute Linked Issue Labels"]
Another idea possibly is to possibly try this
https://github.com/marketplace/actions/actions-ecosystem-add-labels
reference
https://docs.github.com/en/rest/issues/labels?apiVersion=2022-11-28#add-labels-to-an-issue
so i think the logic in your .js is fine, just the .yml will need to change
…omputation Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
- First job computes labels and uploads as artifact - Second job downloads artifact and uses actions-ecosystem-add-labels - This avoids pull_request_target limitations Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
|
Hi, this is WorkflowBot.
|
|
Closed in favor of #1877 Reason: Multiple issues found during review:
All feedback addressed in #1877 with:
|
Description
Adds an automated GitHub workflow + bot script to sync labels from linked issues to pull requests.
When a PR body includes closing keywords (for example
Fixes #123), the workflow fetches labels from those linked issues and adds missing labels to the PR.Related issue(s)
Fixes #1716
What changed
.github/workflows/sync-issue-labels.ymlpull_request_targetonopened,edited,reopened,synchronize, andready_for_reviewharden-runner, checkoutmain, pinned action SHAs)workflow_dispatchwithpr_number+dry_run.github/scripts/sync-issue-labels.jsfixes/closes/resolves)[Unreleased] -> .githubScope note
This PR intentionally implements label sync only (additive). It does not remove labels from PRs and does not include assignee sync.
Testing
Local validation
node --check .github/scripts/sync-issue-labels.jsLocal behavior simulations (mocked GitHub API)
#10, #11with labelsbeginner,github_actions,intermediate; PR already hadgithub_actionsbeginnerandintermediateDRY_RUN=truewith linked issue#12and labelintermediateChecklist