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

Auto add labels and assignees to PRs #5359

Merged
merged 2 commits into from
Sep 19, 2023
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
18 changes: 0 additions & 18 deletions .github/workflows/labeler.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
name: Auto Assign Based on Labels
name: Auto Add Labels and Assignees
on:
pull_request_target:
types: ["opened", "reopened", "ready_for_review"]

jobs:
assign_based_on_labels:
add_label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
if: ${{ github.event.pull_request.draft == false }}
add_assignee:
runs-on: ubuntu-latest
needs: add_label
permissions:
contents: read
pull-requests: write
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set Assignees
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let issue_number = context.payload.pull_request.number;
let issueDetails = await github.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
});
let labels = issueDetails.data.labels
const assignees = [];
const labelsToAssignees = {
'product: CLion': ['tpasternak'],
'product: IntelliJ': ['mai93'],
'product: GoLand': ['blorente'],
'product: Android Studio': ['mai93']
// Add more label-assignee mappings here
};

const labels = context.payload.pull_request.labels.map(label => label.name);
const assignees = [];

for (const label of labels) {
if (label in labelsToAssignees) {
assignees.push(...labelsToAssignees[label]);
if (label.name in labelsToAssignees) {
assignees.push(...labelsToAssignees[label.name]);
}
}

if (assignees.length > 0) {
const issue_number = context.payload.pull_request.number;
await github.issues.addAssignees({
issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
assignees
});
}
}
Loading