Skip to content

Add script to sync suggestions from previous draft branch#111

Open
toshi0806 wants to merge 7 commits into
mainfrom
issue-110-sync-suggestions
Open

Add script to sync suggestions from previous draft branch#111
toshi0806 wants to merge 7 commits into
mainfrom
issue-110-sync-suggestions

Conversation

@toshi0806

Copy link
Copy Markdown
Member

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 creates 2nd-draft from 1st-draft at PR creation time. However, if the teacher adds Suggests to the 1st-draft PR after 2nd-draft has been created, those suggestions are not included in 2nd-draft.

Solution

The scripts/sync-suggestions.sh script allows students to merge the latest changes (including teacher's Suggests) from the previous draft branch into their current draft branch.

Features

  • Automatic branch detection: Detects previous draft from current branch name
  • Pattern support: Works with both xth-draft and abstract-xth patterns
  • Proper suffix handling: Correctly handles st/nd/rd/th suffixes
  • Error handling: Validates branch names and handles edge cases
  • User guidance: Clear feedback and next steps

Usage

```bash

Auto-detect from current branch

git checkout 2nd-draft
./scripts/sync-suggestions.sh

Explicit branch specification

./scripts/sync-suggestions.sh 3rd-draft
```

Changes

  • ✅ New script: scripts/sync-suggestions.sh
  • ✅ Documentation: Updated docs/CLAUDE-WORKFLOWS.md with usage instructions

Closes #110

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
Copilot AI review requested due to automatic review settings November 27, 2025 02:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh that detects previous draft branches and merges their changes
  • Documentation updates in docs/CLAUDE-WORKFLOWS.md with 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

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
# ./scripts/sync-suggestions.sh # 現在のブランチに対して自動判定
# ./scripts/sync-suggestions.sh 2nd-draft # 指定ブランチに対して実行

set -e

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
set -e
set -euo pipefail

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +70
git fetch origin "$PREV_BRANCH"
git fetch origin "$CURRENT_BRANCH"

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.

# マージ実行
echo "🔀 $PREV_BRANCH からの変更を $CURRENT_BRANCH にマージ中..."
git merge "origin/$PREV_BRANCH" --no-ff -m "Merge suggestions from $PREV_BRANCH"

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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').

Suggested change
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

Copilot uses AI. Check for mistakes.

# 引数があればそれを使用、なければ現在のブランチ
if [ -n "$1" ]; then
CURRENT_BRANCH="$1"

Copilot AI Nov 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add script to sync suggestions from previous draft branch

2 participants