> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/ai-sre/ai-sre-for-administrators/set-up-runbook-management/integrations/source-control/github.md).

# GitHub Integration

Automate GitHub pull request creation and tracking from AI SRE runbooks to link code fixes back to an incident.

Integrate GitHub with AI SRE runbooks to automate pull request management during incident response.

### Use cases <a href="#use-cases" id="use-cases"></a>

Use GitHub runbook actions to:

* Create pull requests for hotfixes
* List open pull requests for incident correlation
* Track incident remediation through pull requests
* Automate PR creation for code changes

***

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* GitHub account with repository access
* GitHub personal access token or GitHub App
* Repository permissions: repo, read:org (minimum)

***

### Configure the GitHub integration <a href="#configure-the-github-integration" id="configure-the-github-integration"></a>

Set up the connector with these steps:

1. Go to **Project Settings**, then **Third-Party Integrations for AI SRE**.

   ![Third-Party Integrations for AI SRE](https://2800896578-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwfoiKanOBqsfhP1BJKpx%2Fuploads%2Fgit-blob-37244248e40f71fcc0afc129e4539f65551812dc%2Fthird-party-integrations-connectors.png?alt=media)
2. Select the connector you want to use or create a new one.
3. Provide your GitHub credentials:
   * **Personal Access Token:** Generate from GitHub settings
   * **Permissions:** repo, read:org (minimum)
4. Test the connection.
5. Save the integration.

***

### Available actions <a href="#available-actions" id="available-actions"></a>

#### Create pull request <a href="#create-pull-request" id="create-pull-request"></a>

Create a pull request in a GitHub repository.

**Required fields:**

* Owner: Repository owner (user or organization)
* Repository: Repository name
* Source Branch: Branch with changes
* Target Branch: Branch to merge into
* Title: Pull request title
* Body: Pull request description (optional)

#### List pull requests <a href="#list-pull-requests" id="list-pull-requests"></a>

List pull requests from a GitHub repository.

**Required fields:**

* Owner: Repository owner (user or organization)
* Repository: Repository name
* State: Filter by state (open, closed, or all)

***

### Use GitHub actions in runbooks <a href="#use-github-actions-in-runbooks" id="use-github-actions-in-runbooks"></a>

GitHub actions are configured through the runbook action form in the UI:

1. **In your runbook**, click **New Step**, then **Action**.

   ![New Step Menu](https://2800896578-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwfoiKanOBqsfhP1BJKpx%2Fuploads%2Fgit-blob-d6dffd9114e1a1085c8d3178fe25d3a125df1d23%2Frunbook-new-step-menu.png?alt=media)
2. In the **Select Action** dialog, go to the **Tickets & Code** category.
3. Select **GitHub** from the available actions.

   ![Select Action Dialog](https://2800896578-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwfoiKanOBqsfhP1BJKpx%2Fuploads%2Fgit-blob-dd5b07dbc39eab7e3dbb6766201f1d6a6be64a8c%2Faction-list-github-pull-requests.png?alt=media)
4. Choose the action type (**Create GitHub Pull Request** or **List GitHub Pull Requests**).
5. Fill in the form fields using the **Data Picker** to insert dynamic values like `incident.severity`, `incident.title`, etc.

***

### Available Mustache variables <a href="#available-mustache-variables" id="available-mustache-variables"></a>

Use these variables to map AI SRE incident data to GitHub fields:

| Variable                   | Description                 | Example Value                           |
| -------------------------- | --------------------------- | --------------------------------------- |
| `{{Activity.title}}`       | Incident title              | `API Gateway Outage`                    |
| `{{Activity.summary}}`     | Incident summary            | `Payment API returning 500 errors`      |
| `{{Activity.severity}}`    | Incident severity           | `0`, `1`, `2`, `3`, `4`                 |
| `{{Activity.status}}`      | Incident status             | `Detected`, `Investigating`, `Resolved` |
| `{{Activity.service}}`     | Affected service name       | `payment-service`                       |
| `{{Activity.environment}}` | Environment                 | `production`, `staging`                 |
| `{{Activity.owner}}`       | Incident owner email        | `jane.doe@company.com`                  |
| `{{Activity.created_at}}`  | Incident creation timestamp | `2026-05-06T20:30:00Z`                  |
| `{{Activity.url}}`         | Incident URL in AI SRE      | `https://app.harness.io/...`            |
| `{{Activity.id}}`          | Unique incident identifier  | `abc123...`                             |
| `{{Activity.short_id}}`    | Human-readable ID           | `INC-123`                               |

***

### Example runbook actions <a href="#example-runbook-actions" id="example-runbook-actions"></a>

#### Create a pull request for a fix <a href="#create-a-pull-request-for-a-fix" id="create-a-pull-request-for-a-fix"></a>

**Use case:** Create a pull request for incident remediation with full context.

**Runbook configuration:**

1. In the runbook editor, add a **Create GitHub Pull Request** action.
2. Configure the form fields:
   * **Owner:** `myorg`
   * **Repository:** `payment-service`
   * **Source Branch:** `hotfix/incident-{{Activity.short_id}}`
   * **Target Branch:** `main`
   * **Title:** `Fix for incident {{Activity.short_id}}: {{Activity.title}}`
   * **Body:**

     ```markdown
     ## Incident Fix

     **Incident**: [{{Activity.short_id}}]({{Activity.url}})
     **Severity**: SEV{{Activity.severity}}
     **Service**: {{Activity.service}}
     **Environment**: {{Activity.environment}}

     ### Description
     {{Activity.title}}

     ### Related
     - Incident URL: {{Activity.url}}
     ```

**Result:** Pull request created with title `Fix for incident INC-123: API Gateway Outage` targeting `main` from `hotfix/incident-INC-123`.

#### List open pull requests <a href="#list-open-pull-requests" id="list-open-pull-requests"></a>

**Use case:** List all open pull requests to check for existing fixes before creating a new one.

**Runbook configuration:**

1. In the runbook editor, add a **List GitHub Pull Requests** action.
2. Configure the form fields:
   * **Owner:** `myorg`
   * **Repository:** `payment-service`
   * **State:** `open`

**Result:** Returns a list of all open pull requests in the repository with details including title, branch, and URL.

#### Create a hotfix PR with context <a href="#create-a-hotfix-pr-with-context" id="create-a-hotfix-pr-with-context"></a>

**Use case:** Create a pull request with detailed incident context and action items.

**Runbook configuration:**

1. In the runbook editor, add a **Create GitHub Pull Request** action.
2. Configure the form fields:
   * **Owner:** `myorg`
   * **Repository:** `payment-service`
   * **Source Branch:** `hotfix/{{Activity.short_id}}-{{Activity.service}}`
   * **Target Branch:** `main`
   * **Title:** `[SEV{{Activity.severity}}] {{Activity.title}}`
   * **Body:**

     ```markdown
     ## Hotfix for Incident {{Activity.short_id}}

     **Status**: {{Activity.status}}
     **Service**: {{Activity.service}}
     **Environment**: {{Activity.environment}}
     **Detected**: {{Activity.created_at}}

     ### Incident Summary
     {{Activity.summary}}

     ### Action Items
     - [ ] Code changes implemented
     - [ ] Tests added
     - [ ] Reviewed and approved
     - [ ] Ready to deploy

     ### Links
     - [Incident Details]({{Activity.url}})

     cc: {{Activity.owner}}
     ```

**Result:** Pull request created with full incident context and checklist for tracking remediation progress.

***

### PR title conventions <a href="#pr-title-conventions" id="pr-title-conventions"></a>

Use consistent PR title formats for incident-related pull requests:

**By severity:**

* SEV0/SEV1: `[SEV0] {{Activity.title}}`
* SEV2+: `Fix: {{Activity.title}}`

**By type:**

* Hotfix: `Hotfix/{{Activity.short_id}}: {{Activity.title}}`
* Investigation: `Investigation/{{Activity.short_id}}: {{Activity.title}}`
* Post-incident: `Post-incident/{{Activity.short_id}}: {{Activity.title}}`

***

### Branch naming conventions <a href="#branch-naming-conventions" id="branch-naming-conventions"></a>

Use consistent branch naming for incident-related work:

```yaml
# Pattern examples: <a href="#pattern-examples" id="pattern-examples"></a>
hotfix/incident-{{Activity.short_id}}
fix/{{Activity.service}}-{{Activity.short_id}}
incident/{{Activity.short_id}}-{{Activity.severity}}
```

***

### Security best practices <a href="#security-best-practices" id="security-best-practices"></a>

Follow these practices to secure the GitHub integration:

* Use fine-grained personal access tokens
* Limit repository access to only what is needed
* Rotate tokens regularly
* Use GitHub Apps for organization-wide access
* Enable two-factor authentication
* Audit integration usage regularly

***

### Next steps <a href="#next-steps" id="next-steps"></a>

* [Configure Runbook Actions](/ai-sre/ai-sre-for-administrators/set-up-runbook-management/create-runbook.md): Add GitHub actions to runbooks.
* [Runbook Best Practices](/ai-sre/ai-sre-for-administrators/set-up-runbook-management/workflows/best-practices.md): Review automation patterns.

{% @harness-feedback/feedback %}
