GitHub & Pull Request

コードのSNS。レビュー文化とCI/CDの基盤。

コードのSNS (Social Media for Code)

GitHubは「コードのSNS」です。 **プルリクエスト(PR)** = 投稿(これをmainに入れてください!) **レビュー** = いいね、コメント、リプライ **マージ** = 採用(フォロワーが増える ← チームからの信頼) **Actions** = 自動バックアップ・自動投稿(CI/CD)

用語集

Pull Request
マージ提案。レビュー依頼。
レビュー
コードの確認とフィードバック。
CI
継続的インテグレーション。自動テスト。
Actions
GitHub上で動くワークフロー自動化。

PRワークフロー

プルリクエストを使った開発フローの基本。

pr-workflow.sh
# 1. Create feature branch and make changes
git switch -c feature/user-profile
# ... edit files ...
git add .
git commit -m "feat: Add user profile page"
# 2. Push to GitHub
git push origin feature/user-profile
# 3. Open Pull Request on GitHub
# (via browser or gh CLI)
# 4. After review approval, merge on GitHub
# 5. Pull the merged changes locally
git switch main
git pull origin main
実行結果
remote: Create a pull request for 'feature/user-profile' on GitHub by visiting:
remote:   https://github.com/user/repo/pull/new/feature/user-profile

良いPRの書き方

レビュアーが理解しやすいPRを書くことで、マージまでの時間が短縮されます。

Bad
## Bug fix
Fixed stuff
Good
## Summary
Add user profile page with avatar upload
## Changes
- Add ProfileForm component
- Add avatar upload with size validation
- Add unit tests for image resizing
## How to Test
1. Run `npm run dev`
2. Navigate to /settings/profile
3. Upload an image (max 5MB)
## Screenshots
(Attach before/after screenshots)
Tip: .github/PULL_REQUEST_TEMPLATE.md を作成すると、PRテンプレートが自動適用される。

GitHub Actions (CI/CD)

pushやPR作成時に自動でテストやビルドを実行する。

.github/workflows/ci.yml
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
GitHub上での表示
✓ CI / test (pull_request)
  ✓ Setup Node.js (2s)
  ✓ Install dependencies (15s)
  ✓ Run tests (8s)
  ✓ Build (25s)

合格ライン

PRを作成してマージできる
良いPRテンプレートを書ける
GitHub Actionsのワークフローを読める
レビューコメントを適切に書ける

参考リンク

演習課題

課題1: 初めてのPR
自分のリポジトリでブランチを作成し、プルリクエストを開いてみてください。
課題2: PR Description
Summary, Changes, How to Test を含む詳細な PR 説明文を書いてみてください。

関連ページ