Skip to content

PR Label Management with gitStream

Use YAML to automate label management on your git repo with gitStream.

Enforce Required Labels

Enforce Required Labels

Automatically enforce the use of required PR labels.

Enforce Required Labels

Configuration Description

Conditions (all must be true):

  • The PR lacks one or more labels from a list of required labels.

Automation Actions:

  • Apply a Missing Required Labels label.
  • Post a comment explaining why the label was applied and which labels are required.

Enforce Required Labels

manifest:
  version: 1.0

automations:
  enforce_required_labels:
    if:
      - {{ pr.labels | match(list=['Core', 'Mobile', 'UI']) | nope }}
    run:
      - action: request-changes@v1
        args:
          comment: Please ensure that your PR is labeled with either 'Core', 'Mobile', or 'UI'. These labels help us to better track and manage your contribution. Thank you.

Label Modified Resources

Label Changed Resources By Percent

Apply a label to all PRs that indicates what percentage of new lines of code modify one or more specified resources.

Label Changed Resources By Percent

Configuration Description

Conditions (all must be true):

  • A PR modifies resources listed in one or more specified locations.

Automation Actions:

  • Apply labels that indicate what percentage of new code lines modify the specified resources.

Label Changed Resources By Percent

# -*- mode: yaml -*-
manifest:
  version: 1.0

automations:
  {% for item in labels %}
  label_resource_percent_{{ item.name }}:
      if:
        - {{ files | match(list=item.resources) | some }}
      run:
        - action: add-label@v1
          args:
            label: '{{ item.additions | round }}% {{ item.name }}'
  {% endfor %}

resources:
  core:
    - src/app
    - src/core
  mobile: 
    - src/android
    - src/ios
  docs:
    - docs/

labels:
  - name: Core
    resources: {{ resources.core }}
    additions: {{ branch.diff.files_metadata | filter(attr='file', list=resources.core ) | map(attr='additions') | sum / total.additions * 100 }}
  - name: Mobile
    resources: {{ resources.mobile }}
    additions: {{ branch.diff.files_metadata | filter(attr='file', list=resources.mobile ) | map(attr='additions') | sum / total.additions * 100 }}
  - name: Docs
    resources: {{ resources.docs }}
    additions: {{ branch.diff.files_metadata | filter(attr='file', list=resources.docs ) | map(attr='additions') | sum / total.additions * 100 }}

total:
  additions: {{ branch.diff.files_metadata | map(attr='additions') | sum }}

Label PRs by Language

Automatically detect which programming languages are contained in PRs and automatically label the PRs appropriately.

Label PRs by Language

Configuration Description

Conditions (all must be true):

  • A PR is created or updated.

Automation Actions:

  • Label the PR for each programming language that is included.

Label PRs by Language

# -*- mode: yaml -*-
manifest:
  version: 1.0

automations:
  {% for item in labels %}
  label_{{ item.name }}_pr:
      if:
        - {{ files | match(regex=item.resources) | some }}
      run:
        - action: add-label@v1
          args:
            label: '{{ item.name }}'
  {% endfor %}

labels:
  - name: Java
    resources: r/.java$/
  - name: Rust
    resources: r/.rs$/
  - name: HTML
    resources: r/.html$/
  - name: JavaScript
    resources: r/.js$/
  - name: Python
    resources: r/.py$/
  - name: Golang
    resources: r/.go$/
  - name: Ruby
    resources: r/.rb$/
  - name: CSS
    resources: r/.css/

Label the Number of Unresolved Code Review Threads


Label Unresolved Review Threads

Automatically label PRs when there are unresolved code review comments.

Label Unresolved Review Threads

Configuration Description

Conditions (all must be true):

  • The PR has one or more unresolved code review comments.

Automation Actions:

  • Apply a label that indicates how many unresolved comments the PR has.

Label Unresolved Review Threads

# -*- mode: yaml -*-
manifest:
  version: 1.0
automations:
  label_unresolved_threads:  
    if:  
      - {{ pr.unresolved_threads }}
    run:
      - action: add-label@v1
        args:
          label: {{ pr.unresolved_threads }} Unresolved Thread(s)
          color: {{ colors.yellow }}

colors:
  yellow: 'fbca04'

Automatically Recommend Labels for New PRs

Suggest Labels

Automatically suggest labels to apply to new PRs.

Suggest Labels

Configuration Description

Conditions (all must be true):

  • A PR is created or updated that has no labels.

Automation Actions:

  • Post a comment that suggest labels the author can apply to the PR.

Suggest Labels

# -*- mode: yaml -*-
manifest:
  version: 1.0
automations:
  suggest_labels:  
    if:  
      - {{ pr.labels | length == 0}}
    run:
      - action: add-comment@v1
        args: 
          comment: | 
            All PRs must contain labels that indicate which CI/CD systems must be run. PLease update your PR to include one of the following labels: `Build: Mobile`, `Build: UI`, `Build: All`, `Build: None`

            Additionally, Here are some labels you can apply to this PR that may be helpful:
               * Suggest Reviewer - Use this if you aren't sure who to assign as the reviewer.
               * WIP - Indicate this is a work in progress that shouldn't be merged.

Label PRs with the Number of Approvals

Label the Number of Approvals

Automatically label PRs with the number of completed reviews that approve the PR.

Label the Number of Approvals

Configuration Description

Conditions (all must be true):

  • A PR is created or updated.

Automation Actions:

  • Apply or update a label that indicates how many merge approvals have been granted.

Label the Number of Approvals

# -*- mode: yaml -*-
manifest:
  version: 1.0
automations:
  label_approvals: 
    if:  
      - {{ pr.approvals | length > 0 }}
    run:
      - action: add-label@v1
        args:
          label: {{ pr.approvals | length }} Approved Review(s)

Additional Resources

gitStream is a workflow automation tool that enables you to use YAML configuration files to optimize your code review process. Add context to PRs, find code experts for reviews, and automate the merge process to maximize developer productivity.

Learn More about how gitStream Works.

Related Automations:

More Automations can be found on the Automation Library and Integrations pages.

Special thanks to Boemo W Mmopelwa for help with these examples.