Add script to sync suggestions from previous draft branch#111
Add script to sync suggestions from previous draft branch#111toshi0806 wants to merge 7 commits into
Conversation
Add the following information to notification emails: - PR body/description with fallback text - Commit summary (up to 10 commits) with fallback text - File changes list with additions/deletions (up to 20 files) with fallback text - Patch and diff download links - Unified indentation to 2 spaces for consistency - Added '説明:' label for PR body section
Implements script to automatically merge teacher's GitHub Suggests from the previous draft branch to the current draft branch. Features: - Automatic branch detection from current branch name - Support for both xth-draft and abstract-xth patterns - Proper suffix handling (st/nd/rd/th) - Error handling for edge cases - Clear user feedback during operation This addresses the issue where next draft branches are created before teacher's Suggests are added to the previous draft PR. Fixes #110
There was a problem hiding this comment.
Pull request overview
This PR introduces a script to automatically sync GitHub Suggests from a previous draft branch to the current draft branch, addressing the issue where suggestions added after branch creation are not automatically included in subsequent drafts.
Key Changes:
- New bash script
scripts/sync-suggestions.shthat detects previous draft branches and merges their changes - Documentation updates in
docs/CLAUDE-WORKFLOWS.mdwith usage instructions and workflow integration - Support for both main paper (
xth-draft) and abstract (abstract-xth) branch patterns
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| scripts/sync-suggestions.sh | Implements automatic branch detection and merging logic with proper ordinal suffix handling (st/nd/rd/th) |
| docs/CLAUDE-WORKFLOWS.md | Documents the new sync workflow with examples, behavior description, and important usage notes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,80 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
The script lacks execute permissions declaration. Add chmod +x instruction to the documentation or consider adding a check at the beginning of the script to ensure it has execute permissions.
| # ./scripts/sync-suggestions.sh # 現在のブランチに対して自動判定 | ||
| # ./scripts/sync-suggestions.sh 2nd-draft # 指定ブランチに対して実行 | ||
|
|
||
| set -e |
There was a problem hiding this comment.
Consider using set -euo pipefail instead of just set -e. This will catch more errors: -u fails on undefined variables and -o pipefail fails if any command in a pipeline fails, not just the last one.
| set -e | |
| set -euo pipefail |
| git fetch origin "$PREV_BRANCH" | ||
| git fetch origin "$CURRENT_BRANCH" |
There was a problem hiding this comment.
If the remote branches don't exist, git fetch will fail but won't provide user-friendly error messages. Add error handling with clear messages like 'Branch $PREV_BRANCH not found on remote' to help users understand what went wrong.
| git fetch origin "$PREV_BRANCH" | |
| git fetch origin "$CURRENT_BRANCH" | |
| if ! git fetch origin "$PREV_BRANCH"; then | |
| echo "Error: Branch $PREV_BRANCH not found on remote (origin)" | |
| exit 1 | |
| fi | |
| if ! git fetch origin "$CURRENT_BRANCH"; then | |
| echo "Error: Branch $CURRENT_BRANCH not found on remote (origin)" | |
| exit 1 | |
| fi |
|
|
||
| # マージ実行 | ||
| echo "🔀 $PREV_BRANCH からの変更を $CURRENT_BRANCH にマージ中..." | ||
| git merge "origin/$PREV_BRANCH" --no-ff -m "Merge suggestions from $PREV_BRANCH" |
There was a problem hiding this comment.
The merge command will fail if there are merge conflicts, but users won't get guidance on how to resolve them. Consider wrapping this in a conditional that checks the exit status and provides instructions for conflict resolution (e.g., 'Conflicts detected. Please resolve them manually and run git merge --continue').
| git merge "origin/$PREV_BRANCH" --no-ff -m "Merge suggestions from $PREV_BRANCH" | |
| if ! git merge "origin/$PREV_BRANCH" --no-ff -m "Merge suggestions from $PREV_BRANCH"; then | |
| echo "" | |
| echo "⚠️ マージ中にコンフリクトが発生しました。" | |
| echo "以下の手順でコンフリクトを解消してください:" | |
| echo " 1. ファイルのコンフリクト箇所を手動で修正" | |
| echo " 2. 修正後、'git add <修正したファイル>' を実行" | |
| echo " 3. 'git merge --continue' または 'git commit' を実行" | |
| echo "" | |
| echo "解消後、再度 'git push origin $CURRENT_BRANCH' を実行してください。" | |
| exit 1 | |
| fi |
|
|
||
| # 引数があればそれを使用、なければ現在のブランチ | ||
| if [ -n "$1" ]; then | ||
| CURRENT_BRANCH="$1" |
There was a problem hiding this comment.
The git checkout on line 15 can fail if the branch doesn't exist locally or if there are uncommitted changes, but no error message is provided to explain what went wrong. Add validation and user-friendly error messages before attempting checkout.
| CURRENT_BRANCH="$1" | |
| CURRENT_BRANCH="$1" | |
| # Check if branch exists locally | |
| if ! git rev-parse --verify "$CURRENT_BRANCH" >/dev/null 2>&1; then | |
| echo "Error: ブランチ '$CURRENT_BRANCH' はローカルに存在しません。" | |
| exit 1 | |
| fi | |
| # Check for uncommitted changes | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "Error: 作業ディレクトリにコミットされていない変更があります。ブランチを切り替える前にコミットまたはスタッシュしてください。" | |
| exit 1 | |
| fi |
Summary
This PR implements a script to automatically merge teacher's GitHub Suggests from the previous draft branch to the current draft branch.
Problem
When a student creates a PR from
1st-draft, GitHub Actions automatically creates2nd-draftfrom1st-draftat PR creation time. However, if the teacher adds Suggests to the1st-draftPR after2nd-drafthas been created, those suggestions are not included in2nd-draft.Solution
The
scripts/sync-suggestions.shscript allows students to merge the latest changes (including teacher's Suggests) from the previous draft branch into their current draft branch.Features
xth-draftandabstract-xthpatternsUsage
```bash
Auto-detect from current branch
git checkout 2nd-draft
./scripts/sync-suggestions.sh
Explicit branch specification
./scripts/sync-suggestions.sh 3rd-draft
```
Changes
scripts/sync-suggestions.shdocs/CLAUDE-WORKFLOWS.mdwith usage instructionsCloses #110