diff --git a/plugins/filters/suggestIssues/LICENSE b/plugins/filters/suggestIssues/LICENSE new file mode 100644 index 00000000..4af7cd03 --- /dev/null +++ b/plugins/filters/suggestIssues/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 LinearB + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/filters/suggestIssues/README.md b/plugins/filters/suggestIssues/README.md new file mode 100644 index 00000000..6fb6c6e1 --- /dev/null +++ b/plugins/filters/suggestIssues/README.md @@ -0,0 +1,24 @@ + +--8<-- "plugins/filters/suggestIssues/reference.md" + + +??? note "Plugin Code: suggestIssues" + ```javascript + --8<-- "plugins/filters/suggestIssues/index.js" + ``` +
\[String\]
- Returns a list of suggested issues
+**License**: MIT
+
+| Param | Type | Description |
+| ------ | -------- | ------------------------------------------------ |
+| pr | `Object` | The pull request object from gitStream's context |
+| branch | Object | The branch object from gitStream's context |
+| apiKey | `string` | The API key used to authenticate requests. |
+
+
+**Example**
+
+```yaml
+{{ pr | suggestIssues(env.LINEARB_TOKEN) }}
+```
diff --git a/plugins/filters/suggestIssues/suggestIssues.cm b/plugins/filters/suggestIssues/suggestIssues.cm
new file mode 100644
index 00000000..4cba4d00
--- /dev/null
+++ b/plugins/filters/suggestIssues/suggestIssues.cm
@@ -0,0 +1,46 @@
+# -*- mode: yaml -*-
+
+manifest:
+ version: 1.0
+
+automations:
+ # Add comment that suggests tickets for this PR when there is no linked
+ # ticket in the title or description
+ suggest_issues:
+ on:
+ - label_added
+ if:
+ - {{ pr.labels | match(term='suggest-ticket') | some }}
+ run:
+ - action: add-comment@v1
+ args:
+ comment: |
+ Select one of the suggested issues to link to this PR. Once you make a selection, gitStream will automatically update the PR title and description with the selected issue key (taking into account issues opened up to the last 2 hours).
+
+ {{ pr | suggestedIssues(branch, env.TICKET_SUGGESTION_TOKEN) }}
+
+ *✨ This list was created using LinearB’s AI service*
+
+ # If the PR author has indicated that they used a specific issue,
+ # add it to the PR description and title
+ add_selected_issue_to_pr:
+ if:
+ - {{ pr.comments | filter(attr='commenter', term='gitstream-cm') | filter (attr='content', regex=r/\- \[x\]/) | some }}
+ - {{ not (has.jira_ticket_in_title or has.jira_ticket_in_desc) }}
+ run:
+ - action: update-title@v1
+ args:
+ concat_mode: prepend
+ title: |
+ {{ selected_issue_key }} -
+ - action: update-description@v1
+ args:
+ concat_mode: prepend
+ description: |
+ Jira issue: {{ selected_issue_key }}
+
+selected_issue_key: {{ pr.comments | filter(attr='commenter', term='gitstream-cm') | map(attr='content') | filter (regex=r/\- \[x\].*/) | first | capture(regex=r/\b[A-Za-z]+-\d+\b/) }}
+
+has:
+ jira_ticket_in_title: {{ pr.title | includes(regex=r/\b[A-Za-z]+-\d+\b/) }}
+ jira_ticket_in_desc: {{ pr.description | includes(regex=r/atlassian.net\/browse\/\w{1,}-\d{3,4}/) }}
\ No newline at end of file