Skip to content
Open
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
37 changes: 15 additions & 22 deletions .github/workflows/sync-pr-labels.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Sync PR Labels

on:
pull_request:
types: [opened, reopened, synchronize, edited]
pull_request_target:
types: [opened, reopened, synchronize, edited]

Expand Down Expand Up @@ -249,7 +247,7 @@ jobs:
labels: [sizeLabel]
});

# STEP 4: Contributor-based labels
# STEP 4: Contributor-based labels(in this later we can add logic of team p as discussed on discord)
- name: Apply contributor-based labels
uses: actions/github-script@v7
env:
Expand All @@ -270,37 +268,32 @@ jobs:

const contributorLabels = [];

// Check if contributor is a member of the organization
try {
await github.rest.orgs.checkMembershipForUser({
org: context.repo.owner,
username: prAuthor
});
contributorLabels.push('member');
} catch (error) {
// Not a member
if (commits.data.length <= 1) {
contributorLabels.push('first-time-contributor');
} else {
contributorLabels.push('external-contributor');
}
}

// Check if PR author is a collaborator
// First check if maintainer
let isMaintainer = false;
try {
const permissionLevel = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: prAuthor
});

if (permissionLevel.data.permission === 'admin' || permissionLevel.data.permission === 'maintain') {
contributorLabels.push('maintainer');
if (['admin', 'maintain'].includes(permissionLevel.data.permission)) {
contributorLabels.push('Org-Member');
isMaintainer = true;
}
} catch (error) {
console.log('Could not check collaborator status');
}

// If not maintainer, check contributor type
if (!isMaintainer) {
if (commits.data.length <= 1) {
contributorLabels.push('first-time-contributor');
} else {
contributorLabels.push('external-contributor');
}
}

if (contributorLabels.length > 0) {
console.log(`Applying contributor-based labels: ${contributorLabels.join(', ')}`);

Expand Down