Skip to content

Add GitHub client method to create pull requests with configurable branch prefixes, nanoid generation, and automatic copilot assignment #1486

Add GitHub client method to create pull requests with configurable branch prefixes, nanoid generation, and automatic copilot assignment

Add GitHub client method to create pull requests with configurable branch prefixes, nanoid generation, and automatic copilot assignment #1486

name: genai commander
permissions:
contents: read
pull-requests: write
models: read
on:
issue_comment:
types: [created]
jobs:
pr_commented:
# must be PR and have a comment starting with /genai
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/genai ') }}
runs-on: ubuntu-latest
steps:
# only allow PRs from the same repository
- name: Check if PR is from the same repository
id: check_pr
uses: actions/github-script@v7
with:
script: |
const { owner, repo, number } = context.issue;
const pr = await github.rest.pulls.get({ owner, repo, pull_number: number });
if(pr.data.head.repo.full_name !== `${owner}/${repo}`)
throw new Error("pull request is not from the same repository");
# only allow comments from collaborators
- name: Check if comment author is a collaborator
id: check_author
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const commentAuthor = context.payload.comment.user.login;
const { data: collaborators } = await github.rest.repos.listCollaborators({ owner, repo });
const isCollaborator = collaborators.some(collaborator => collaborator.login === commentAuthor);
if (!isCollaborator)
throw new Error(`user ${commentAuthor} is not a collaborator on this repository`);
#
# Resolve the PR sha and ref
#
- name: resolve pr sha
id: sha
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const { owner, repo, number } = context.issue;
const pr = await github.rest.pulls.get({ owner, repo, pull_number: number, });
const res = { sha: pr.data.head.sha, ref: pr.data.head.ref }
console.log(res)
return JSON.stringify(res)
#
# Checkout both dev and PR branches
#
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: diff PR branch
run: git diff origin/dev...origin/${{ fromJSON(steps.sha.outputs.result).ref }}
- name: diff PR commit
run: git diff origin/dev...${{ fromJSON(steps.sha.outputs.result).sha }}
- name: checkout PR commit
run: git checkout ${{ fromJSON(steps.sha.outputs.result).sha }}
- name: diff dev
run: git diff origin/dev
#
# Setup and build project
#
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: yarn
- name: install dependencies
run: yarn install --frozen-lockfile
- name: compile
run: yarn compile
- name: genaiscript pr-describe
if: startsWith(github.event.comment.body, '/genai describe')
run: node packages/cli/built/genaiscript.cjs run pr-describe -p github -prd --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
env:
GITHUB_ISSUE: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_COMMIT_SHA: ${{ fromJSON(steps.sha.outputs.result).sha }}
- name: genaiscript pr-review
if: startsWith(github.event.comment.body, '/genai review')
run: node packages/cli/built/genaiscript.cjs run pr-review -p github -prc --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
env:
GITHUB_ISSUE: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_COMMIT_SHA: ${{ fromJSON(steps.sha.outputs.result).sha }}