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 3 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/auto-label@v2.3.0
- 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 labels = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number
});
SGI-CAPP-AT2 marked this conversation as resolved.
Show resolved Hide resolved
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"]
SGI-CAPP-AT2 marked this conversation as resolved.
Show resolved Hide resolved
});
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"]
});
Copy link

@coderabbitai coderabbitai bot Oct 31, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Logic doesn't match requirements - should check issue body for keywords.

The current implementation checks existing labels instead of scanning the issue body for keywords as specified in the requirements. Additionally, some required label combinations are missing.

Here's the corrected implementation:

-            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"]  
-              });
+            const issue = await github.rest.issues.get({
+              owner,
+              repo,
+              issue_number
+            });
+            
+            const body = issue.data.body.toLowerCase();
+            const labelsToAdd = new Set(["good first issue"]);
+            
+            if (body.match(/\b(dependabot|dependency|dependencies)\b/)) {
+              labelsToAdd.add("dependencies").add("security");
+            }
+            if (body.match(/\bsecurity\b/)) {
+              labelsToAdd.add("security");
+            }
+            if (body.match(/\b(layout|screen|design|figma)\b/)) {
+              labelsToAdd.add("ui/ux");
+            }
+            
+            if (labelsToAdd.size > 1) { // More than just "good first issue"
+              await github.rest.issues.addLabels({
+                owner,
+                repo,
+                issue_number,
+                labels: Array.from(labelsToAdd)
+              });
+            }
📝 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
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"]
});
const issue = await github.rest.issues.get({
owner,
repo,
issue_number
});
const body = issue.data.body.toLowerCase();
const labelsToAdd = new Set(["good first issue"]);
if (body.match(/\b(dependabot|dependency|dependencies)\b/)) {
labelsToAdd.add("dependencies").add("security");
}
if (body.match(/\bsecurity\b/)) {
labelsToAdd.add("security");
}
if (body.match(/\b(layout|screen|design|figma)\b/)) {
labelsToAdd.add("ui/ux");
}
if (labelsToAdd.size > 1) { // More than just "good first issue"
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: Array.from(labelsToAdd)
});
}
🧰 Tools
🪛 yamllint

[error] 47-47: trailing spaces

(trailing-spaces)


[error] 54-54: trailing spaces

(trailing-spaces)

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