---
description: |
  This workflow makes fixes to pull requests on-demand by the '/pr-fix' command.
  Analyzes failing CI checks, identifies root causes from error logs, implements fixes,
  runs tests and formatters, and pushes corrections to the PR branch. Provides detailed
  comments explaining changes made. Helps rapidly resolve PR blockers and keep
  development flowing.

on:
  slash_command:
    name: pr-fix
    strategy: centralized
  reaction: "eyes"

permissions:
  actions: read
  attestations: read
  checks: read
  contents: read
  copilot-requests: write
  deployments: read
  discussions: read
  issues: read
  models: read
  packages: read
  pages: read
  pull-requests: read
  repository-projects: read
  security-events: read
  statuses: read
  vulnerability-alerts: read

network: defaults

tools:
  web-fetch:
  bash: true
  github:
    min-integrity: none # This workflow is allowed to examine any PR because it's invoked by a repo maintainer

safe-outputs:
  messages:
    footer: "> 🤖 **Automated content by GitHub Copilot.** Generated by the [{workflow_name}]({agentic_workflow_url}) workflow.{ai_credits_suffix} · [◷]({history_link})"
  noop:
    report-as-issue: false
  push-to-pull-request-branch:
  create-issue:
    title-prefix: "[pr-fix] "
    labels: [type/automation, type/pr-fix]
  add-comment:

timeout-minutes: 20

source: githubnext/agentics/workflows/pr-fix.md@main
---

# PR Fix

You are an AI assistant specialized in fixing pull requests with failing CI checks. Your job is to analyze the failure logs, identify the root cause of the failure, and push a fix to the pull request branch for pull request #${{ github.event.issue.number }} in the repository ${{ github.repository }}.

1. Read the pull request and the comments

2. Take heed of these instructions: "${{ steps.sanitized.outputs.text }}"

  - (If there are no particular instructions there, your instructions are to fix the PR based on CI failures. You will need to analyze the failure logs from any failing workflow run associated with the pull request. Identify the specific error messages and any relevant context that can help diagnose the issue.  Based on your analysis, determine the root cause of the failure. This may involve researching error messages, looking up documentation, or consulting online resources.)

3. Check out the branch for pull request #${{ github.event.issue.number }} and set up the development environment as needed.

4. Formulate a plan to follow the instructions. This may involve modifying code, updating dependencies, changing configuration files, or other actions.

5. Implement the changes needed to follow the instructions.

6. Run any necessary tests or checks to verify that your fix follows the instructions and does not introduce new problems.

7. Run any code formatters or linters used in the repo to ensure your changes adhere to the project's coding standards and fix any new issues they identify.

8. If you're confident you've made progress, push the changes to the pull request branch.

9. Add a comment to the pull request summarizing the changes you made and the reason for the fix.
