Skip to content
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

feat: Workflow changes which will label issues automatically as per #2256 #2390

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/auto-label.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"labelsSynonyms": {
"dependencies": ["dependabot", "dependency", "dependencies"],
"security": ["security"],
"ui/ux": ["layout", "screen", "design", "figma"]
},
"defaultLabels": ["unapproved"],
}
39 changes: 35 additions & 4 deletions .github/workflows/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,43 @@ jobs:
name: Adding Issue Label
runs-on: ubuntu-latest
steps:
- uses: Renato66/[email protected]
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github/workflows/auto-label.json5
sparse-checkout-cone-mode: false
- uses: Renato66/auto-label@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
SGI-CAPP-AT2 marked this conversation as resolved.
Show resolved Hide resolved
ignore-comments: true
default-labels: '["unapproved"]'

- uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const apiParams = {
owner,
repo,
issue_number
};
const labels = await github.rest.issues.listLabelsOnIssue(apiParams);
if(labels.data.reduce((a, c)=>a||["dependencies"].includes(c.name), false))
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ["good first issue", "security"]
});
else if(labels.data.reduce((a, c)=>a||["security", "ui/ux"].includes(c.name), false))
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ["good first issue"]
});
Comment on lines +29 to +55
Copy link

@coderabbitai coderabbitai bot Nov 2, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implementation doesn't match requirements.

The current implementation has several issues:

  1. It checks existing labels instead of scanning the issue body for keywords
  2. The label combinations don't match the requirements
  3. It doesn't handle all required keyword cases
  4. There's potential for duplicate label additions

Here's the corrected implementation:

 - uses: actions/github-script@v6
   env:
     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   with:
     script: |
       const { owner, repo } = context.repo;
       const issue_number = context.issue.number;
       const apiParams = {
         owner,
         repo,
         issue_number
       };
-      const labels = await github.rest.issues.listLabelsOnIssue(apiParams);
-      if(labels.data.reduce((a, c)=>a||["dependencies"].includes(c.name), false))
-        await github.rest.issues.addLabels({
-          owner: context.repo.owner,
-          repo: context.repo.repo,
-          issue_number: context.issue.number,
-          labels: ["good first issue", "security"]
-        });
-      else if(labels.data.reduce((a, c)=>a||["security", "ui/ux"].includes(c.name), false))
-        await github.rest.issues.addLabels({
-          owner: context.repo.owner,
-          repo: context.repo.repo,
-          issue_number: context.issue.number,
-          labels: ["good first issue"]
-        });
+      // Get issue details
+      const issue = await github.rest.issues.get(apiParams);
+      const body = issue.data.body?.toLowerCase() || '';
+      
+      // Initialize labels set with the default label
+      const labelsToAdd = new Set(['good first issue']);
+      
+      // Check for dependencies keywords
+      if (body.match(/\b(dependabot|dependency|dependencies)\b/)) {
+        labelsToAdd.add('dependencies').add('security');
+      }
+      
+      // Check for security keyword
+      if (body.match(/\bsecurity\b/)) {
+        labelsToAdd.add('security');
+      }
+      
+      // Check for UI/UX keywords
+      if (body.match(/\b(layout|screen|design|figma)\b/)) {
+        labelsToAdd.add('ui/ux');
+      }
+      
+      // Add labels if we have more than just the default label
+      if (labelsToAdd.size > 1) {
+        await github.rest.issues.addLabels({
+          ...apiParams,
+          labels: Array.from(labelsToAdd)
+        });
+      }

Key improvements:

  1. Scans issue body for keywords as per requirements
  2. Handles all required keyword-label mappings
  3. Uses Set to prevent duplicate labels
  4. Adds null check for issue body
  5. Reuses apiParams object
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const apiParams = {
owner,
repo,
issue_number
};
const labels = await github.rest.issues.listLabelsOnIssue(apiParams);
if(labels.data.reduce((a, c)=>a||["dependencies"].includes(c.name), false))
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ["good first issue", "security"]
});
else if(labels.data.reduce((a, c)=>a||["security", "ui/ux"].includes(c.name), false))
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ["good first issue"]
});
- uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const apiParams = {
owner,
repo,
issue_number
};
// Get issue details
const issue = await github.rest.issues.get(apiParams);
const body = issue.data.body?.toLowerCase() || '';
// Initialize labels set with the default label
const labelsToAdd = new Set(['good first issue']);
// Check for dependencies keywords
if (body.match(/\b(dependabot|dependency|dependencies)\b/)) {
labelsToAdd.add('dependencies').add('security');
}
// Check for security keyword
if (body.match(/\bsecurity\b/)) {
labelsToAdd.add('security');
}
// Check for UI/UX keywords
if (body.match(/\b(layout|screen|design|figma)\b/)) {
labelsToAdd.add('ui/ux');
}
// Add labels if we have more than just the default label
if (labelsToAdd.size > 1) {
await github.rest.issues.addLabels({
...apiParams,
labels: Array.from(labelsToAdd)
});
}

Copy link
Author

Choose a reason for hiding this comment

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

The changes suggested by the coderabbit will add 'good first issue' to every issue by default.
@palisadoes
and my approach is not to use script for that but to use for detecting labels as mentioned in PR Body.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!



Issue-Greeting:
name: Greeting Message to User
runs-on: ubuntu-latest
Expand Down
Loading