mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-28 16:55:44 +00:00
162 lines
6.0 KiB
YAML
162 lines
6.0 KiB
YAML
name: pr-management
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [opened]
|
|
|
|
jobs:
|
|
check-duplicates:
|
|
if: |
|
|
github.event.pull_request.user.login != 'actions-user' &&
|
|
github.event.pull_request.user.login != 'opencode' &&
|
|
github.event.pull_request.user.login != 'rekram1-node' &&
|
|
github.event.pull_request.user.login != 'thdxr' &&
|
|
github.event.pull_request.user.login != 'kommander' &&
|
|
github.event.pull_request.user.login != 'jayair' &&
|
|
github.event.pull_request.user.login != 'fwang' &&
|
|
github.event.pull_request.user.login != 'adamdotdevin' &&
|
|
github.event.pull_request.user.login != 'iamdavidhill' &&
|
|
github.event.pull_request.user.login != 'opencode-agent[bot]'
|
|
runs-on: blacksmith-4vcpu-ubuntu-2404
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Setup Bun
|
|
uses: ./.github/actions/setup-bun
|
|
|
|
- name: Install dependencies
|
|
run: bun install
|
|
|
|
- name: Install opencode
|
|
run: curl -fsSL https://opencode.ai/install | bash
|
|
|
|
- name: Build prompt
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
run: |
|
|
{
|
|
echo "Check for duplicate PRs related to this new PR:"
|
|
echo ""
|
|
echo "CURRENT_PR_NUMBER: $PR_NUMBER"
|
|
echo ""
|
|
echo "Title: $(gh pr view "$PR_NUMBER" --json title --jq .title)"
|
|
echo ""
|
|
echo "Description:"
|
|
gh pr view "$PR_NUMBER" --json body --jq .body
|
|
} > pr_info.txt
|
|
|
|
- name: Check for duplicate PRs
|
|
env:
|
|
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
run: |
|
|
COMMENT=$(bun script/duplicate-pr.ts -f pr_info.txt "Check the attached file for PR details and search for duplicates")
|
|
|
|
gh pr comment "$PR_NUMBER" --body "_The following comment was made by an LLM, it may be inaccurate:_
|
|
|
|
$COMMENT"
|
|
|
|
add-contributor-labels:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pull-requests: write
|
|
issues: write
|
|
steps:
|
|
- name: Add appropriate contributor labels
|
|
uses: actions/github-script@v8
|
|
with:
|
|
script: |
|
|
const prNumber = context.payload.pull_request.number;
|
|
const authorAssociation = context.payload.pull_request.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') {
|
|
await github.rest.issues.addLabels({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
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`);
|
|
}
|