Skip to main content

Copilot を使用してコードベースを調べる

GitHub Copilot Chat は、コードベースの内容、構造、機能を理解するのに役立ちます。

はじめに

よく知らないプロジェクトでの作業に割り当てられた場合、またはコントリビュートしたい興味深いオープンソース プロジェクトが見つかった場合は、変更を始める前に、コードベースをある程度理解しておく必要があります。 このガイドでは、GitHub Copilot Chat を使ってコードベースを調べて、プロジェクトのことを短時間で理解する方法について説明します。

Copilot Chat の操作

このガイドでの作業は、GitHub.com 上で Copilot Chat を支援モードで使って行います。このモードでは、Copilot Chat パネルが GitHub.com の現在のページの右下隅に表示されます。

パネルの端をクリックしてドラッグすることで Copilot Chat パネルを広げて、Copilot の応答が表示される領域を増やすことができます。

定義済みのプロンプトの使用

Copilot Chat には、コードベースを調べ始める際に役立つ一連の定義済みのプロンプトが付属しています。 プロンプトを使うには、チャット パネルのボタンをクリックします。 Copilot Chat で新しい会話を始めると、ボタンが表示されます。 選択されるプロンプトは、GitHub.com に現在表示されているページによって異なります。

  1. GitHub.com で調べるリポジトリを開きます。

  2. [Code] タブをクリックして、リポジトリのメイン ページを表示します。

  3. Shift+C キーを押して、支援モードで Copilot Chat を開きます。

  4. チャット パネルの [Tell me about this repository] ボタンをクリックします。

    [Tell me about this repository] ボタンが強調されているチャット パネルのスクリーンショット。

    ヒント

    このボタンが表示されない場合は、リポジトリのメイン ページにいることを確認し、Copilot パネルの右上にあるプラス記号 () をクリックして、新しい会話を始めます。

    定義済みのプロンプトが Copilot に送信されて、応答がチャット パネルに表示されます。

  5. 応答を読んだ後、必要であれば、Copilot パネルの右上にあるプラス記号 () をクリックして新しい会話を開始し、[How to get started with this repository] をクリックします。

プロンプトの例

以下のプロンプトは、Copilot に質問できて、コードベースについて調べるのに役立つ質問の種類の例です。

一般的な質問

  • Based on the code in this repository, give me an overview of the architecture of the codebase. Provide evidence.

  • Which languages are used in this repo? Show the percentages for each language.

  • What are the core algorithms implemented in this repo?

  • What design patterns are used in this repository? Give a brief explanation of each pattern that you find, and an example of code from this repository that uses the pattern, with a link to the file.

具体的な質問

これらの質問が役に立つかどうかは、調べているコードベースによります。

  • How do I build this project?

  • Where is authentication handled in this codebase?

  • Analyze the code in this repository and tell me about the entry points for this application.

  • Describe the data flow in this application.

  • Analyze the code in this repository and tell me what application-level security mechanisms are employed. Provide references.

ディレクトリ内のファイルについて

Copilot を使うと、ディレクトリ内のファイルまたは個々のファイルの目的を理解するのに役立ちます。

ディレクトリ内のファイルについて調べるには:

  1. GitHub.com でディレクトリに移動します。
  2. Shift+C キーを押して、支援モードで Copilot Chat を開きます。
  3. Copilot に次のように質問します: Explain the files in this directory

特定のファイルについて調べるには:

  1. GitHub.com でファイルを開きます。
  2. Shift+C キーを押して、支援モードで Copilot Chat を開きます。
  3. 小さいファイルの場合は、Copilot に次のように質問します: Explain this file
  4. 大きいファイルの場合は、次のように質問します: Explain what this file does. Start with an overview of the purpose of the file. Then, in appropriately headed sections, go through each part of the file and explain what it does in detail.

コミットについて調べる

プロジェクトについての理解を深めるのに良い方法の 1 つは、最近行われている作業を調べることです。 これを行うには、最近のコミットを参照します。

  1. GitHub で、リポジトリのメイン ページに移動します。

  2. リポジトリのメイン ページで、ファイルリストの上にある コミットをクリックします。

    リポジトリのメイン ページのスクリーンショット。 時計のアイコンと [178 件のコミット] がオレンジ色の枠線で強調表示されています。

  3. コミット メッセージをクリックして、そのコミットの差分ビューを表示します。

  4. Copilot Chat パネルに「What does this commit do?」と入力します。

  5. 必要な場合は、「Explain in more detail」と入力してフォローアップできます。

[Insights] タブの使用

プロジェクトについての理解を深めるには、Copilot を使うだけでなく、GitHub.com の [Insights] タブを使うこともできます。 これにより、リポジトリの概要が表示されます。

詳細については、「Pulse を使用してリポジトリ アクティビティの概要を表示する」および「プロジェクトのコントリビューターを表示する」を参照してください。

参考資料