{"meta":{"title":"提醒非活动用户使用其GitHub Copilot 许可证","intro":"使用 GitHub API 识别非活动用户并帮助他们入门。","product":"GitHub Copilot","breadcrumbs":[{"href":"/zh/copilot","title":"GitHub Copilot"},{"href":"/zh/copilot/tutorials","title":"教程"},{"href":"/zh/copilot/tutorials/roll-out-at-scale","title":"大规模推出"},{"href":"/zh/copilot/tutorials/roll-out-at-scale/assign-licenses","title":"分配许可证"},{"href":"/zh/copilot/tutorials/roll-out-at-scale/assign-licenses/remind-inactive-users","title":"提醒非活动用户"}],"documentType":"article"},"body":"# 提醒非活动用户使用其GitHub Copilot 许可证\n\n使用 GitHub API 识别非活动用户并帮助他们入门。\n\n在企业中推出 GitHub Copilot 时，请务必跟踪哪些用户使用其 Copilot 许可证，以便通过重新分配未使用的许可证或帮助用户开始使用 Copilot来有效响应。\n\n可以使用[列出组织的所有 Copilot 席位分配](/zh/rest/copilot/copilot-user-management#list-all-copilot-seat-assignments-for-an-organization) API 终结点来查找组织中分配有许可证的每个用户的最后活动日期。 然后，可以通过筛选一定时间内未使用其许可证的用户并向这些用户发送提醒来自动做出响应。\n\n## 编写提醒消息\n\n向非活跃用户发送的提醒应帮助用户克服采用 Copilot 时常见的障碍。 建议通过开展调查或采访开发人员来识别公司的特定阻碍因素。\n\n例如，该消息可以包含帮助用户的信息和链接：\n\n* 将 Copilot 安装到其环境中\n* 将 Copilot 设置为可与贵公司的代理或防火墙配合使用。\n* 在日常工作中充分利用 Copilot。\n\n你还应明确传达在许可证仍不被使用的情况下你将采取的任何进一步的行动，例如撤销用户的许可证。\n\n### 示例提醒\n\n在下一部分中，我们将在自动化中使用此消息创建一个问题，并将其分配给每个非活动用户。\n\n> 我们注意到，分配给您的 GitHub Copilot 许可证已经有 30 天未使用。 下面是一些可能帮助您入门的资源：\n>\n> * 如果您尚未在您的环境中设置好 Copilot，请参阅 [为自己设置GitHub Copilot](/zh/copilot/how-tos/set-up/set-up-for-self) 或 [排除GitHub Copilot的常见故障问题](/zh/copilot/how-tos/troubleshoot-copilot/troubleshoot-common-issues)。\n> * 有关入门的最佳实践和建议，请参阅 [使用 GitHub Copilot 的最佳做法](/zh/copilot/get-started/best-practices) 或 [GitHub Copilot 对话助手的提示设计](/zh/copilot/concepts/prompting/prompt-engineering)。\n> * 有关特定任务的示例，请参阅 [GitHub Copilot 指南](/zh/copilot/tutorials/copilot-cookbook)。\n>\n> 如果您不再需要对 Copilot 的访问权限，请在此问题中告知我们。 如果许可证在 30 天内保持非活动状态，我们将撤销该许可证，以便为其他用户释放access。\n\n#### Markdown 提醒示例\n\n<!-- markdownlint-disable search-replace -->\n\n```markdown copy\nWe noticed you haven't used your assigned license for GitHub Copilot in 30 days. Here are some resources that might help you get started:\n\n* 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).\n* 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).\n* For examples related to specific tasks, see [Copilot Chat Cookbook](https://docs.github.com/en/copilot/example-prompts-for-github-copilot-chat).\n\nIf 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.\n```\n\n<!-- markdownlint-enable search-replace -->\n\n## 使用 GitHub Actions 将提醒自动化\n\n以下示例工作流使用 API 识别组织中 30 天内未使用过其许可证或自分配席位以来根本没有使用许可证的用户，然后创建分配给每个用户的议题。 这是一个简单的示例，你可以对其进行调整来满足你的需求。\n\n要使用此工作流，请：\n\n1. 在将创建提醒问题的存储库中创建标签。 调用标签 `copilot-reminder`。 我们将使用此标签来检查每个非活动用户是否都已有处于打开状态的提醒问题。\n\n   若要创建标签，请参阅“[管理标签](/zh/issues/using-labels-and-milestones-to-track-work/managing-labels#creating-a-label)”。\n2. 将提醒消息（例如 [Markdown 中的提醒示例](#example-reminder-in-markdown)中提供的消息）保存为存储库或组织中的 GitHub Actions 变量。 调用变量 `COPILOT_REMINDER_MESSAGE`。\n\n   若要创建变量，请参阅“[在变量中存储信息](/zh/actions/how-tos/write-workflows/choose-what-workflows-do/use-variables#creating-configuration-variables-for-a-repository)”。\n3. 创建一个 personal access token，它应有权调用[列出组织中的所有 Copilot 席位分配](/zh/rest/copilot/copilot-user-management#list-all-copilot-seat-assignments-for-an-organization) API 终结点。 例如，创建具有下列详细信息的精细化的令牌：\n\n   * **资源所有者**：用于查找非活动用户的组织。\n   * **组织权限**： GitHub Copilot Business （只读）。\n\n   若要创建令牌，请参阅 [管理个人访问令牌](/zh/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token)。\n4. 将访问令牌保存为 GitHub Actions 存储库或组织中的机密。 调用密钥 `COPILOT_LICENSE_READ`。\n\n   若要创建机密，请参阅 [在 GitHub Actions 中使用机密](/zh/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets#creating-secrets-for-a-repository)。\n5. 通过使用以下示例，在要在其中创建提醒议题的仓库中创建工作流。\n\n   如果你不熟悉 GitHub Actions，请参阅 [GitHub Actions快速入门](/zh/actions/get-started/quickstart)。\n6. 如果要在不属于工作流所在的存储库中创建问题，请将 `${{ github.repository }}` 命令中的 `${{ github.repository }}` 替换为要在其中创建提醒问题的存储库的名称。 例如：`octo-org/octo-repo`。\n\n### 示例工作流\n\n> \\[!NOTE] 此示例假定你通过组织分配许可证。 企业帐户和企业团队也存在类似的 API 终结点。 请参阅“[用于Copilot用户管理的 REST API 终结点](/zh/rest/copilot/copilot-user-management)”。\n\n<!-- markdownlint-disable GHD021 -->\n\n```yaml annotate\n# Name your workflow\nname: Remind inactive users about GitHub Copilot license\n\non:\n  # Run on demand (enables `Run workflow` button on the Actions tab to easily trigger a run manually)\n  workflow_dispatch:\n  # Run the workflow every day at 8am UTC\n  schedule:\n    - cron: '0 8 * * *'\n\njobs:\n  context-log:\n    runs-on: ubuntu-latest\n\n    # Modify the default permissions granted to GITHUB_TOKEN\n    permissions:\n      contents: read\n      issues: write\n\n    steps:\n      - name: Check last GitHub Copilot activity\n        id: check-last-activity\n        run: |\n          # List all GitHub Copilot seat assignments for an organization\n          RESPONSE=$(gh api \\\n            -H \"Accept: application/vnd.github+json\" \\\n            -H \"X-GitHub-Api-Version: 2022-11-28\" \\\n            -H \"Authorization: Bearer ${{ secrets.COPILOT_LICENSE_READ }}\" \\\n            /orgs/${{ github.repository_owner }}/copilot/billing/seats)\n          echo \"Raw Response from gh api:\"\n          echo \"$RESPONSE\"\n\n          # Parse and check each user's `last_activity_at` and `created_at`\n          echo \"$RESPONSE\" | jq -c '.seats[]' | while read -r seat; do\n            LOGIN=$(echo \"$seat\" | jq -r '.assignee.login')\n            LAST_ACTIVITY=$(echo \"$seat\" | jq -r '.last_activity_at')\n            CREATED_AT=$(echo \"$seat\" | jq -r '.created_at')\n\n            # List all open issues with label `copilot-reminder`\n            EXISTING_ISSUES=$(gh issue list --repo ${{ github.repository }} --assignee $LOGIN --label 'copilot-reminder' --json id)\n\n            # Get last activity date and convert dates to seconds since epoch for comparison\n            if [ \"$LAST_ACTIVITY\" = \"null\" ]; then\n              LAST_ACTIVITY_DATE=$(date -d \"$CREATED_AT\" +%s)\n            else\n              LAST_ACTIVITY_DATE=$(date -d \"$LAST_ACTIVITY\" +%s)\n            fi\n            THIRTY_DAYS_AGO=$(date -d \"30 days ago\" +%s)\n\n            # Create issues for inactive users who don't have an existing open issue\n            if [ \"$LAST_ACTIVITY_DATE\" -lt \"$THIRTY_DAYS_AGO\" ] && [ \"$EXISTING_ISSUES\" = \"[]\" ]; then\n              echo \"User $LOGIN has not been active in the last 30 days. Last activity: $LAST_ACTIVITY\"\n\n              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')\"\n            else\n              echo \"User $LOGIN is active or already has an assigned reminder issue. Last activity: $LAST_ACTIVITY\"\n            fi\n          done\n\n        # Set the GH_TOKEN, required for the 'gh issue' commands\n        env:\n          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n```\n\n<!-- markdownlint-enable GHD021 -->\n\n## 其他阅读材料\n\n* [GitHub Copilot的指标数据属性](/zh/copilot/reference/metrics-data#last_activity_at)\n* [推动您的公司采用GitHub Copilot](/zh/copilot/tutorials/roll-out-at-scale/enable-developers/drive-adoption)\n* [使用 Copilot 使用情况指标跟踪许可证激活和初始使用情况](/zh/copilot/tutorials/roll-out-at-scale/assign-licenses/track-usage-and-adoption)"}