# GitHub

> Connect GitHub to FlyMyAI agents.

Lets an agent read and comment on repositories you have access to on
GitHub.

## What it can do

- Search repositories, issues, and pull requests
- Read issues and PRs including comments and review threads
- Create issues and comments
- Trigger workflow dispatches (if the token has the scope)

## How to get credentials

GitHub uses a **fine-grained personal access token (PAT)**. Classic PATs
also work but we strongly recommend fine-grained for the scoped access.

1. Go to
   [github.com/settings/personal-access-tokens/new](https://github.com/settings/personal-access-tokens/new).
2. Pick **Fine-grained token**, name it (e.g. "FlyMyAI Agent"), and set
   an expiration.
3. Under **Repository access**, choose *All repositories* or the exact
   list the agent should reach.
4. Under **Repository permissions**, grant at least:
   - **Contents**: Read-only
   - **Issues**: Read and write
   - **Pull requests**: Read and write
   - **Metadata**: Read-only *(automatic)*
   - Add **Actions: Read and write** if you want workflow dispatch.
5. Click **Generate token** and copy the `github_pat_…` value - it's only
   shown once.

For org repos, an org owner may need to approve the token before it can
access those repos.

## Fields to fill in FlyMyAI

| FlyMyAI field | Where it comes from |
| --- | --- |
| `GitHub token` | The `github_pat_…` (or `ghp_…` for classic) token. |

## Troubleshooting

- **404 on a repo you can see on github.com** - token doesn't include
  that repo. Edit the PAT's *Repository access* list, or wait for org
  approval.
- **403 `Resource not accessible by personal access token`** - the scope
  is missing. Edit the token, add the permission, save. No need to
  re-paste unless you rotated the token.
- **Rate-limited** - authenticated requests get 5,000/hour per token.
  Don't share one token across many agents running heavy workloads;
  create a dedicated token per use case.

## Links

- [Create a fine-grained PAT](https://github.com/settings/personal-access-tokens/new)
- [GitHub REST API reference](https://docs.github.com/en/rest)
