Skip to content

Automatically Label GitHub Copilot PRs

Automatically apply labels to PRs that are assisted by GitHub Copilot. You can apply labels based on a known list of Copilot users, PR tags, or by prompting the PR author to indicate if they used Copilot.

Prompt PR authors to indicate if they used Copilot for the PR and automatically label the PR if they did. This requires two separate automation files to handle posting the prompt and labeling accordingly.

Label Copilot by Prompt

Configuration Description

Conditions:

  • A PR is created

Automation Actions:

  • Post a comment prompting the author to indicate if Copilot assisted the author with writing the code in the PR.

Ask the PR author about Copilot usage.

-*- mode: yaml -*-

manifest:
  version: 1.0

on:
  - pr_created

automations:
  comment_copilot_prompt:
    # Post a comment for all PRs to prompt the PR author to indicate whether they used Copilot to assist coding in this PR
    if:
      - true
    run:
      - action: add-comment@v1
        args:
          comment: |
            Please mark whether you used Copilot to assist coding in this PR

            - [ ] Copilot Assisted
            - [ ] Not Copilot Assisted

Configuration Description

Conditions:

  • A PR is updated or merged where the author indicates they used Copilot via a prompt.

Automation Actions:

  • Apply a 🤖 Copilot label to the PR

Label PRs where the user indicated Copilot usage

-*- mode: yaml -*-

manifest:
  version: 1.0

automations:
  # You should use this automation in conjunction with comment_copilot_prompt.cm
  label_copilot_pr:
    # If the PR author has indicated that they used Copilot to assist coding in this PR, 
    # apply a label indicating the PR was supported by Copilot
    if:
      - {{ pr.comments | filter(attr='commenter', term='gitstream-cm') | filter (attr='content', regex=r/\- \[x\] Copilot Assisted/) | some}}
    run:
      - action: add-label@v1
        args:
          label: '🤖 Copilot'

Automatically apply labels to PRs that are created by known users of generative AI coding tools.

Label by Contributors

Configuration Description

Conditions:

  • The PR author is one of a specified list of contributors

Automation Actions:

  • Apply a 🤖 Copilot label to the PR

Label by Contributors

# -*- mode: yaml -*-

manifest:
  version: 1.0

automations:
  label_genai:
    # For all PRs authored by someone who is specified in the genai_contributors list
    if:
      - {{ pr.author | match(list=genai_contributors) | some  }}
    # Apply a label indicating the user has adopted Copilot
    run:
      - action: add-label@v1
        args:
          label: '🤖 Copilot'

genai_contributors:
  - username1
  - username2
  - etc

Look for a specific tag in the PR title, description, comments or commit messages and if found add a label to the PR

Label Copilot by Tag

Configuration Description

Conditions:

  • The #copilot# tag is found in any of the PR title, description, comments or commit messages for commits in the PR

Automation Actions:

  • Apply a 🤖 Copilot label to the PR

Label Copilot by Tag

# -*- mode: yaml -*-

manifest:
  version: 1.0

on:
  - comment_added
  - commit
  - pr_created

automations:
  label_copilot:
    # Detect PRs that contain the text '#copilot#' in the title, description, comments, or commit messages
    if:
      - {{ copilot_tag.pr_title or copilot_tag.pr_desc or copilot_tag.pr_comments or copilot_tag.commit_messages  }}
    # Apply a label indicating the user has adopted Copilot
    run:
      - action: add-label@v1
        args:
          label: '🤖 Copilot'

copilot_tag:
  pr_title: {{ pr.title | includes(regex=r/#copilot#/) }}
  pr_desc: {{pr.description | includes(regex=r/#copilot#/) }}
  pr_comments: {{ pr.comments | map(attr='content') | match(regex=r/#copilot#/) | some }}
  commit_messages: {{ branch.commits.messages | match(regex=r/#copilot#/) | some }}

Experimental

Code generation instructions is an experimental setting wich might change in future GitHub Copilot versions.

Use Code generation instructions to instruct copilot to add a comment at the beginning of the AI generated code. Use gitStream automation to automatically identify PRs with this comment Label by Copilot comment

Configuration Description

Conditions:

  • The comment Generated by Copilot is added to the code in this PR

Automation Actions:

  • Apply a 🤖 Copilot label to the PR

Label Copilot by comment

-*- mode: yaml -*-

manifest:
  version: 1.0

automations:
  label_copilot_pr:
    # Look for the comment 'Generated by Copilot' in the added code
    if:
      - {{ source.diff.files | matchDiffLines(regex=copilot_comment, ignoreWhiteSpaces=true) | some }}
    run:
      - action: add-label@v1
        args:
          label: '🤖 Copilot'

copilot_comment: "r/^\\+.*Generated by Copilot/"