Skip to content

Commit e731296

Browse files
Copilotpelikhan
andauthored
feat: add PR reviewer patterns workshop activities (step 13 + 3 side quests) (#1912)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent fc2dc3c commit e731296

7 files changed

Lines changed: 419 additions & 1 deletion

.github/skills/micro-environment-simulator/workshop-student-journey.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const STEP_FILE_ALIASES = {
5252
"08b-interpret-your-run": ["08b-interpret-your-run.md"],
5353
"09-agentic-editing": ["09-agentic-editing.md"],
5454
"12-test-and-iterate": ["12-test-and-iterate.md"],
55+
"13-pr-reviewer-workflow": ["13-pr-reviewer-workflow.md"],
5556
"14-next-steps": ["14-next-steps.md"],
5657
"15-conditional-logic": ["15-conditional-logic.md"],
5758
"16-connect-data-source": ["16-connect-data-source.md"],
@@ -81,6 +82,7 @@ const STEP_IDS = [
8182
"08b-interpret-your-run",
8283
"09-agentic-editing",
8384
"12-test-and-iterate",
85+
"13-pr-reviewer-workflow",
8486
"14-next-steps",
8587
"15-conditional-logic",
8688
"16-connect-data-source",

workshop/12-test-and-iterate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ If you want a stricter review loop, score each run for accuracy, completeness, a
9595
- [ ] I compared the new run with the previous run and decided what to change next
9696

9797
<!-- journey: all -->
98-
**Next:** [What's Next? Keep Exploring](14-next-steps.md)
98+
**Next:** [Build Your First Event-Driven Workflow: PR Auto-Reviewer](13-pr-reviewer-workflow.md)
9999
<!-- /journey -->
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<!-- page-journey: all -->
2+
<!-- page-adventure: advanced -->
3+
# Build Your First Event-Driven Workflow: PR Auto-Reviewer
4+
5+
_You've built a scheduled workflow. Now build one that fires when something happens — and posts a useful review the moment a pull request opens._
6+
7+
## 🎯 What You'll Do
8+
9+
Create a new agentic workflow triggered by the `pull_request` event. When a contributor opens or updates a PR, your workflow will read the changed files and the PR description, then post an automated review comment summarising what changed and flagging anything worth a second look.
10+
11+
By the end you will have a working PR reviewer workflow and understand how event-driven triggers differ from scheduled ones.
12+
13+
## 📋 Before You Start
14+
15+
- You have a working `daily-report-status` workflow from [Test and Improve Your Workflow](12-test-and-iterate.md).
16+
- You understand the two-file structure (`.md` source + `.lock.yml`) from earlier steps.
17+
18+
## Why Event-Driven Triggers?
19+
20+
Your daily-status workflow runs on a schedule — it wakes up on its own, checks what happened, and reports. A PR reviewer workflow is different: it runs the moment a developer opens or updates a pull request, with the full PR context handed to it automatically.
21+
22+
This is the `pull_request` trigger:
23+
24+
```yaml
25+
on:
26+
pull_request:
27+
types: [opened, synchronize]
28+
```
29+
30+
`opened` fires when a PR is first created. `synchronize` fires every time a new commit is pushed to the PR branch. Together they cover the full PR lifecycle without any manual intervention.
31+
32+
Event-driven workflows are the foundation of most real-world agentic review automation. The same pattern powers auto-labellers, summary generators, and quality checklists — three of which you can explore in the side quests at the end of this step.
33+
34+
## Create the Workflow File
35+
36+
In your practice repository, create `.github/workflows/pr-reviewer.md`:
37+
38+
```markdown
39+
---
40+
name: PR Auto-Reviewer
41+
on:
42+
pull_request:
43+
types: [opened, synchronize]
44+
permissions:
45+
pull-requests: write
46+
contents: read
47+
safe-outputs:
48+
create-issue-comment:
49+
limit: 1
50+
---
51+
52+
You are a helpful PR reviewer. When a pull request is opened or updated:
53+
54+
1. Read the list of changed files and the PR title and description.
55+
2. Write a short summary (3–5 sentences) of what the PR does.
56+
3. List up to three things a reviewer should pay close attention to, based on the file names and PR description alone.
57+
4. Post the summary and checklist as a single comment on the pull request.
58+
59+
Keep the tone constructive and specific. Do not speculate about code you have not seen.
60+
```
61+
62+
A few things to notice in this frontmatter:
63+
64+
- `permissions: pull-requests: write` lets the agent post a comment on the PR.
65+
- `safe-outputs: create-issue-comment: limit: 1` caps the workflow at one comment per run, preventing spam if the workflow is triggered repeatedly.
66+
- The agent brief uses only information available in the trigger context (changed file paths, PR title, PR description) — it does not need to read raw file contents to produce a useful first-pass review.
67+
68+
## Compile and Push
69+
70+
From your repository root, compile the workflow:
71+
72+
```bash
73+
gh aw compile
74+
```
75+
76+
Then commit both files:
77+
78+
```bash
79+
git add .github/workflows/pr-reviewer.md .github/workflows/pr-reviewer.lock.yml
80+
git commit -m "feat: add PR auto-reviewer workflow"
81+
git push
82+
```
83+
84+
> [!TIP]
85+
> If you want to watch the compiler update the lock file every time you save, run `gh aw compile --watch` instead and keep it running in a background terminal while you edit.
86+
87+
## Test It by Opening a PR
88+
89+
Create a small branch with a trivial change — for example, add a comment to any file — and open a pull request against your default branch.
90+
91+
The workflow fires automatically within a few seconds of the PR being created. To watch it:
92+
93+
1. Go to the **Actions** tab of your repository.
94+
2. Find the **PR Auto-Reviewer** run next to your pull request.
95+
3. Open the run and watch the agent step process the PR context.
96+
4. Navigate back to the pull request and check the **Conversation** tab — your automated review comment should appear there.
97+
98+
![PR auto-reviewer comment posted by the workflow](images/13-pr-reviewer-comment.svg)
99+
100+
## Inspect the Agent's Reasoning
101+
102+
Open the run log and look for the agent's `[plan]` and `[tool]` lines. You should see the agent:
103+
104+
1. Reading the PR metadata (title, description, file list).
105+
2. Planning its summary based on available context.
106+
3. Calling the `create-issue-comment` tool to post the result.
107+
108+
If the agent posted a comment but it feels generic, the brief is working but may need tightening. Try adding a sentence like:
109+
110+
```text
111+
When the PR only touches test files, note that explicitly and skip the "things to watch" list.
112+
```
113+
114+
Then recompile, push, and update the PR branch to trigger another run.
115+
116+
## ✅ Checkpoint
117+
118+
- [ ] I created `.github/workflows/pr-reviewer.md` with a `pull_request` trigger
119+
- [ ] `gh aw compile` completed without errors and `.lock.yml` is committed and pushed
120+
- [ ] I opened a test pull request and the workflow triggered automatically
121+
- [ ] The workflow posted exactly one comment on my pull request
122+
- [ ] I can explain why `safe-outputs: create-issue-comment: limit: 1` matters for an event-driven workflow
123+
124+
<!-- journey: all -->
125+
**Next:** [What's Next? Keep Exploring](14-next-steps.md)
126+
<!-- /journey -->
127+
128+
---
129+
130+
## Go Further: PR Reviewer Patterns
131+
132+
Ready to extend this workflow? These side quests each cover a popular PR reviewer pattern:
133+
134+
- [Pattern: Auto-Label PRs by Content](side-quest-13-01-pr-labeler-pattern.md) — apply labels based on which files changed.
135+
- [Pattern: Generate a PR Summary Comment](side-quest-13-02-pr-summary-pattern.md) — post a structured summary that PR authors can use as a release note draft.
136+
- [Pattern: PR Review Checklist](side-quest-13-03-pr-checklist-pattern.md) — check PRs against a quality checklist and post results.

workshop/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ A hands-on workshop that takes you from zero to a fully automated, AI-powered wo
2626
| 8b | [Interpret Your First Run](08b-interpret-your-run.md) |
2727
| 9 | [Refine Your Workflow with Agentic Editing](09-agentic-editing.md) |
2828
| 12 | [Test and Improve Your Workflow](12-test-and-iterate.md) |
29+
| 13 | [Build Your First Event-Driven Workflow: PR Auto-Reviewer](13-pr-reviewer-workflow.md) |
2930
| 14 | [What's Next? Keep Exploring](14-next-steps.md) |
3031

3132
## Curriculum — Part 2: Go Deeper
@@ -59,6 +60,9 @@ A hands-on workshop that takes you from zero to a fully automated, AI-powered wo
5960
- [Jailbreaking the Agent Brief](side-quest-10-02-jailbreak-brief.md) — explains how adversarial instructions embedded in repository content attempt to override the agent's task brief, and how the compiled brief, minimal `permissions:`, `safe-outputs`, and `network.allowed-domains` contain any partial success; branches from [Step 10](09-agentic-editing.md).
6061
- [Frontmatter Deep Dive — Part A](side-quest-11-01-frontmatter-deep-dive.md) — walkthrough of the opening, trigger, and permissions sections of `gh-aw` frontmatter, with predict-and-try activities; branches from [Step 11a](07-your-first-workflow.md).
6162
- [Frontmatter Deep Dive — Part B](side-quest-11-08-frontmatter-tools-outputs.md) — walkthrough of the tools, safe-outputs, closing fence, and agent body sections, with predict-and-try activities; continues from Part A.
63+
- [Pattern: Auto-Label PRs by Content](side-quest-13-01-pr-labeler-pattern.md) — apply labels automatically based on which files changed in a pull request; branches from [Step 13](13-pr-reviewer-workflow.md).
64+
- [Pattern: Generate a PR Summary Comment](side-quest-13-02-pr-summary-pattern.md) — post a structured, changelog-ready summary comment when a pull request opens; branches from [Step 13](13-pr-reviewer-workflow.md).
65+
- [Pattern: PR Review Checklist](side-quest-13-03-pr-checklist-pattern.md) — evaluate pull requests against a quality checklist and post a pass/fail table; branches from [Step 13](13-pr-reviewer-workflow.md).
6266
- [Fuzzy Schedule Expressions](side-quest-13-01-schedule-expressions.md) — quick reference for choosing between `daily`, `hourly`, `weekly`, and other fuzzy schedule expressions; branches from [Step 13](12-test-and-iterate.md).
6367
- [Evaluating and Iterating on Agent Output](side-quest-12-01-iterate-agent-output.md) — structured rubric for judging output quality, a five-row problem-to-fix reference table, and a one-change-at-a-time iteration loop; branches from [Step 12](12-test-and-iterate.md).
6468
- [GitHub Actions Expressions and Contexts](side-quest-15-01-expressions-and-contexts.md) — deep dive into `${{ }}` syntax, available context objects, output references, and `if:` conditions; branches from [Step 15](15-conditional-logic.md).
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!-- page-journey: all -->
2+
<!-- page-adventure: side-quest -->
3+
# Side Quest 13-01: Pattern — Auto-Label PRs by Content
4+
5+
## 🎯 What You'll Do
6+
7+
Extend your PR reviewer workflow to automatically apply GitHub labels based on the files that changed in a pull request.
8+
9+
## Before You Start
10+
11+
- Complete [Build Your First Event-Driven Workflow: PR Auto-Reviewer](13-pr-reviewer-workflow.md).
12+
- Your practice repository has at least one label already created. If not, go to **Issues → Labels** in your repository and create labels like `documentation`, `tests`, and `bug-fix`.
13+
14+
## Why Auto-Labelling?
15+
16+
Labels help teams filter and prioritise pull requests at a glance. Applying them manually is easy to forget, especially on busy repositories. An agentic labeller reads the list of changed files and applies the right labels before a human reviewer opens the PR.
17+
18+
The pattern is simple: map file path patterns to label names in your workflow brief, then instruct the agent to pick and apply the matching labels.
19+
20+
## The Labeller Workflow
21+
22+
Create `.github/workflows/pr-labeler.md`:
23+
24+
```markdown
25+
---
26+
name: PR Labeler
27+
on:
28+
pull_request:
29+
types: [opened, synchronize]
30+
permissions:
31+
pull-requests: write
32+
contents: read
33+
safe-outputs:
34+
add-labels-to-pull-request:
35+
limit: 5
36+
---
37+
38+
You are a pull request labeller. When a pull request is opened or updated:
39+
40+
1. Read the list of changed files from the pull request context.
41+
2. Apply labels to the pull request using these rules:
42+
- If any changed file is under `docs/` or has a `.md` extension → apply `documentation`
43+
- If any changed file is under `tests/` or has a `.test.` or `.spec.` pattern → apply `tests`
44+
- If the PR title or description contains the word "fix" or "bug" (case-insensitive) → apply `bug-fix`
45+
3. Apply only the labels that match. Do not remove labels already present.
46+
4. If no rule matches, do not apply any label and do not post a comment.
47+
```
48+
49+
Compile and push:
50+
51+
```bash
52+
gh aw compile
53+
git add .github/workflows/pr-labeler.md .github/workflows/pr-labeler.lock.yml
54+
git commit -m "feat: add PR labeller workflow"
55+
git push
56+
```
57+
58+
## Test It
59+
60+
Open a test pull request that touches a Markdown file. After the workflow runs, check the pull request sidebar — the `documentation` label should appear automatically.
61+
62+
Then open another PR that touches a test file and verify the `tests` label is applied.
63+
64+
## Hands-On Exercise
65+
66+
The current rules use simple path patterns. Extend the labeller to also apply a `config-change` label when any file under `.github/` or named `*.yaml` / `*.yml` changes.
67+
68+
<details>
69+
<summary>Show one way to add this rule</summary>
70+
71+
Add this rule to the workflow brief:
72+
73+
```text
74+
- If any changed file is under `.github/` or has a `.yaml` or `.yml` extension → apply `config-change`
75+
```
76+
77+
Compile, push, and test with a PR that changes a workflow file.
78+
79+
</details>
80+
81+
## ✅ Checkpoint
82+
83+
- [ ] I created `.github/workflows/pr-labeler.md` with a `pull_request` trigger
84+
- [ ] `gh aw compile` completed without errors and `.lock.yml` is committed and pushed
85+
- [ ] I opened a test PR and the workflow applied the correct label automatically
86+
- [ ] I can explain why `safe-outputs: add-labels-to-pull-request` is the right surface for this pattern
87+
- [ ] I extended the labeller to handle at least one additional file-path rule
88+
89+
<!-- journey: all -->
90+
<!-- /journey -->
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!-- page-journey: all -->
2+
<!-- page-adventure: side-quest -->
3+
# Side Quest 13-02: Pattern — Generate a PR Summary Comment
4+
5+
## 🎯 What You'll Do
6+
7+
Build a PR summary workflow that posts a structured, human-readable summary comment when a pull request is opened. The summary is written in a format that can be copied directly into a changelog or release note.
8+
9+
## Before You Start
10+
11+
- Complete [Build Your First Event-Driven Workflow: PR Auto-Reviewer](13-pr-reviewer-workflow.md).
12+
13+
## Why a Structured Summary?
14+
15+
A free-form review comment is useful, but a structured summary is re-usable. When every PR gets a summary in the same format, teams can scrape those comments to generate changelogs automatically, hand them to release managers as draft notes, or include them in sprint retrospectives.
16+
17+
The key design choice here is the output template: you define the structure in the workflow brief, and the agent fills in the blanks.
18+
19+
## The Summary Workflow
20+
21+
Create `.github/workflows/pr-summary.md`:
22+
23+
```markdown
24+
---
25+
name: PR Summary Generator
26+
on:
27+
pull_request:
28+
types: [opened]
29+
permissions:
30+
pull-requests: write
31+
contents: read
32+
safe-outputs:
33+
create-issue-comment:
34+
limit: 1
35+
---
36+
37+
You are a changelog assistant. When a pull request is opened:
38+
39+
1. Read the PR title, description, and list of changed files.
40+
2. Write a summary using exactly this template:
41+
42+
## Summary
43+
<!-- One sentence describing what this PR does. -->
44+
45+
## Changes
46+
<!-- Bullet list of the main areas touched, based on file paths. One bullet per distinct area. Maximum five bullets. -->
47+
48+
## Notes for reviewers
49+
<!-- One or two sentences flagging anything that needs special attention. If nothing stands out, write "No special concerns." -->
50+
51+
3. Post the summary as a comment on the pull request.
52+
4. Do not add any text outside the template structure.
53+
```
54+
55+
Compile and push:
56+
57+
```bash
58+
gh aw compile
59+
git add .github/workflows/pr-summary.md .github/workflows/pr-summary.lock.yml
60+
git commit -m "feat: add PR summary generator workflow"
61+
git push
62+
```
63+
64+
## Test It
65+
66+
Open a test pull request. The workflow fires on `opened` only (not on every push), so you will see exactly one comment per new PR. Check that the output matches the three-section template.
67+
68+
## Hands-On Exercise: Customise the Template
69+
70+
The template above is generic. Adapt it to your team's actual workflow by changing one section.
71+
72+
Ideas:
73+
- Replace **Notes for reviewers** with **Testing instructions** — ask the agent to suggest one manual test based on the changed file names.
74+
- Add a **Breaking changes** section — ask the agent to flag any file deletion or rename that might indicate a breaking change.
75+
- Replace **Summary** with **Ticket reference** — ask the agent to extract a ticket number from the PR title (for example `[PROJ-123]`) or write "No ticket found" if none is present.
76+
77+
After making your change, recompile and open a fresh PR to see the updated output.
78+
79+
## ✅ Checkpoint
80+
81+
- [ ] I created `.github/workflows/pr-summary.md` with an `opened`-only `pull_request` trigger
82+
- [ ] `gh aw compile` completed without errors and `.lock.yml` is committed and pushed
83+
- [ ] I opened a test PR and the workflow posted a comment matching the three-section template
84+
- [ ] I customised at least one section of the template to fit a real use case
85+
- [ ] I can explain why triggering only on `opened` (not `synchronize`) is the right choice for a summary workflow
86+
87+
<!-- journey: all -->
88+
<!-- /journey -->

0 commit comments

Comments
 (0)