Skip to content

docs(label_issues): add logics for adding os related labels #1437

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

Merged
merged 2 commits into from
May 19, 2025

Conversation

bearomorphism
Copy link
Contributor

@bearomorphism bearomorphism commented May 19, 2025

Description

I think the issue labels can be added automatically.

Checklist

Code Changes

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run poetry doc locally to ensure the documentation pages renders correctly

Expected Behavior

Steps to Test This Pull Request

Additional Context

Copy link

codecov bot commented May 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.57%. Comparing base (120d514) to head (7fead35).
Report is 615 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1437      +/-   ##
==========================================
+ Coverage   97.33%   97.57%   +0.23%     
==========================================
  Files          42       57      +15     
  Lines        2104     2681     +577     
==========================================
+ Hits         2048     2616     +568     
- Misses         56       65       +9     
Flag Coverage Δ
unittests 97.57% <ø> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

TBH, I know nothing about js....

It doesn't look weird and it probably won't break anything but CI so I'll go ahead and merge it

@Lee-W Lee-W merged commit 49f4d2b into commitizen-tools:master May 19, 2025
18 checks passed
@bearomorphism
Copy link
Contributor Author

At least ChatGPT said it's good. I just spent 21 dollars on ChatGPT today.


Great idea — converting osLabels to a Set is a clean way to prevent duplicate labels and make your intention explicit.

Here's how you'd update your script:


✅ Version using Set for osLabels

const issue = await github.rest.issues.get({
  owner: context.repo.owner,
  repo: context.repo.repo,
  issue_number: context.issue.number,
});

const body = issue.data.body || '';

const osLabels = new Set();

if (body.includes('Operating System: Darwin')) {
  osLabels.add('os: macOS');
}

if (body.includes('Operating System: Linux')) {
  osLabels.add('os: Linux');
}

if (body.includes('Operating System: Windows')) {
  osLabels.add('os: Windows');
}

// Combine with static labels, converting Set to Array
await github.rest.issues.addLabels({
  issue_number: context.issue.number,
  owner: context.repo.owner,
  repo: context.repo.repo,
  labels: ['issue-status: needs-triage', ...osLabels],
});

🔍 Why Use Set?

  • Prevents duplicates (in case multiple OS lines appear — unlikely, but good hygiene).
  • Semantic clarity — shows you're collecting unique labels.

✅ Optional Improvements

  • Case-insensitive matching:

    const body = (issue.data.body || '').toLowerCase();
    if (body.includes('operating system: darwin')) osLabels.add('os: macOS');
  • Use a map if you want to reduce repetition:

    const osMap = {
      'Darwin': 'os: macOS',
      'Linux': 'os: Linux',
      'Windows': 'os: Windows',
    };
    
    Object.entries(osMap).forEach(([keyword, label]) => {
      if (body.includes(`Operating System: ${keyword}`)) {
        osLabels.add(label);
      }
    });

Let me know if you want to generalize this for other metadata fields too.

@bearomorphism bearomorphism deleted the issue-script branch May 19, 2025 14:16
@Lee-W
Copy link
Member

Lee-W commented May 19, 2025

might need some time to think about it haha

I actually learnt some of it from cpython and airflow

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

Successfully merging this pull request may close these issues.

2 participants