Skip to content

Conversation

sheikhlimon
Copy link
Contributor

@sheikhlimon sheikhlimon commented Oct 21, 2025

Description

Fixes #986

Type of Change

  • New feature (e.g., new page, component, or functionality)
  • Bug fix (non-breaking change that fixes an issue)
  • UI/UX improvement (design, layout, or styling updates)
  • Performance optimization (e.g., code splitting, caching)
  • Documentation update (README, contribution guidelines, etc.)
  • Other (please specify):

Changes Made

  • Changed from return to core.setOutput() to prevent double-encoding
  • Split outputs into separate values (issues and pr) for cleaner parsing

Testing

  • Tested locally with `act` (nektos/act)
  • Workflow extracts linked issues correctly
  • No syntax errors or crashes
  • Ready for integration testing on live PR

Test Output

[Sync Issue Metadata to PR/sync-pr-metadata]   ⚙  ::set-output:: issues=["986"]
[Sync Issue Metadata to PR/sync-pr-metadata]   ⚙  ::set-output:: pr=984
[Sync Issue Metadata to PR/sync-pr-metadata]   ✅  Success - Main Extract linked issue(s) from PR
[Sync Issue Metadata to PR/sync-pr-metadata]   ✅  Success - Main Sync Issue Metadata to PR
[Sync Issue Metadata to PR/sync-pr-metadata] 🏁  Job succeeded

@vercel
Copy link
Contributor

vercel bot commented Oct 21, 2025

@sheikhlimon is attempting to deploy a commit to the recode Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. The estimated time for response is 5–8 hrs.

In the meantime, please provide all necessary screenshots and make sure you run - npm build run , command and provide a screenshot, a video recording, or an image of the update you made below, which helps speed up the review and assignment. If you have questions, reach out to LinkedIn. Your contributions are highly appreciated!😊

Note: I maintain the repo issue every day twice at 8:00 AM IST and 9:00 PM IST. If your PR goes stale for more than one day, you can tag and comment on this same issue by tagging @sanjay-kv.

We are here to help you on this journey of open source. Consistent 20 contributions are eligible for sponsorship 💰

🎁 check our list of amazing people we sponsored so far: GitHub Sponsorship. ✨

📚Your perks for contribution to this community 👇🏻

  1. Get free Consultation use code recode50 to get free: Mentorship for free.

  2. Get the Ebook for free use code recode at checkout: Data Science cheatsheet for Beginners.

  3. Check out this weekly Newsletter: Sanjay's Newsletter.

If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

@github-actions github-actions bot added hacktoberfest-accepted recode this is label for leaderboard labels Oct 21, 2025
@github-actions
Copy link

Synced data from Linked Issues

Labels:

  • level 1
  • recode
  • hacktoberfest-accepted

Assignees:

  • None

Milestones:

  • None

@sheikhlimon
Copy link
Contributor Author

sheikhlimon commented Oct 21, 2025

Ready for review @iitzIrFan

@iitzIrFan iitzIrFan moved this to In Progress in @recode-web Oct 21, 2025
@iitzIrFan iitzIrFan added the under review Review under the maintainers or the admins label Oct 21, 2025
@sheikhlimon sheikhlimon force-pushed the fix/sync-metadata-workflow branch from 8dda805 to 7aefb94 Compare October 21, 2025 12:22
@sheikhlimon sheikhlimon force-pushed the fix/sync-metadata-workflow branch from 87ac17c to 80ed039 Compare October 21, 2025 12:40
@sheikhlimon sheikhlimon force-pushed the fix/sync-metadata-workflow branch from d16ab6d to d639a87 Compare October 21, 2025 12:52
- Replaced `setLabels()` with `addLabels()` to prevent race conditions
  where concurrent label additions could be lost.
- Labels from linked issues are now added without removing existing PR labels.
- Milestones from linked issues continue to be synced.
- Adds a comment to the PR summarizing synchronized metadata.
@sheikhlimon
Copy link
Contributor Author

@iitzIrFan i think my last commit change should work right.... vercel agent review came to the rescue @sanjay-kv did you turn it on.. or it was working from the beginning... @iitzIrFan its shows error now because its still checking the previous gitflow i have attached the log below thats coming from merged gitflow...

Run actions/github-script@v7
  with:
    github-token: ***
    script: const data = JSON.parse('"{\"issues\":[\"986\"],\"pr\":989}"');
  const prNumber = data.pr;
  const issueNumbers = data.issues || [];
  
  if (issueNumbers.length === 0) {
    console.log("No linked issues found");
    return;
  }
  
  for (const issueNumber of issueNumbers) {
    try {
      // Fetch issue
      const { data: issue } = await github.rest.issues.get({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: parseInt(issueNumber)
      });
  
      console.log(`Syncing metadata from Issue #${issueNumber} to PR #${prNumber}`);
  
      // --- Sync Labels ---
      const issueLabels = issue.labels.map(l => l.name);
      const { data: pr } = await github.rest.pulls.get({
        owner: context.repo.owner,
        repo: context.repo.repo,
        pull_number: prNumber
      });
      const currentPRLabels = pr.labels.map(l => l.name);
      const combinedLabels = Array.from(new Set([...currentPRLabels, ...issueLabels]));
  
      await github.rest.issues.addLabels({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: prNumber,
        labels: combinedLabels
      });
      console.log(`Labels applied: ${combinedLabels.join(', ')}`);
  
      // --- Sync Milestone ---
      if (issue.milestone) {
        await github.rest.issues.update({
          owner: context.repo.owner,
          repo: context.repo.repo,
          issue_number: prNumber,
          milestone: issue.milestone.number
        });
        console.log(`Milestone synced: ${issue.milestone.title}`);
      }
  
      // --- Sync Projects (GitHub Projects v2) ---
      if(issue.project_cards_url) {
        // Fetch project cards of issue
        const cardsResponse = await github.rest.projects.listCards({
          column_id: issue.project_cards_url.split('/').pop() // last part is column_id
        }).catch(()=>({data:[]}));
        
        for(const card of cardsResponse.data || []) {
          await github.rest.projects.createCard({
            column_id: card.column_id,
            content_id: prNumber,
            content_type: 'PullRequest'
          });
          console.log(`Added PR #${prNumber} to project card in column ${card.column_id}`);
        }
      }
  
      // --- Optionally: Add a comment on PR ---
      await github.rest.issues.createComment({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: prNumber,
        body: `✅ Synchronized metadata from Issue #${issueNumber}:\nLabels: ${issueLabels.join(', ')}\nMilestone: ${issue.milestone ? issue.milestone.title : 'None'}`
      });
  
    } catch (error) {
      console.error(`Error syncing issue #${issueNumber} to PR #${prNumber}:`, error.message);
    }

@sanjay-kv
Copy link
Member

I turned vercel agent on got $100 offer so opted for it

- Stop direct interpolation of workflow outputs into github-script to avoid malformed JSON errors.
- Pass issues and PR number via environment variables and parse from process.env.
- Add defensive JSON parsing with cleaning for extra quotes/newlines.
- Fix typo in PR comment: use issue.milestone correctly.
- Use addLabels() instead of setLabels() to prevent race conditions and preserve existing PR labels.
- Sync milestones and add a comment summarizing the synchronized metadata.
@sanjay-kv
Copy link
Member

@sheikhlimon this got few conflicts, can you help

@sheikhlimon
Copy link
Contributor Author

@sheikhlimon this got few conflicts, can you help

Yeah you merged the test PR as well should have closed that

@sanjay-kv sanjay-kv merged commit bef94e7 into recodehive:main Oct 22, 2025
4 of 5 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in @recode-web Oct 22, 2025
@sheikhlimon sheikhlimon deleted the fix/sync-metadata-workflow branch October 22, 2025 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted recode this is label for leaderboard under review Review under the maintainers or the admins

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG]: Fix sync metadata workflow

3 participants