Skip to main content

非アクティブなユーザーに GitHub Copilot ライセンスを使うよう通知する

GitHub API を使って非アクティブなユーザーを特定し、開始できるように支援します。

この機能を使用できるユーザーについて

Organization owners and billing managers

GitHub Copilot Business or GitHub Copilot Enterprise

ビジネスで GitHub Copilot を展開する場合、どのユーザーが Copilot ライセンスを使っているかを追跡することが重要です。これにより、使われていないライセンスを再割り当てすることや、ユーザーが Copilot を使い始めるのを支援することで、効果的に対応できるようになります。

organization のすべての Copilot シート割り当てを一覧表示する API エンドポイントを使って、organization 内でライセンスが割り当てられている各ユーザーの最終アクティビティの日付を確認できます。 次に、一定期間ライセンスを使っていないユーザーをフィルター処理し、それらのユーザーにリマインダーを送信することで、自動的に応答できます。

リマインダー メッセージを書く

非アクティブなユーザーに対するリマインダーは、ユーザーが Copilot の一般的な導入阻害要因を克服するのに役立ちます。 アンケートを実施する、開発者に聞き取りするなどして、会社にとっての具体的な阻害要因を特定することをお勧めします。

たとえば、メッセージには、ユーザーに役立つ情報やリンクが含めることができます。

  • Copilot を環境にインストールします。
  • 会社のプロキシまたはファイアウォールと連携できるように、Copilot を設定します。
  • 日常業務で Copilot を最大限に活用しましょう。

また、ライセンスが未使用のままである場合は、ユーザーのライセンスを取り消すなど、追加の措置をとる予定であることも明確に伝えてください。

リマインダーの例

次のセクションでは、個々の非アクティブ ユーザーに割り当てられる issue を作成するオートメーションで使われているメッセージを紹介します。

お客様には GitHub Copilot のライセンスが割り当てられていますが、30 日間使われていません。 使い始めるときに役立つリソースをいくつか紹介します。

Copilot にアクセスする必要がなくなった場合は、この issue でお知らせください。 お客様のライセンスが非アクティブな期間がさらに 30 日間続いた場合は、ライセンスを取り消して他のユーザーがアクセスできるようにする予定です。

Markdown でのリマインダーの例

Markdown
We noticed you haven't used your assigned license for GitHub Copilot in 30 days. Here are some resources that might help you get started:

* If you haven't yet set up Copilot in your environment, see [Setting up GitHub Copilot for yourself](https://docs.github.com/en/copilot/setting-up-github-copilot/setting-up-github-copilot-for-yourself) or [Troubleshooting common issues with GitHub Copilot](https://docs.github.com/en/copilot/troubleshooting-github-copilot/troubleshooting-common-issues-with-github-copilot).
* For best practices and advice on getting started, see [Best practices for using GitHub Copilot](https://docs.github.com/en/copilot/using-github-copilot/best-practices-for-using-github-copilot) or [Prompt engineering for GitHub Copilot](https://docs.github.com/en/copilot/using-github-copilot/prompt-engineering-for-github-copilot).
* For examples related to specific tasks, see [Copilot Chat Cookbook](https://docs.github.com/en/copilot/example-prompts-for-github-copilot-chat).

If you no longer need access to Copilot, please let us know in this issue. If your license remains inactive for a further 30 days, we'll revoke it to free up access for another user.

GitHub Actions を使ってリマインダーを自動化する

次のワークフロー例では、API を使って、organization 内で 30 日間ライセンスを使っていないユーザー、またはシートが割り当てられてからまったく使っていないユーザーを特定し、各ユーザーに割り当てられる issue を作成します。 これは、ニーズに合わせて調整できる簡単な例です。

このワークフローを使うには:

  1. リマインダーの issue が作成されるリポジトリにラベルを作成します。 copilot-reminder というラベルにします。 このラベルを使って、個々の非アクティブ ユーザーに対してリマインダーの issue が既に開かれているかどうかをチェックします。

    ラベルを作成するには、「ラベルを管理する」を参照してください。

  2. Markdown でのリマインダーの例」に記載されているようなリマインダー メッセージを、リポジトリまたは organization の GitHub Actions 変数として保存します。 COPILOT_REMINDER_MESSAGE という変数にします。

    変数を作成するには、「変数に情報を格納する」を参照してください。

  3. organization のすべての Copilot シート割り当てを一覧表示する API エンドポイントを呼び出すアクセス許可を持つ personal access token を作成します。 たとえば、次の詳細を指定して、きめ細かいトークンを作成します。

    • リソース所有者: 非アクティブ ユーザーを探している organization。
    • organization のアクセス許可: GitHub Copilot Business (読み取り専用)。

    トークンを作成するには、「個人用アクセス トークンを管理する」を参照してください。

  4. アクセス トークンを GitHub Actions シークレットとしてリポジトリまたは organization に保存します。 COPILOT_LICENSE_READ というシークレットにします。

    シークレットを作成するには、「GitHub Actions でのシークレットの使用」を参照してください。

  5. 以下の例を使って、リマインダーの issue を作成するワークフローをリポジトリに作成します。

    GitHub Actions を初めて使う場合は、「GitHub Actions のクイックスタート」を参照してください。

  6. ワークフローが配置されているリポジトリ以外のリポジトリに issue を作成する場合は、gh コマンドの ${{ github.repository }} をリマインダーの issue を作成するリポジトリの名前に置き換えます。 (例: octo-org/octo-repo)。

ワークフローの例

Note

この例では、organization を通じてライセンスを割り当てることを前提としています。 Copilot Business に専用の Enterprise アカウントを使っている場合は、別の API エンドポイントを使う必要があります。 「Copilot Business (個人用アカウント) 向けの専用エンタープライズのセットアップ」を参照してください。

YAML
name: Remind inactive users about GitHub Copilot license
on:

Name your workflow

  workflow_dispatch:

Run on demand (enables Run workflow button on the Actions tab to easily trigger a run manually)

  schedule:
    - cron: '0 8 * * *'
jobs:
  context-log:
    runs-on: ubuntu-latest

Run the workflow every day at 8am UTC

    permissions:
      contents: read
      issues: write
    steps:
      - name: Check last GitHub Copilot activity
        id: check-last-activity
        run: |

Modify the default permissions granted to GITHUB_TOKEN

          RESPONSE=$(gh api \
            -H "Accept: application/vnd.github+json" \
            -H "X-GitHub-Api-Version: 2022-11-28" \
            -H "Authorization: Bearer ${{ secrets.COPILOT_LICENSE_READ }}" \
            /orgs/${{ github.repository_owner }}/copilot/billing/seats)
          echo "Raw Response from gh api:"
          echo "$RESPONSE"

List all GitHub Copilot seat assignments for an organization

          echo "$RESPONSE" | jq -c '.seats[]' | while read -r seat; do
            LOGIN=$(echo "$seat" | jq -r '.assignee.login')
            LAST_ACTIVITY=$(echo "$seat" | jq -r '.last_activity_at')
            CREATED_AT=$(echo "$seat" | jq -r '.created_at')

Parse and check each user's last_activity_at and created_at

            EXISTING_ISSUES=$(gh issue list --repo ${{ github.repository }} --assignee $LOGIN --label 'copilot-reminder' --json id)

List all open issues with label copilot-reminder

            if [ "$LAST_ACTIVITY" = "null" ]; then
              LAST_ACTIVITY_DATE=$(date -d "$CREATED_AT" +%s)
            else
              LAST_ACTIVITY_DATE=$(date -d "$LAST_ACTIVITY" +%s)
            fi
            THIRTY_DAYS_AGO=$(date -d "30 days ago" +%s)

Get last activity date and convert dates to seconds since epoch for comparison

            if [ "$LAST_ACTIVITY_DATE" -lt "$THIRTY_DAYS_AGO" ] && [ "$EXISTING_ISSUES" = "[]" ]; then
              echo "User $LOGIN has not been active in the last 30 days. Last activity: $LAST_ACTIVITY"
              NEW_ISSUE_URL="$(gh issue create --title "Reminder about your GitHub Copilot license" --body "${{ vars.COPILOT_REMINDER_MESSAGE }}" --repo ${{ github.repository }} --assignee $LOGIN --label 'copilot-reminder')"
            else
              echo "User $LOGIN is active or already has an assigned reminder issue. Last activity: $LAST_ACTIVITY"
            fi
          done

Create issues for inactive users who don't have an existing open issue

        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Set the GH_TOKEN, required for the 'gh issue' commands

# Name your workflow
name: Remind inactive users about GitHub Copilot license

on:
  # Run on demand (enables `Run workflow` button on the Actions tab to easily trigger a run manually)
  workflow_dispatch:
  # Run the workflow every day at 8am UTC
  schedule:
    - cron: '0 8 * * *'

jobs:
  context-log:
    runs-on: ubuntu-latest

    # Modify the default permissions granted to GITHUB_TOKEN
    permissions:
      contents: read
      issues: write

    steps:
      - name: Check last GitHub Copilot activity
        id: check-last-activity
        run: |
          # List all GitHub Copilot seat assignments for an organization
          RESPONSE=$(gh api \
            -H "Accept: application/vnd.github+json" \
            -H "X-GitHub-Api-Version: 2022-11-28" \
            -H "Authorization: Bearer ${{ secrets.COPILOT_LICENSE_READ }}" \
            /orgs/${{ github.repository_owner }}/copilot/billing/seats)
          echo "Raw Response from gh api:"
          echo "$RESPONSE"

          # Parse and check each user's `last_activity_at` and `created_at`
          echo "$RESPONSE" | jq -c '.seats[]' | while read -r seat; do
            LOGIN=$(echo "$seat" | jq -r '.assignee.login')
            LAST_ACTIVITY=$(echo "$seat" | jq -r '.last_activity_at')
            CREATED_AT=$(echo "$seat" | jq -r '.created_at')

            # List all open issues with label `copilot-reminder`
            EXISTING_ISSUES=$(gh issue list --repo ${{ github.repository }} --assignee $LOGIN --label 'copilot-reminder' --json id)

            # Get last activity date and convert dates to seconds since epoch for comparison
            if [ "$LAST_ACTIVITY" = "null" ]; then
              LAST_ACTIVITY_DATE=$(date -d "$CREATED_AT" +%s)
            else
              LAST_ACTIVITY_DATE=$(date -d "$LAST_ACTIVITY" +%s)
            fi
            THIRTY_DAYS_AGO=$(date -d "30 days ago" +%s)

            # Create issues for inactive users who don't have an existing open issue
            if [ "$LAST_ACTIVITY_DATE" -lt "$THIRTY_DAYS_AGO" ] && [ "$EXISTING_ISSUES" = "[]" ]; then
              echo "User $LOGIN has not been active in the last 30 days. Last activity: $LAST_ACTIVITY"

              NEW_ISSUE_URL="$(gh issue create --title "Reminder about your GitHub Copilot license" --body "${{ vars.COPILOT_REMINDER_MESSAGE }}" --repo ${{ github.repository }} --assignee $LOGIN --label 'copilot-reminder')"
            else
              echo "User $LOGIN is active or already has an assigned reminder issue. Last activity: $LAST_ACTIVITY"
            fi
          done

        # Set the GH_TOKEN, required for the 'gh issue' commands
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

参考資料