# GitHub PR Template Generator

> Generate PR templates, issue templates, and CODEOWNERS files for GitHub repos based on your team's patterns.

Source: https://cotera.co/solutions/ops/github-pr-template-generator

---

- **Team:** Operations
- **Tools:** GitHub
- **Difficulty:** easy
- **Setup time:** 5 min
- **Time saved:** 30 min/repo

## How it works
1. **Analyze Project** — Reads existing code to understand the tech stack, testing tools, and team structure
2. **Generate Templates** — Creates PR and issue templates with checklists tailored to your project type
3. **Map Ownership** — Builds a CODEOWNERS file mapping directories to the right teams and individuals
4. **Open PR** — Commits all templates to a new branch and opens a PR for the team to review

## Example requests
- Generate PR and issue templates for acme/web-app with frontend and backend teams
- Create a CODEOWNERS file for our monorepo based on the directory structure
- Add issue templates for bug reports and feature requests to acme/api

## Prompt

```markdown
## Task

Use @GitHub/Read File to understand existing code patterns and team structure, then generate PR templates, issue templates, and CODEOWNERS files tailored to the project. Use @GitHub/Get Branch SHA, @GitHub/Create Branch, @GitHub/Create File, and @GitHub/Create Pull Request to commit the new templates and open a PR.

## Input

The user provides:
1. The repository owner and name (e.g., "acme/web-app")
2. What templates to generate (PR template, issue templates, CODEOWNERS, or all)
3. Team structure or ownership info (optional, e.g., "frontend team owns src/components, backend team owns src/api")
4. Any specific sections or checklist items they want included

**Example:** "Generate PR and issue templates for acme/web-app. We have frontend and backend teams."

## Context

### Analyze Existing Patterns

1. Use @GitHub/Read File to check if any templates already exist in .github/
2. Read package.json or equivalent to understand the project type (frontend, backend, monorepo)
3. Check for existing CODEOWNERS file
4. Look at the project structure to infer team ownership areas
5. Check for testing frameworks, linting tools, and CI workflows to inform checklist items

### Generate PR Template

1. Create a pull_request_template.md with sections based on the project type:
   - Summary of changes
   - Type of change (feature, bug fix, refactor, etc.)
   - Testing checklist appropriate to the project (unit tests, integration tests, manual testing)
   - Reviewer notes
   - Screenshots section for frontend projects
   - Migration notes for backend projects with databases
2. Include checkboxes for common PR hygiene items

### Generate Issue Templates

1. Create bug_report.md with structured fields for reproduction steps, expected vs actual behavior, and environment info
2. Create feature_request.md with sections for problem description, proposed solution, and alternatives considered
3. Create a config.yml for the issue template chooser if the repo uses GitHub Issues

### Generate CODEOWNERS

1. Map team ownership based on directory structure and user input
2. Set default reviewers for the root
3. Assign specific paths to appropriate teams or individuals

### Create Branch and PR

1. Use @GitHub/Get Branch SHA to get the current SHA of the default branch
2. Use @GitHub/Create Branch to create a new branch (e.g., "add/github-templates")
3. Use @GitHub/Create File to add each template file to the new branch
4. Use @GitHub/Create Pull Request to open a PR with a summary of all generated templates

## Output

**Templates Generated:**

**Repository:** [owner/repo]
**Branch:** [new branch name]

**Files Created:**
- .github/pull_request_template.md - PR template with [X] checklist items
- .github/ISSUE_TEMPLATE/bug_report.md - Bug report template
- .github/ISSUE_TEMPLATE/feature_request.md - Feature request template
- .github/ISSUE_TEMPLATE/config.yml - Issue template chooser config
- .github/CODEOWNERS - Code ownership mapping

**PR Template Highlights:**
- Includes [testing framework] checklist items
- [Frontend/Backend] specific sections included
- Change type classification with checkboxes

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

## Related reading
- [AI Code Review on GitHub: Copilot vs CodeRabbit vs an Agent That Reads Your Codebase](https://cotera.co/articles/ai-code-review-github.md)
- [We Tried Using GitHub for Project Management. Here's Where It Broke.](https://cotera.co/articles/github-project-management-guide.md)

