Skip to content

Commit a854273

Browse files
committed
feat(copier): add support for using a PR Template in target repo
1 parent 21161b4 commit a854273

File tree

7 files changed

+536
-18
lines changed

7 files changed

+536
-18
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Example: Using PR Templates from Target Repository
2+
# This configuration demonstrates the hybrid PR template approach
3+
4+
source_repo: "myorg/source-repo"
5+
source_branch: "main"
6+
7+
copy_rules:
8+
# Example 1: Use target repo's PR template with appended copier info
9+
- name: "use-target-template-with-append"
10+
source_pattern:
11+
type: "prefix"
12+
pattern: "examples/"
13+
targets:
14+
- repo: "myorg/target-repo"
15+
branch: "main"
16+
path_transform: "code-examples/${relative_path}"
17+
commit_strategy:
18+
type: "pull_request"
19+
pr_title: "Update code examples from ${source_repo}"
20+
21+
# Fetch and use the PR template from the target repository
22+
use_target_pr_template: true
23+
24+
# Optional: Specify custom template path (defaults to .github/pull_request_template.md)
25+
pr_template_path: ".github/pull_request_template.md"
26+
27+
# Append copier-specific information after the template
28+
pr_body_append: |
29+
30+
---
31+
## 🤖 Automated Copy Information
32+
33+
This PR was automatically created by the examples-copier service.
34+
35+
- **Source Repository**: ${source_repo}
36+
- **Source Branch**: ${source_branch}
37+
- **Source PR**: #${pr_number}
38+
- **Source Commit**: ${commit_sha}
39+
- **Files Updated**: ${file_count}
40+
- **Copy Rule**: ${rule_name}
41+
42+
### Review Checklist
43+
- [ ] Verify all files copied correctly
44+
- [ ] Check for any breaking changes
45+
- [ ] Run tests locally
46+
47+
auto_merge: false
48+
49+
# Example 2: Use target repo's PR template without appending
50+
- name: "use-target-template-only"
51+
source_pattern:
52+
type: "prefix"
53+
pattern: "docs/"
54+
targets:
55+
- repo: "myorg/target-repo"
56+
branch: "main"
57+
path_transform: "documentation/${relative_path}"
58+
commit_strategy:
59+
type: "pull_request"
60+
pr_title: "Update documentation from ${source_repo}"
61+
62+
# Just use the target repo's template as-is
63+
use_target_pr_template: true
64+
65+
auto_merge: false
66+
67+
# Example 3: Traditional approach - define PR body in config
68+
- name: "define-pr-body-in-config"
69+
source_pattern:
70+
type: "prefix"
71+
pattern: "scripts/"
72+
targets:
73+
- repo: "myorg/target-repo"
74+
branch: "main"
75+
path_transform: "scripts/${relative_path}"
76+
commit_strategy:
77+
type: "pull_request"
78+
pr_title: "Update scripts from ${source_repo}"
79+
80+
# Define the entire PR body in the config
81+
pr_body: |
82+
## Automated Update
83+
84+
This PR updates scripts from the source repository.
85+
86+
### Details
87+
- **Source**: ${source_repo}
88+
- **PR**: #${pr_number}
89+
- **Commit**: ${commit_sha}
90+
- **Files**: ${file_count}
91+
92+
### Testing
93+
Please verify that all scripts work as expected.
94+
95+
auto_merge: false
96+
97+
# Example 4: Fallback behavior - template not found
98+
- name: "template-with-fallback"
99+
source_pattern:
100+
type: "prefix"
101+
pattern: "config/"
102+
targets:
103+
- repo: "myorg/target-repo"
104+
branch: "main"
105+
path_transform: "config/${relative_path}"
106+
commit_strategy:
107+
type: "pull_request"
108+
pr_title: "Update config from ${source_repo}"
109+
110+
# Try to use target template, but provide fallback via pr_body
111+
use_target_pr_template: true
112+
pr_template_path: ".github/pull_request_template.md"
113+
114+
# This will be used if the template file is not found
115+
pr_body: |
116+
## Configuration Update
117+
118+
Automated update of configuration files.
119+
120+
- Source: ${source_repo}
121+
- Files: ${file_count}
122+
123+
# This will be appended if the template IS found
124+
pr_body_append: |
125+
126+
---
127+
**Automated by**: examples-copier
128+
129+
auto_merge: false
130+

examples-copier/docs/CONFIGURATION-GUIDE.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ commit_strategy:
321321
pr_title: "Update ${lang} examples"
322322
pr_body: |
323323
Automated update of ${lang} examples
324-
324+
325325
Files updated: ${file_count}
326326
Source: ${source_repo}
327327
PR: #${pr_number}
@@ -334,12 +334,50 @@ commit_strategy:
334334
- `pr_body` - (optional) PR body template
335335
- `auto_merge` - (optional) Auto-merge if checks pass (default: false)
336336
- `commit_message` - (optional) Commit message template
337+
- `use_target_pr_template` - (optional) Fetch PR template from target repo (default: false)
338+
- `pr_template_path` - (optional) Path to PR template in target repo (default: `.github/pull_request_template.md`)
339+
- `pr_body_append` - (optional) Additional content to append after the template
337340

338341
**Use When:**
339342
- Changes require review
340343
- You want CI checks to run
341344
- Multiple approvers needed
342345

346+
#### Using PR Templates from Target Repository
347+
348+
You can configure the copier to use PR templates that exist in the target repository:
349+
350+
```yaml
351+
commit_strategy:
352+
type: "pull_request"
353+
use_target_pr_template: true
354+
pr_template_path: ".github/pull_request_template.md" # Optional, this is the default
355+
pr_body_append: |
356+
357+
---
358+
**Automated Copy Information:**
359+
- Source: ${source_repo}
360+
- PR: #${pr_number}
361+
- Commit: ${commit_sha}
362+
- Files: ${file_count}
363+
auto_merge: false
364+
```
365+
366+
**How it works:**
367+
1. The copier fetches the PR template file from the target repository
368+
2. Uses the template content as the PR body
369+
3. Optionally appends additional copier-specific information via `pr_body_append`
370+
4. If the template file is not found, falls back to using `pr_body` (if configured)
371+
372+
**Template Variables:**
373+
Both `pr_body` and `pr_body_append` support template variables like `${source_repo}`, `${pr_number}`, `${file_count}`, etc.
374+
375+
**Common PR Template Locations:**
376+
- `.github/pull_request_template.md` (default, hidden directory)
377+
- `pull_request_template.md` (root directory)
378+
- `docs/pull_request_template.md` (docs directory)
379+
- `.github/PULL_REQUEST_TEMPLATE/template_name.md` (multiple templates)
380+
343381
### Batch Commit
344382

345383
Batches multiple files into fewer commits.

0 commit comments

Comments
 (0)