{"meta":{"title":"GitHubの問題からの機能の実装","intro":"GitHubにGitHub Copilot CLI問題を与え、会話を誘導して機能を実装します。","product":"GitHub Copilot","breadcrumbs":[{"href":"/ja/copilot","title":"GitHub Copilot"},{"href":"/ja/copilot/tutorials","title":"チュートリアル"},{"href":"/ja/copilot/tutorials/copilot-cookbook","title":"GitHub Copilot クックブック"},{"href":"/ja/copilot/tutorials/copilot-cookbook/generate-code","title":"コードの生成"},{"href":"/ja/copilot/tutorials/copilot-cookbook/generate-code/implement-a-feature","title":"機能を実装する"}],"documentType":"article"},"body":"# GitHubの問題からの機能の実装\n\nGitHubにGitHub Copilot CLI問題を与え、会話を誘導して機能を実装します。\n\nGitHub Copilot CLI では、 GitHub の問題を読み取り、実装計画を提案し、要件を満たすコード変更のドラフトを作成できます。 ワークフローは会話型であるため、前提条件を修正し、関連するファイルをポイントし、 GitHub Copilot CLI 動作するようにアプローチを絞り込むことができます。\n\n## サンプル シナリオ\n\n顧客のサブスクリプションをサポートする内部 Node.js 課金 API を維持するプラットフォーム チームで作業しているとします。 製品マネージャーは、特定のサブスクリプションにアタッチされたプランを返す新しい `GET /subscriptions/{id}/plan` エンドポイントを要求する問題を、単体テストと OpenAPI 仕様の更新と共に開きます。 この問題には、必要な応答の形状、サブスクリプションが見つからないか取り消された場合のエラー ケース、パターンとして従う既存の `/subscriptions/{id}` エンドポイントへのリンクが含まれます。 課題を GitHub Copilot CLI に任せて、ルート、コントローラー、テストのひな形を生成させたうえで、プルリクエストを作成できます。\n\n## ワークフローの例\n\nGitHub Copilot CLI では、 GitHubから直接問題を読み取り、作業を計画し、コードを記述し、テストを実行し、pull request を開くことができます。\n\n### 問題をコンテキストに取り込む\n\nリポジトリのルートから開始し、URL または `owner/repo#number`で問題を参照します。\nGitHub Copilot CLI では、 GitHub MCP サーバーを使用して問題の本文、コメント、およびリンクされた項目をフェッチし、そのコンテキストをセッションの残りの部分で使用できるようにします。\n\n```text copy\nRead octo-org/billing-api#482 and any issues or PRs it links to. \nSummarize what needs to be implemented before we plan the work.\n```\n\n### `/plan` を使用して実装計画を作成する\n\nプラン モードに切り替えて、 GitHub Copilot CLI ファイルに触れる前に変更を考慮します。\n\n```text copy\n/plan Implement the subscription lookup endpoint described in the issue. \nFollow the same conventions as the existing GET /subscriptions/{id} endpoint.\n```\n\n> \\[!NOTE] 次の応答は例です。 Copilot Chat の応答は非決定的であるため、ここで示したものとは異なる応答が返される可能性があります。\n\nGitHub Copilot CLI は、次のようなプランを返します。\n\n```text\n1. Add a `getPlanForSubscription` method in `src/services/subscriptionService.ts` that reuses the existing billing client, throws `NotFoundError` when the subscription or plan does not exist, and throws `CancelledSubscriptionError` when the subscription has been cancelled.\n1. Add a `GET /subscriptions/:id/plan` route in `src/routes/subscriptions.ts`, mirroring the error handling in the sibling `GET /subscriptions/:id` route and mapping `CancelledSubscriptionError` to a `410` response.\n1. Update `openapi/subscriptions.yaml` with the new path, response schema, and `404` and `410` responses.\n1. Add unit tests in `test/services/subscriptionService.test.ts` and `test/routes/subscriptions.test.ts` covering the success case, missing subscription, cancelled subscription, and missing plan.\n1. Run the test suite and update the changelog entry.\n```\n\n計画を確認し、気になる点があれば指摘し、承認する前に GitHub Copilot CLI に修正を依頼します。 たとえば、 `Use the existing error classes in src/errors—NotFoundError for missing subscriptions or plans and CancelledSubscriptionError for cancelled subscriptions rather than introducing new ones` で返信し、影響を受ける手順を更新してもらう場合があります。\n\n### 実装を開始し、必要に応じて操縦する\n\n計画を承認してコーディングを開始します。\nGitHub Copilot CLI は、一度に 1 つずつ手順を実行し、適用する前に各編集を表示します。 間違った方向に進みそうになったら、中断して正しい方向に導いてください。\n\nたとえば、チームで標準化された課金クライアントを再利用するのではなく、GitHub Copilot CLI が `getPlanForSubscription` メソッドに新しいデータベースクエリを追加するとします。 停止して操縦することができます。\n\n```text copy\nDon't add a new query here. The billing client in \nsrc/clients/billingClient.ts already exposes a getPlan method. \nUse that and update the service to handle its NotFound response.\n```\n\nGitHub Copilot CLI はコードを修正し、残りの計画手順を続行します。\n\n### 単体テストを生成して実行する\n\nGitHub Copilot CLIテスト ステップに達すると、既存のテスト ファイル内のパターンに一致するテストがスキャフォールディングされます。 プラン エンドポイントでは、次のようなケースが追加される場合があります。\n\n* 有効なサブスクリプションのプラン情報を返します。\n* サブスクリプションが存在しない場合に `404` を返します。\n* サブスクリプションが取り消されたときの `410` を返します。\n* サブスクリプションにプランがアタッチされていない場合に `404` を返します。\n\nテストを記述した後、 GitHub Copilot CLI はターミナルでテストを実行して、結果をすぐに確認できるようにします。\n\n```text copy\nRun the test suite for the new endpoint and fix any failures.\n```\n\nテストが失敗した場合、 GitHub Copilot CLI はエラー出力を読み取り、実装を更新し、テスト スイートが緑色になるまで再実行します。 各修正プログラムを確認して、マスクするのではなく、根本原因に対処していることを確認します。\n\n### を使用して変更を確認します。 `/diff`\n\n`/diff`を使用して、セッション全体で行われた変更の統合ビューを表示します。\n\n```text copy\n/diff\n```\n\n問題が発生した場合は、コミットする前に GitHub Copilot CLI に修正を依頼してください。 たとえば、 `Revert the formatting changes in src/routes/subscriptions.ts to only keep the new route handler` で返信して、差分のスコープを意図した変更に戻す場合があります。\n\n### pull request を開く\n\n機能が実装、テスト、およびレビューされたら、pull request を開くように GitHub Copilot CLI に依頼します。\nGitHub MCP サーバーを使用してブランチをプッシュし、プル要求を作成します\n\n```text copy\nCommit the changes on a new branch, push it, and open a pull request \nagainst main. Link it to octo-org/billing-api#482 and summarize the \nimplementation, the tests added, and any follow-up work.\n```\n\nGitHub Copilot CLI はプルリクエストの URL を返し、そこから先に進められるようにします。\n\n## 詳細については、次を参照してください。\n\n* [GitHub Copilot CLI](/ja/copilot/how-tos/copilot-cli)"}