-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add community-contribution-in-progress label action
- Loading branch information
1 parent
ddbfddc
commit c90f62d
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|