1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHubプロフィールに非公開リポジトリの情報も表示する方法

Last updated at Posted at 2025-05-03

セルフホスティングの効果

セルフホスティングにより非公開リポジトリの情報が反映されると、統計情報は大きく変わります。以下は実際のビフォー/アフター例です:

Before(公開リポジトリのみ):

Before - 公開リポジトリのみの統計

Total Stars Earned:        1
Total Commits (2025):      504
Total PRs:                 0
Total Issues:              0
Contributed to (last year): 0
評価: C+

After(非公開リポジトリを含む):

After - 非公開リポジトリを含む統計

Total Stars Earned:        2
Total Commits (2025):      787
Total PRs:                 11
Total Issues:              52
Contributed to (last year): 0
評価: B-

このように、非公開リポジトリの情報を含めることで、より正確な活動実績が表示されるようになります。

この記事では、非公開リポジトリの情報も含めてGitHubプロフィールを充実させる方法を紹介します。

目次

  • GitHub Readme Statsとは
  • パラメータだけでは不十分な理由
  • Vercelによるセルフホスティング手順
  • コードの変更方法
  • トラブルシューティング

GitHub Readme Statsとは

GitHub Readme Statsは、プロフィールページに統計情報を美しく表示するためのツールです。コミット数、Star数、PR数などの情報やよく使用するプログラミング言語を視覚的に表示することができます。

標準的な使用例:

<a href="https://github.com/username">
  <img align="left" src="https://github-readme-stats.vercel.app/api?username=username&show_icons=true" />
</a>

パラメータだけでは不十分な理由

GitHub Readme Statsはcount_private=trueというパラメータを提供していますが、これだけでは非公開リポジトリの完全な情報を取得できないことがあります。理由は以下の通りです:

  1. GitHubのAPIレート制限
  2. 認証情報不足による非公開リポジトリへの限定的なアクセス
  3. プロバイダーの共有インスタンスによる制限

これらの問題を解決するためには、GitHub Readme Statsをセルフホスティングする必要があります。

Vercelによるセルフホスティング手順

Step 1: GitHubトークンの作成

まず、GitHubの個人アクセストークンを作成します:

  1. GitHubの「Settings」→「Developer settings」→「Personal access tokens」→「Tokens (classic)」
  2. 「Generate new token」→「Generate new token (classic)」をクリック
  3. 必要なスコープを選択:
    • repo(非公開リポジトリへのアクセスに必要)
    • read:user(ユーザー情報へのアクセスに必要)
  4. トークンを生成し安全な場所に保存

Step 2: リポジトリのフォーク

GitHub Readme Statsリポジトリをフォークします。

Step 3: Vercelへのデプロイ

  1. Vercelにアカウント登録・ログイン
  2. 「Add New...」→「Project」をクリック
  3. フォークしたリポジトリをインポート
  4. 環境変数を設定:
    • GITHUB_TOKEN = 先ほど作成したGitHubトークン
  5. 「Deploy」をクリック

デプロイが完了すると、Vercelのダッシュボード画面にプロジェクト情報が表示されます。
このダッシュボードから生成されたドメイン(例:github-readme-stats-your-username.vercel.app)を確認します。

Step 4: 環境変数の追加と再デプロイ

必要に応じて追加の環境変数を設定し、「Redeploy」ボタンをクリックして変更を適用します。

コードの変更方法

GitHubプロフィールのREADME.mdファイルのコードを以下のように変更します:

変更前:

<p>
<a href="https://github.com/username">
  <img align="left" height="170px" src="https://github-readme-stats.vercel.app/api?username=username&count_private=true&show_icons=true&theme=github_dark" />
</a>
<a href="https://github.com/username">
  <img align="left" height="170px" src="https://github-readme-stats.vercel.app/api/top-langs/?username=username&layout=compact&theme=github_dark" />
</a>
</p>

変更後:

<p>
<a href="https://github.com/username">
  <img align="left" height="170px" src="https://github-readme-stats-your-username.vercel.app/api?username=username&count_private=true&show_icons=true&theme=github_dark" />
</a>
<a href="https://github.com/username">
  <img align="left" height="170px" src="https://github-readme-stats-your-username.vercel.app/api/top-langs/?username=username&layout=compact&theme=github_dark&count_private=true&include_all_commits=true" />
</a>
</p>

重要な変更点:

  1. ドメインをgithub-readme-stats.vercel.appから自分のVercelドメイン(例:github-readme-stats-your-username.vercel.app)に変更
  2. 言語統計にもcount_private=trueinclude_all_commits=trueパラメータを追加

トラブルシューティング

言語統計に非公開リポジトリが反映されない場合

言語統計(top-langs)は通常の統計よりも取得が難しい場合があります。以下の方法を試してみてください:

  1. 追加パラメータの設定

    &private=true&include_all_commits=true
    
  2. 環境変数の追加
    Vercel環境変数に以下を追加(命名重要)

    PAT_1 = GitHubトークン
    
  3. 再デプロイの実行
    環境変数を追加したら「Redeploy」ボタンをクリック

更新が反映されない場合

GitHubはREADME.mdの画像をキャッシュすることがあります。以下の方法でキャッシュをクリアできます:

  1. URLの末尾にタイムスタンプパラメータを追加

    &cache_seconds=86400
    
  2. ブラウザのキャッシュをクリア


注:この記事の手順は2025年5月時点のものです。GitHubやVercelの仕様変更により、手順が異なる場合があります。

参考

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?