Skip to content

feat: sync linked issue labels to pull requests#1815

Closed
cheese-cakee wants to merge 10 commits intohiero-ledger:mainfrom
cheese-cakee:feat/sync-issue-labels-1716-clean
Closed

feat: sync linked issue labels to pull requests#1815
cheese-cakee wants to merge 10 commits intohiero-ledger:mainfrom
cheese-cakee:feat/sync-issue-labels-1716-clean

Conversation

@cheese-cakee
Copy link
Contributor

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

  • Added workflow: .github/workflows/sync-issue-labels.yml
    • Uses pull_request_target on opened, edited, reopened, synchronize, and ready_for_review
    • Includes secure defaults used in this repo (harden-runner, checkout main, pinned action SHAs)
    • Supports workflow_dispatch with pr_number + dry_run
  • Added script: .github/scripts/sync-issue-labels.js
    • Skips bot/dependabot PRs
    • Parses linked same-repo issue references from closing keywords (fixes/closes/resolves)
    • Aggregates labels from all linked issues (deduplicated)
    • Adds only missing labels to the PR (idempotent/additive)
    • Supports dry-run logging without mutating labels
  • Added changelog entry under [Unreleased] -> .github

Scope 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.js

Local behavior simulations (mocked GitHub API)

  1. Linked issues #10, #11 with labels beginner, github_actions, intermediate; PR already had github_actions
  • Result: script requested adding only beginner and intermediate
  1. DRY_RUN=true with linked issue #12 and label intermediate
  • Result: script logged intended action and made no label API mutation

Checklist

  • Documented (workflow + script behavior is self-logged and changelog updated)
  • Tested (syntax check + local simulation runs)

@codecov
Copy link

codecov bot commented Feb 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 15, 2026

Warning

Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories.

Walkthrough

Adds 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

Cohort / File(s) Summary
Workflow
.github/workflows/sync-issue-labels.yml
New workflow "Sync Linked Issue Labels to PR" triggered on pull_request_target and workflow_dispatch; minimal token permissions; hardens runner; checks out repo and runs the local script via actions/github-script with PR_NUMBER and DRY_RUN.
Action script
.github/scripts/sync-issue-labels.js
New Node.js module exported as module.exports = async ({ github, context }) => { ... }. Retrieves PR details, skips bot-authored PRs, extracts linked issue numbers from PR body, fetches each linked issue (handles 404s and PR references), normalizes and aggregates labels, computes labels missing from the PR, supports DRY_RUN (logs intended changes), and applies labels via GitHub REST API when not dry-run.
Changelog
CHANGELOG.md
Added "Added workflow and bot script to automatically sync labels from linked issues to pull requests. (#1716)" under Unreleased.
Config
.coderabbit.yaml
Removed the schedule_review_instructions block (large deletions) while retaining other configuration entries.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a workflow to synchronize labels from linked issues to pull requests.
Description check ✅ Passed The description is detailed and directly relates to the changeset, explaining the workflow behavior, script logic, scope, testing, and changelog updates.
Linked Issues check ✅ Passed The PR implements both security hardening requirements from #123 (harden-runner, least-privileged permissions, pinned dependencies) and all core objectives from #1716 (workflow detection, label sync, bot skipping, maintainable code structure, changelog).
Out of Scope Changes check ✅ Passed The changes are scoped to label synchronization as intended, with only minor unrelated changes (.coderabbit.yaml removal of schedule_review_instructions) that do not impact functionality.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Copy link
Contributor

@aceppaluni aceppaluni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@aceppaluni aceppaluni added the status: needs developer revision PR has requested changes that the developer needs to implement label Feb 17, 2026
@cheese-cakee cheese-cakee force-pushed the feat/sync-issue-labels-1716-clean branch 3 times, most recently from 98d5de7 to 51327bc Compare February 18, 2026 20:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
@cheese-cakee cheese-cakee force-pushed the feat/sync-issue-labels-1716-clean branch from 51327bc to 40b03f9 Compare February 18, 2026 21:13
@cheese-cakee
Copy link
Contributor Author

I've refactored the script as suggested - extracted 5 single-responsibility functions:

  • resolveExecutionContext() - PR number + dry-run
  • shouldSkipPR() - bot check + linked issues check
  • collectLabelsFromLinkedIssues() - fetches labels from issues
  • computeLabelsToAdd() - filters existing labels
  • addLabelsToPullRequest() - adds labels via API

The main exported function now mainly orchestrates these. Ready for re-review.

@cheese-cakee cheese-cakee force-pushed the feat/sync-issue-labels-1716-clean branch from e91da8a to 40b03f9 Compare February 18, 2026 21:19
@github-actions
Copy link

Hi, this is MergeConflictBot.
Your pull request cannot be merged because it contains merge conflicts.

Please resolve these conflicts locally and push the changes.

Quick Fix for CHANGELOG.md Conflicts

If your conflict is only in CHANGELOG.md, you can resolve it easily using the GitHub web editor:

  1. Click on the "Resolve conflicts" button in the PR
  2. Accept both changes (keep both changelog entries)
  3. Click "Mark as resolved"
  4. Commit the merge

For all other merge conflicts, please read:

Thank you for contributing!

@exploreriii exploreriii added status: needs committer review PR needs a review from the committer team and removed status: needs developer revision PR has requested changes that the developer needs to implement labels Feb 21, 2026
@exploreriii
Copy link
Contributor

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>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@exploreriii exploreriii added status: needs developer testing and removed status: needs committer review PR needs a review from the committer team labels Feb 24, 2026
@github-actions
Copy link

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,
The Python SDK Team

Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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,

  1. workflow to read and save labels
    i think you can use https://github.com/actions/download-artifact
  2. 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

@exploreriii exploreriii added status: needs developer revision PR has requested changes that the developer needs to implement and removed status: needs developer testing labels Feb 25, 2026
@exploreriii exploreriii marked this pull request as draft February 25, 2026 12:09
…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>
@github-actions
Copy link

Hi, this is WorkflowBot.
Your pull request cannot be merged as it is not passing all our workflow checks.
Please click on each check to review the logs and resolve issues so all checks pass.
To help you:

@cheese-cakee cheese-cakee deleted the feat/sync-issue-labels-1716-clean branch February 26, 2026 18:58
@cheese-cakee
Copy link
Contributor Author

cheese-cakee commented Feb 27, 2026

Closed in favor of #1877

Reason: Multiple issues found during review:

  • High cyclomatic complexity (31), needed function extraction
  • Single workflow approach couldn't write labels back (pull_request_target limitation)
  • Requested fork testing before merging

All feedback addressed in #1877 with:

  • Two-workflow approach (compute + add)
  • Refactored to single-responsibility functions
  • All CodeRabbit issues fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs developer revision PR has requested changes that the developer needs to implement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Intermediate]: Create a workflow to copy over the issue labels, type to the PR labels

3 participants