mirror of
https://github.com/anomalyco/opencode.git
synced 2026-02-01 22:48:16 +00:00
ci: add OSS contributor detection pr label
This commit is contained in:
87
.github/workflows/pr-management.yml
vendored
87
.github/workflows/pr-management.yml
vendored
@@ -64,25 +64,98 @@ jobs:
|
|||||||
|
|
||||||
$COMMENT"
|
$COMMENT"
|
||||||
|
|
||||||
add-contributor-label:
|
add-contributor-labels:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
issues: write
|
issues: write
|
||||||
steps:
|
steps:
|
||||||
- name: Add Contributor Label
|
- name: Add appropriate contributor labels
|
||||||
uses: actions/github-script@v8
|
uses: actions/github-script@v8
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const isPR = !!context.payload.pull_request;
|
const prNumber = context.payload.pull_request.number;
|
||||||
const issueNumber = isPR ? context.payload.pull_request.number : context.payload.issue.number;
|
const authorAssociation = context.payload.pull_request.author_association;
|
||||||
const authorAssociation = isPR ? context.payload.pull_request.author_association : context.payload.issue.author_association;
|
const prAuthor = context.payload.pull_request.user.login;
|
||||||
|
|
||||||
|
console.log(`Author: ${prAuthor}, Association: ${authorAssociation}`);
|
||||||
|
|
||||||
|
// Add opencode-contributor label if they have prior contributions
|
||||||
if (authorAssociation === 'CONTRIBUTOR') {
|
if (authorAssociation === 'CONTRIBUTOR') {
|
||||||
await github.rest.issues.addLabels({
|
await github.rest.issues.addLabels({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
issue_number: issueNumber,
|
issue_number: prNumber,
|
||||||
labels: ['contributor']
|
labels: ['opencode-contributor']
|
||||||
});
|
});
|
||||||
|
console.log('Added opencode-contributor label');
|
||||||
|
}
|
||||||
|
// Check for OSS contributions only if NOT a contributor/collaborator/owner
|
||||||
|
else if (authorAssociation !== 'COLLABORATOR' && authorAssociation !== 'OWNER') {
|
||||||
|
console.log(`Checking OSS contributions for: ${prAuthor}`);
|
||||||
|
|
||||||
|
// Query user's contributions via GraphQL
|
||||||
|
const result = await github.graphql(`
|
||||||
|
query($login: String!) {
|
||||||
|
user(login: $login) {
|
||||||
|
login
|
||||||
|
contributionsCollection {
|
||||||
|
pullRequestContributionsByRepository(maxRepositories: 20) {
|
||||||
|
repository {
|
||||||
|
owner { login }
|
||||||
|
isPrivate
|
||||||
|
}
|
||||||
|
contributions(first: 1) {
|
||||||
|
nodes {
|
||||||
|
pullRequest { merged }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commitContributionsByRepository(maxRepositories: 20) {
|
||||||
|
repository {
|
||||||
|
owner { login }
|
||||||
|
isPrivate
|
||||||
|
}
|
||||||
|
contributions {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, {
|
||||||
|
login: prAuthor
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check if user has any contributions to external public repos
|
||||||
|
const isExternalPublicRepo = repo =>
|
||||||
|
repo.repository.owner.login !== prAuthor && !repo.repository.isPrivate;
|
||||||
|
|
||||||
|
const { pullRequestContributionsByRepository, commitContributionsByRepository } =
|
||||||
|
result.user.contributionsCollection;
|
||||||
|
|
||||||
|
const hasOSSContributions =
|
||||||
|
pullRequestContributionsByRepository
|
||||||
|
.filter(isExternalPublicRepo)
|
||||||
|
.some(repo => repo.contributions.nodes.some(c => c.pullRequest.merged)) ||
|
||||||
|
commitContributionsByRepository
|
||||||
|
.filter(isExternalPublicRepo)
|
||||||
|
.some(repo => repo.contributions.totalCount > 0);
|
||||||
|
|
||||||
|
console.log(`Has OSS contributions: ${hasOSSContributions}`);
|
||||||
|
|
||||||
|
// Add label if user is an OSS contributor
|
||||||
|
if (hasOSSContributions) {
|
||||||
|
await github.rest.issues.addLabels({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: prNumber,
|
||||||
|
labels: ['oss-contributor']
|
||||||
|
});
|
||||||
|
console.log('Added oss-contributor label');
|
||||||
|
} else {
|
||||||
|
console.log('User has no OSS contributions to other repos');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`User is ${authorAssociation}, skipping OSS check`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ interface RunResult {
|
|||||||
async function main() {
|
async function main() {
|
||||||
console.log("Fetching open contributor PRs...")
|
console.log("Fetching open contributor PRs...")
|
||||||
|
|
||||||
const prsResult = await $`gh pr list --label contributor --state open --json number,title --limit 100`.nothrow()
|
const prsResult =
|
||||||
|
await $`gh pr list --label opencode-contributor --state open --json number,title --limit 100`.nothrow()
|
||||||
if (prsResult.exitCode !== 0) {
|
if (prsResult.exitCode !== 0) {
|
||||||
throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`)
|
throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user