Skip to content

Commit f4e3bee

Browse files
Apply PR #11526: ci: add OSS contributor detection pr label
2 parents d5d36fd + f4972a2 commit f4e3bee

File tree

2 files changed

+82
-8
lines changed

2 files changed

+82
-8
lines changed

.github/workflows/pr-management.yml

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,98 @@ jobs:
6464
6565
$COMMENT"
6666
67-
add-contributor-label:
67+
add-contributor-labels:
6868
runs-on: ubuntu-latest
6969
permissions:
7070
pull-requests: write
7171
issues: write
7272
steps:
73-
- name: Add Contributor Label
73+
- name: Add appropriate contributor labels
7474
uses: actions/github-script@v8
7575
with:
7676
script: |
77-
const isPR = !!context.payload.pull_request;
78-
const issueNumber = isPR ? context.payload.pull_request.number : context.payload.issue.number;
79-
const authorAssociation = isPR ? context.payload.pull_request.author_association : context.payload.issue.author_association;
77+
const prNumber = context.payload.pull_request.number;
78+
const authorAssociation = context.payload.pull_request.author_association;
79+
const prAuthor = context.payload.pull_request.user.login;
8080
81+
console.log(`Author: ${prAuthor}, Association: ${authorAssociation}`);
82+
83+
// Add opencode-contributor label if they have prior contributions
8184
if (authorAssociation === 'CONTRIBUTOR') {
8285
await github.rest.issues.addLabels({
8386
owner: context.repo.owner,
8487
repo: context.repo.repo,
85-
issue_number: issueNumber,
86-
labels: ['contributor']
88+
issue_number: prNumber,
89+
labels: ['opencode-contributor']
8790
});
91+
console.log('Added opencode-contributor label');
92+
}
93+
// Check for OSS contributions only if NOT a contributor/collaborator/owner
94+
else if (authorAssociation !== 'COLLABORATOR' && authorAssociation !== 'OWNER') {
95+
console.log(`Checking OSS contributions for: ${prAuthor}`);
96+
97+
// Query user's contributions via GraphQL
98+
const result = await github.graphql(`
99+
query($login: String!) {
100+
user(login: $login) {
101+
login
102+
contributionsCollection {
103+
pullRequestContributionsByRepository(maxRepositories: 20) {
104+
repository {
105+
owner { login }
106+
isPrivate
107+
}
108+
contributions(first: 1) {
109+
nodes {
110+
pullRequest { merged }
111+
}
112+
}
113+
}
114+
commitContributionsByRepository(maxRepositories: 20) {
115+
repository {
116+
owner { login }
117+
isPrivate
118+
}
119+
contributions {
120+
totalCount
121+
}
122+
}
123+
}
124+
}
125+
}
126+
`, {
127+
login: prAuthor
128+
});
129+
130+
// Check if user has any contributions to external public repos
131+
const isExternalPublicRepo = repo =>
132+
repo.repository.owner.login !== prAuthor && !repo.repository.isPrivate;
133+
134+
const { pullRequestContributionsByRepository, commitContributionsByRepository } =
135+
result.user.contributionsCollection;
136+
137+
const hasOSSContributions =
138+
pullRequestContributionsByRepository
139+
.filter(isExternalPublicRepo)
140+
.some(repo => repo.contributions.nodes.some(c => c.pullRequest.merged)) ||
141+
commitContributionsByRepository
142+
.filter(isExternalPublicRepo)
143+
.some(repo => repo.contributions.totalCount > 0);
144+
145+
console.log(`Has OSS contributions: ${hasOSSContributions}`);
146+
147+
// Add label if user is an OSS contributor
148+
if (hasOSSContributions) {
149+
await github.rest.issues.addLabels({
150+
owner: context.repo.owner,
151+
repo: context.repo.repo,
152+
issue_number: prNumber,
153+
labels: ['oss-contributor']
154+
});
155+
console.log('Added oss-contributor label');
156+
} else {
157+
console.log('User has no OSS contributions to other repos');
158+
}
159+
} else {
160+
console.log(`User is ${authorAssociation}, skipping OSS check`);
88161
}

script/beta.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface RunResult {
1414
async function main() {
1515
console.log("Fetching open contributor PRs...")
1616

17-
const prsResult = await $`gh pr list --label contributor --state open --json number,title --limit 100`.nothrow()
17+
const prsResult =
18+
await $`gh pr list --label opencode-contributor --state open --json number,title --limit 100`.nothrow()
1819
if (prsResult.exitCode !== 0) {
1920
throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`)
2021
}

0 commit comments

Comments
 (0)