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

Add Auto-Labeling for Issues using GitHub Actions #5136

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Changes from 10 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
57 changes: 57 additions & 0 deletions .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Auto Label Issues

on:
issues:
types: [opened, edited] # Runs when an issue is created or modified
workflow_dispatch: # Allows manual triggering

jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Auto-label Issues
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const labelsToAdd = [];

// Define label mappings based on brackets in title
const labelMappings = {
"[bug]": "bug",
"[feature]": "enhancement",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could also be feat

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean in addition to [feature] we should also add [feat] and both will map to enhancement??

Copy link
Collaborator

Choose a reason for hiding this comment

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

For example, yes. You could have multiple variants.

"[docs]": "documentation",
"[dpdk]": "dpdk",
"[bmv2]": "bmv2",
"[P4Testgen]": "p4tools",
"[P4Smith]": "p4tools",
"[P4tools]": "p4tools",
"[Tofino]":"tofino",
"[p4tc]": "p4tc",
"[p4fmt]": "p4fmt",
"[core]":"core",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This list is missing some more labels:

https://github.com/p4lang/p4c/issues/labels

Copy link
Contributor Author

@Vineet1101 Vineet1101 Feb 23, 2025

Choose a reason for hiding this comment

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

Screenshot from 2025-02-23 09-51-55
Screenshot from 2025-02-23 10-07-59
Screenshot from 2025-02-23 10-07-45

Do i need to add them in the auto label list????

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fruffy can you please clear this doubts so that I can make changes accordingly

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am currently traveling with limited access to internet. I will give this a thorough look later. run-xyz you do not need to map.

For the other labels you should take a look at the issues that are being tagged with them and see whether you can find a mapping that works.

"[p4-spec]": "p4-spec",
"[control-plane]": "control-plane",
"[P4runtime]":"control-plane",
"[frontend]":"core",
"[midend]":"core",
"[parser]":"core",
};

// Check if issue title contains bracketed keywords
const title = issue.title.toLowerCase();
for (const [keyword, label] of Object.entries(labelMappings)) {
if (title.includes(keyword.toLowerCase())) {
labelsToAdd.push(label);
}
}

if (labelsToAdd.length > 0) {
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labelsToAdd
});
}
Loading