# GitHub Config File Updater

> Update config files in GitHub repos without cloning. Read, modify, branch, commit, and open a PR in one step.

Source: https://cotera.co/solutions/ops/github-config-file-updater

---

- **Team:** Operations
- **Tools:** GitHub
- **Difficulty:** medium
- **Setup time:** 10 min
- **Time saved:** 15 min/update

## How it works
1. **Read Config** — Fetches the current file contents from the repo so you can see exactly what needs to change
2. **Apply Changes** — Modifies the file based on your instructions while preserving formatting and structure
3. **Branch & Commit** — Creates a new branch and commits the updated file with a descriptive commit message
4. **Open PR** — Opens a pull request with a clear title and description ready for review

## Example requests
- In acme/web-app, update package.json to set engines.node to >=20.0.0
- Add a new env var DATABASE_POOL_SIZE=10 to the .env.example in our backend repo
- Bump the Terraform AWS provider version to 5.40.0 in infra/main.tf

## Prompt

```markdown
## Task

Use @GitHub/Read File to fetch a config file from a repo, modify it based on user instructions, then use @GitHub/Get Branch SHA, @GitHub/Create Branch, @GitHub/Update File, and @GitHub/Create Pull Request to commit the change on a new branch and open a PR. Automates routine config updates without cloning the repo.

## Input

The user provides:
1. The repository owner and name (e.g., "acme/web-app")
2. The file path to update (e.g., "package.json", ".env.example", "terraform/variables.tf")
3. The specific change to make (e.g., "bump Node version to 20", "add a new env var called API_TIMEOUT with default 30s")
4. The target branch to base the PR on (optional, defaults to "main")

**Example:** "In acme/web-app, update package.json to set the engines.node field to >=20.0.0"

## Context

### Read the Current File

1. Use @GitHub/Read File to fetch the current contents of the target file from the specified branch
2. Parse the file content to understand its structure (JSON, YAML, HCL, etc.)
3. Identify the specific section or field that needs to change

### Apply the Modification

1. Make the requested change to the file content
2. Preserve formatting, indentation, and comments where possible
3. Validate the modified content is syntactically correct for its file type
4. Show the user a diff of what changed before proceeding

### Create Branch and Commit

1. Use @GitHub/Get Branch SHA to get the current SHA of the base branch
2. Use @GitHub/Create Branch to create a new branch (e.g., "update/package-json-node-version")
3. Use @GitHub/Update File to commit the modified file to the new branch
4. Use a descriptive commit message that explains the change

### Open a Pull Request

1. Use @GitHub/Create Pull Request to open a PR from the new branch to the base branch
2. Include a clear title describing the config change
3. Add a description explaining what was changed and why

## Output

**Config Update Summary:**

**Repository:** [owner/repo]
**File:** [file path]
**Branch:** [new branch name] -> [base branch]

**Change Made:**
- [Description of the specific modification]

**Diff:**
```
[before/after comparison]
```

**Pull Request:** [PR URL]
**Status:** Ready for review
```

## Related reading
- [We Automated Our GitHub Pull Requests. Code Reviews Got Faster.](https://cotera.co/articles/automate-github-pull-requests.md)
- [GitHub Actions Hit Our Limits. An AI Agent Handled the Rest.](https://cotera.co/articles/github-actions-alternative-guide.md)

