Skip to content

Commit

Permalink
Merge pull request #381 from linear-b/language-labels
Browse files Browse the repository at this point in the history
New language-based examples
  • Loading branch information
BenLloydPearson authored Dec 20, 2023
2 parents c8b558d + eec6cfd commit 1babf0c
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/automations/automation-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This library of gitStream examples is meant to serve as a starting point for you
* [Label deleted files](label-deleted-files/README.md) - Label PRs that delete files.
* [Label missing project tracker](label-missing-project-tracker/README.md) - Flag PRs that are missing a reference to an associated project tracking resource.
* [Automatic project tracking links](standard/link-issue-tracker/README.md) - Automatically post PR comments that link to the associated project tracking resource (Jira, Shortcut, Azure Boards, and more).
* [Summarize PR contents by language](standard/summarize-language-changes/README.md) - Post a comment that breaks down code changes by the programming languages contained in the PR.

## Improve PR Quality
### Merge Routing
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 4 additions & 11 deletions docs/automations/standard/label-management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,18 @@ description: Implement workflow automations for GitHub and GitLab PR labels.

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

* [Enforce Required Labels](#enforce-required-labels)
* [Label Modified Resources](#label-changed-resources)
* [Percent-Based Labels for Modified Resources](#label-resources-percent)
* [Label the number of unresolved code review threads](#label-unresolved-threads)
* [Automatically recommend labels for new PRs](#suggest-labels)
* [Label PRs with the number of reviews](#label-approvals)

<a name="enforce-required-labels"></a>
## Enforce Required Labels
--8<-- "docs/automations/standard/label-management/enforce-labels/README.md:6:"

<a name="label-changed-resources"></a>
## Label Modified Resources
--8<-- "docs/automations/standard/label-management/label-modified-resources/README.md:6:"

<a name="label-changed-resources"></a>
## Percent-Based Labels for Modified Resources
--8<-- "docs/automations/standard/label-management/label-resources-percent/README.md:6:"

<a name="label-languages"></a>
## Label PRs by Language
--8<-- "docs/automations/standard/label-management/label-prs-by-language/README.md:example"

<a name="label-unresolved-threads"></a>
## Label the Number of Unresolved Code Review Threads
--8<-- "docs/automations/standard/label-management/label-unresolved-threads/README.md:6:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ title: Automation - Label Modified Resources
description: Automatically label PRs to indicate what resources are being changed.
---
# Label Modified Resourcess Based on Modified Resources
<!-- --8<-- [start:example]-->
Automatically label PRs to indicate what resources are being changed.

Automatically label PRs to indicate what resources are being changed. This works as a direct replacement for the <a href="https://github.com/marketplace/actions/labeler" target="_blank">PR Labeler</a> GitHub Action.

<div class="automationImage" markdown="1">
![Label Modified Resources](/automations/standard/label-management/label-modified-resources/label-modified-resources.png)
</div>
<div class="automationDescription" markdown="1">
!!! info "Configuration Description"
Conditions (all must be true):

Expand All @@ -19,8 +16,6 @@ Automatically label PRs to indicate what resources are being changed. This works

* Apply labels based on the branch name or modified resources.

</div>
<div class="automationExample" markdown="1">
!!! example "Label Modified Resources"
```yaml+jinja
--8<-- "docs/downloads/automation-library/standard/label-management/label_modified_resources.cm"
Expand All @@ -30,4 +25,5 @@ Automatically label PRs to indicate what resources are being changed. This works
[:octicons-download-24: Download this example as a CM file.](/downloads/automation-library/standard/label-management/label_modified_resources.cm){ .md-button }
</span>
</div>
</div>

<!-- --8<-- [end:example]-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Automation - Label PRs by Language
description: Automatically detect which programming languages are contained in PRs and automatically label the PRs appropriately.
---
# Label PRs by Language

<!-- --8<-- [start:example]-->
Automatically detect which programming languages are contained in PRs and automatically label the PRs appropriately.

![Label PRs by Language](/automations/standard/label-management/label-prs-by-language/label-prs-by-language.png)
!!! info "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.

!!! example "Label PRs by Language"
```yaml+jinja
--8<-- "docs/downloads/automation-library/standard/label-management/label_prs_by_language.cm"
```
<div class="result" markdown>
<span>
[:octicons-download-24: Download this example as a CM file.](/downloads/automation-library/standard/label-management/label_prs_by_language.cm){ .md-button }
</span>
</div>

<!-- --8<-- [end:example]-->

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions docs/automations/standard/summarize-language-changes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Automation - Summarize Language Changes
description: Automatically post a comment that summarizes which programming languages are contained in PRs..
---
# Summarize Language Changes

<!-- --8<-- [start:example]-->

Post a comment that summarizes which programming languages are contained in PRs.

<div class="automationImage" markdown="1">
![Summarize Language Changes](/automations/standard/summarize-language-changes/summarize-language-changes.png)
</div>

<div class="automationDescription" markdown="1">
!!! info "Configuration Description"
Conditions (all must be true):

* A PR is created.

Automation Actions:

* Post a comment containing a table that shows the percent of total changes for each programming language present in the PR.
</div>

<div class="automationExample" markdown="1">
!!! example "Summarize Language Changes"
```yaml+jinja
--8<-- "docs/downloads/automation-library/standard/summarize_language_changes.cm"
```
<div class="result" markdown>
<span>
[:octicons-download-24: Download this example as a CM file.](/downloads/automation-library/standard/summarize_language_changes.cm){ .md-button }
</span>
</div>
<!-- --8<-- [end:example]-->

## Additional Resources

--8<-- "docs/snippets/general.md"

--8<-- "docs/snippets/automation-footer.md"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- 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/

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- mode: yaml -*-
manifest:
version: 1.0

on:
- pr_created

automations:
summarize_language_changes:
if:
- true
run:
- action: add-comment@v1
args:
comment:
<h3>Summary of Changes by Language</h3>
<table>
<tr>
<td>Language</td>
<td>Language Change Percentage</td>
</tr>
<tr>
<td>Java</td>
<td>{{ total.java | round }}%</td>
</tr>
<tr>
<td>JavaScript</td>
<td>{{ total.javascript | round }}%</td>
</tr>
<td>Rust</td>
<td>{{ total.rust | round }}%</td>
</tr>
<tr>
<td>Ruby</td>
<td>{{ total.ruby | round }}%</td>
</tr>
<td>HTML</td>
<td>{{ total.html | round }}%</td>
</tr>
<td>CSS</td>
<td>{{ total.css | round }}%</td>
</tr>
<tr>
<td>Golang</td>
<td>{{ total.golang | round }}%</td>
</tr>
<tr>
<td>Python</td>
<td>{{ total.python | round }}%</td>
</tr>
</table>

total:
additions: {{ branch.diff.files_metadata | map(attr='additions') | sum }}
java: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.java$/ ) | map(attr='additions') | sum / total.additions * 100 }}
javascript: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.js$/ ) | map(attr='additions') | sum / total.additions * 100 }}
rust: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.rs$/ ) | map(attr='additions') | sum / total.additions * 100 }}
ruby: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.rb$/ ) | map(attr='additions') | sum / total.additions * 100 }}
html: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.html$/ ) | map(attr='additions') | sum / total.additions * 100 }}
css: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.css$/ ) | map(attr='additions') | sum / total.additions * 100 }}
golang: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.go$/ ) | map(attr='additions') | sum / total.additions * 100 }}
python: {{ branch.diff.files_metadata | filter(attr='file', regex=r/.py$/ ) | map(attr='additions') | sum / total.additions * 100 }}

12 changes: 12 additions & 0 deletions docs/integrations/linearb.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ LinearB is a software delivery management platform that makes it easy to benchma
## Track the Impact of Generative AI Initiatives
These examples show how to label PRs that are assisted by GitHub Copilot so you can easily track productivity within LinearB. These examples can be adapted for any other generative AI solutions you might use.

![Track Copilot Initiatives in LinearB](/automations/integrations/linearb/copilot-label-metrics.png)

--8<-- "docs/automations/integrations/copilot/flag-copilot-pr/README.md:example"

## Label Changes to Track in LinearB

These examples show how to label PRs based on the changed code so you can more easily compare metrics across languages, frameworks, changed directories, and more.

![Track Copilot Initiatives in LinearB](/automations/integrations/linearb/resource-label-metrics.png)


=== "by Modified Resource"
--8<-- "docs/automations/standard/label-management/label-modified-resources/README.md:example"
=== "by Language"
--8<-- "docs/automations/standard/label-management/label-prs-by-language/README.md:example"

## Additional Resources

Expand Down

0 comments on commit 1babf0c

Please sign in to comment.