Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions examples-copier/configs/pr-template-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Example: Using PR Templates from Target Repository
# This configuration demonstrates the hybrid PR template approach

source_repo: "myorg/source-repo"
source_branch: "main"

copy_rules:
# Example 1: Use target repo's PR template with appended copier info
- name: "use-target-template-with-append"
source_pattern:
type: "prefix"
pattern: "examples/"
targets:
- repo: "myorg/target-repo"
branch: "main"
path_transform: "code-examples/${relative_path}"
commit_strategy:
type: "pull_request"
pr_title: "Update code examples from ${source_repo}"

# Fetch and use the PR template from the target repository
use_target_pr_template: true

# Optional: Specify custom template path (defaults to .github/pull_request_template.md)
pr_template_path: ".github/pull_request_template.md"

# Append copier-specific information after the template
pr_body_append: |

---
## 🤖 Automated Copy Information

This PR was automatically created by the examples-copier service.

- **Source Repository**: ${source_repo}
- **Source Branch**: ${source_branch}
- **Source PR**: #${pr_number}
- **Source Commit**: ${commit_sha}
- **Files Updated**: ${file_count}
- **Copy Rule**: ${rule_name}

### Review Checklist
- [ ] Verify all files copied correctly
- [ ] Check for any breaking changes
- [ ] Run tests locally

auto_merge: false

# Example 2: Use target repo's PR template without appending
- name: "use-target-template-only"
source_pattern:
type: "prefix"
pattern: "docs/"
targets:
- repo: "myorg/target-repo"
branch: "main"
path_transform: "documentation/${relative_path}"
commit_strategy:
type: "pull_request"
pr_title: "Update documentation from ${source_repo}"

# Just use the target repo's template as-is
use_target_pr_template: true

auto_merge: false

# Example 3: Traditional approach - define PR body in config
- name: "define-pr-body-in-config"
source_pattern:
type: "prefix"
pattern: "scripts/"
targets:
- repo: "myorg/target-repo"
branch: "main"
path_transform: "scripts/${relative_path}"
commit_strategy:
type: "pull_request"
pr_title: "Update scripts from ${source_repo}"

# Define the entire PR body in the config
pr_body: |
## Automated Update

This PR updates scripts from the source repository.

### Details
- **Source**: ${source_repo}
- **PR**: #${pr_number}
- **Commit**: ${commit_sha}
- **Files**: ${file_count}

### Testing
Please verify that all scripts work as expected.

auto_merge: false

# Example 4: Fallback behavior - template not found
- name: "template-with-fallback"
source_pattern:
type: "prefix"
pattern: "config/"
targets:
- repo: "myorg/target-repo"
branch: "main"
path_transform: "config/${relative_path}"
commit_strategy:
type: "pull_request"
pr_title: "Update config from ${source_repo}"

# Try to use target template, but provide fallback via pr_body
use_target_pr_template: true
pr_template_path: ".github/pull_request_template.md"

# This will be used if the template file is not found
pr_body: |
## Configuration Update

Automated update of configuration files.

- Source: ${source_repo}
- Files: ${file_count}

# This will be appended if the template IS found
pr_body_append: |

---
**Automated by**: examples-copier

auto_merge: false

40 changes: 39 additions & 1 deletion examples-copier/docs/CONFIGURATION-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ commit_strategy:
pr_title: "Update ${lang} examples"
pr_body: |
Automated update of ${lang} examples

Files updated: ${file_count}
Source: ${source_repo}
PR: #${pr_number}
Expand All @@ -334,12 +334,50 @@ commit_strategy:
- `pr_body` - (optional) PR body template
- `auto_merge` - (optional) Auto-merge if checks pass (default: false)
- `commit_message` - (optional) Commit message template
- `use_target_pr_template` - (optional) Fetch PR template from target repo (default: false)
- `pr_template_path` - (optional) Path to PR template in target repo (default: `.github/pull_request_template.md`)
- `pr_body_append` - (optional) Additional content to append after the template

**Use When:**
- Changes require review
- You want CI checks to run
- Multiple approvers needed

#### Using PR Templates from Target Repository

You can configure the copier to use PR templates that exist in the target repository:

```yaml
commit_strategy:
type: "pull_request"
use_target_pr_template: true
pr_template_path: ".github/pull_request_template.md" # Optional, this is the default
pr_body_append: |

---
**Automated Copy Information:**
- Source: ${source_repo}
- PR: #${pr_number}
- Commit: ${commit_sha}
- Files: ${file_count}
auto_merge: false
```

**How it works:**
1. The copier fetches the PR template file from the target repository
2. Uses the template content as the PR body
3. Optionally appends additional copier-specific information via `pr_body_append`
4. If the template file is not found, falls back to using `pr_body` (if configured)

**Template Variables:**
Both `pr_body` and `pr_body_append` support template variables like `${source_repo}`, `${pr_number}`, `${file_count}`, etc.

**Common PR Template Locations:**
- `.github/pull_request_template.md` (default, hidden directory)
- `pull_request_template.md` (root directory)
- `docs/pull_request_template.md` (docs directory)
- `.github/PULL_REQUEST_TEMPLATE/template_name.md` (multiple templates)

### Batch Commit

Batches multiple files into fewer commits.
Expand Down
Loading