Feature Request: Automated Labeling for Pull Requests
TL;DR
Implement a new GitHub Action workflow within run-gemini-cli to automatically analyze the content of a Pull Request and apply relevant labels, similar to how GitHub Issues are currently triaged.
Detailed design
This feature proposes extending the run-gemini-cli action's capabilities to include automated labeling for Pull Requests. The current system effectively triages and labels GitHub Issues, and introducing a parallel system for PRs would significantly enhance workflow efficiency and consistency across repositories.
The envisioned functionality involves a dedicated GitHub Actions workflow. This workflow would be designed to trigger automatically on key Pull Request events, such as when a PR is opened, reopened, or when new commits are pushed (synchronize). Upon triggering, the workflow would utilize the Gemini CLI to analyze the pull request's content, including its title, description, and the nature of the code changes. Based on this AI-powered analysis, the system would infer the most appropriate labels (e.g., bugfix, feature, documentation, refactor, chore) and automatically apply them to the Pull Request. This would create a cohesive and automated labeling experience that mirrors the existing issue triage process.
Sample YAML:
name: '🏷️ Gemini PR Auto-Labeler'
on:
pull_request:
types:
- 'opened'
- 'reopened'
issue_comment:
types:
- 'created'
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to triage'
required: true
type: 'number'
concurrency:
# Group by PR number to avoid concurrent runs on the same PR.
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}'
cancel-in-progress: true
defaults:
run:
shell: 'bash'
permissions:
contents: 'read'
id-token: 'write'
pull-requests: 'write' # Required to add/remove labels on PRs
statuses: 'write'
jobs:
triage-pr:
if: |-
github.event_name == 'pull_request' ||
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'issue_comment' &&
github.event.issue.pull_request && # Ensures the comment is on a PR
contains(github.event.comment.body, '@gemini-cli /triage') &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
)
timeout-minutes: 5
runs-on: 'ubuntu-latest'
steps:
- name: 'Checkout repository'
uses: 'actions/checkout@v4'
- name: 'Generate GitHub App Token'
id: 'generate_token'
if: |-
${{ vars.APP_ID }}
uses: 'actions/create-github-app-token@v2'
with:
app-id: '${{ vars.APP_ID }}'
private-key: '${{ secrets.APP_PRIVATE_KEY }}'
- name: 'Run Gemini PR Triage'
uses: 'google-github-actions/run-gemini-cli@v1'
id: 'gemini_pr_triage'
env:
# Define a single PR_NUMBER variable that works for all trigger types
PR_NUMBER: '${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}'
GITHUB_TOKEN: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
REPOSITORY: '${{ github.repository }}'
with:
gemini_cli_version: '${{ vars.GEMINI_CLI_VERSION }}'
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
settings: |-
{
"maxSessionTurns": 25,
"coreTools": [
"run_shell_command(echo)",
"run_shell_command(gh label list)",
"run_shell_command(gh pr view)",
"run_shell_command(gh pr edit)"
],
"telemetry": {
"enabled": false,
"target": "gcp"
}
}
prompt: |-
## Role
You are a pull request triage assistant. Your task is to analyze the
current GitHub pull request and apply the most appropriate existing labels.
Use the available tools to gather information; do not ask for
information to be provided.
## Steps
1. Run `gh label list` to get all available labels.
2. Run `gh pr view "${PR_NUMBER}" --json title,body` to get the PR's title and body.
3. Review the PR title and body to understand its purpose.
4. Classify the pull request by its kind (e.g., fix, feature, docs, chore, refactor)
and apply labels that match existing `kind/*` or `type/*` patterns.
5. Apply the selected labels to this pull request using:
`gh pr edit "${PR_NUMBER}" --add-label "label1,label2"`
6. If a "status/needs-triage" label exists and is on the PR, remove it using:
`gh pr edit "${PR_NUMBER}" --remove-label "status/needs-triage"`
## Guidelines
- Only use labels that already exist in the repository.
- Do not add comments or modify the pull request content.
- Triage only the current pull request identified by "${PR_NUMBER}".
- Assign all applicable labels based on the pull request content.
- Reference all shell variables as "${VAR}" (with quotes and braces).
- name: 'Post PR Triage Failure Comment'
if: failure()
uses: 'actions/github-script@v7'
with:
github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
script: |-
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }},
body: 'There was a problem while triaging this pull request with Gemini CLI. Please check the [action logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.'
})
Additional information
- Consistency Across Repository Objects: This feature ensures a uniform and automated labeling strategy for both GitHub Issues and Pull Requests, making repository management more intuitive and less prone to manual error.
- Reduced Manual Overhead: Automating PR labeling will free up maintainers and contributors from the administrative task of manually categorizing PRs, allowing them to concentrate more on code review and development.
- Improved Discoverability and Organization: Automated and consistent labeling makes it easier for teams to filter, prioritize, and track the status of pull requests, leading to better project oversight and faster turnaround times.
@samucodesh this is a great idea! did you implement it? if so, we'd love for you to share it in our awesome list: https://github.com/google-github-actions/run-gemini-cli/tree/main/examples/workflows#awesome-workflows
We won't be able to support all kinds of example workflows, but we encourage the community to build and share them in https://github.com/google-github-actions/run-gemini-cli/tree/main/examples/workflows#awesome-workflows