Skip to content

Commit

Permalink
Add community-contribution-in-progress label action
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhanushcdivakar committed Dec 25, 2024
1 parent ddbfddc commit c90f62d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/actions/manage-label/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Manage Labels for External Contributors'
description: 'Add or remove labels when external contributors are assigned or unassigned.'

inputs:
github_token:
description: 'GitHub Token for authentication'
required: true
default: ${{ secrets.GITHUB_TOKEN }}

runs:
using: 'python'
main: 'manage_labels.py'

# Add other configuration based on your requirements

48 changes: 48 additions & 0 deletions .github/actions/manage-label/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const core = require('@actions/core');
const github = require('@actions/github');

async function run() {
try {
const token = core.getInput('repo-token');
const octokit = github.getOctokit(token);
const { context } = github;

const issueNumber = context.issue.number;
const assignee = context.payload.assignee;
const owner = context.repo.owner;
const repo = context.repo.repo;

// Check if the assignee is an external contributor (not a member or owner)
const { data: collaborators } = await octokit.rest.repos.listCollaborators({
owner,
repo,
});

const isExternalContributor = !collaborators.some(
(collab) => collab.login === assignee.login && (collab.role === 'member' || collab.role === 'owner')
);

if (isExternalContributor) {
// Add the label
await octokit.rest.issues.addLabels({
owner,
repo,
issue_number: issueNumber,
labels: ['community-contribution-in-progress'],
});
} else {
// Remove the label
await octokit.rest.issues.removeLabel({
owner,
repo,
issue_number: issueNumber,
name: 'community-contribution-in-progress',
});
}
} catch (error) {
core.setFailed(error.message);
}
}

run();

0 comments on commit c90f62d

Please sign in to comment.