Skip to content

Commit

Permalink
Merge pull request #1 from ctriolo/test-branh
Browse files Browse the repository at this point in the history
fix:readme  change CHR-14
  • Loading branch information
ctriolo authored May 8, 2022
2 parents 9d73df3 + dddf019 commit 0ba63d9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: Find Linear Issue in Pull Request

env:
ACTIONS_STEP_DEBUG: true

on:
workflow_dispatch:
pull_request:
branches:
- main
types: [opened, reopened]
types: ["opened", "edited", "reopened", "synchronize"]

jobs:
create-linear-issue-on-pull-request:
Expand Down
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ This is helpful when you're:

## Inputs

| Input | Description | Required |
| ---------------- | ------------------------------------------------------------- | -------- |
| `linear-api-key` | Linear API key generated from https://linear.app/settings/api ||
| Input | Description | Required |
| ---------------- | ---------------------------------------------------------------------------------- | -------- |
| `linear-api-key` | Linear API key generated from https://linear.app/settings/api . (e.g. `lin_api_*)` ||

## Outputs

| Output | Description |
| -------------------------- | ------------------------------------------------------------ |
| `linear-issue-id` | The Linear issue's unique identifier. (UUID) |
| `linear-issue-identifier` | The Linear issue's human readable identifier. (e.g. ENG-123) |
| `linear-issue-number` | The Linear issue's number. (e.g. the 123 of ENG-123) |
| `linear-issue-title` | The Linear issue's title. |
| `linear-issue-description` | The Linear issue's description. |
| `linear-issue-url` | The Linear issue's URL. (e.g. https://...) |
| `linear-team-id` | The Linear teams unique identifier. (UUID) |
| `linear-team-key` | The Linear teams key/prefix (e.g. ENG) |
| Output | Description |
| -------------------------- | -------------------------------------------------------------- |
| `linear-issue-id` | The Linear issue's unique identifier. (UUID) |
| `linear-issue-identifier` | The Linear issue's human readable identifier. (e.g. `ENG-123`) |
| `linear-issue-number` | The Linear issue's number. (e.g. the `123` of `ENG-123`) |
| `linear-issue-title` | The Linear issue's title. |
| `linear-issue-description` | The Linear issue's description. |
| `linear-issue-url` | The Linear issue's URL. (e.g. `https://...`) |
| `linear-team-id` | The Linear teams unique identifier. (UUID) |
| `linear-team-key` | The Linear teams key/prefix (e.g. `ENG`) |

## Example usage

### Create Linear Issue on Pull Request

```yaml
name: Create Linear Issue on Pull Request
name: Find Linear Issue in Pull Request

on:
workflow_dispatch:
Expand All @@ -43,16 +43,17 @@ jobs:
create-linear-issue-on-pull-request:
runs-on: ubuntu-latest
steps:
- name: Create the Linear Issue
id: createIssue
- name: Find the Linear Issue
id: findIssue
uses: ctriolo/action-find-linear-issue@v1
with:
linear-api-key: ${{secrets.LINEAR_API_KEY}}

- name: Create comment in PR with Linear Issue link
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{secrets.GITHUB_TOKEN}}
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ steps.createIssue.outputs.linear-issue-url }}"
[${{ steps.findIssue.outputs.linear-issue-identifier }}: ${{ steps.findIssue.outputs.linear-issue-title }}](${{ steps.findIssue.outputs.linear-issue-url }})
```
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: "Find Linear Issue"
description: "Finds a Linear Issue from your pull request's branch, title, or description"
inputs:
linear-api-key:
description: "Linear API key generated from https://linear.app/settings/api"
description: "Linear API key generated from https://linear.app/settings/api . (e.g. `lin_api_*)`"
required: true
outputs:
linear-issue-id:
description: "The unique identifier of the Linear issue. (UUID)"
linear-issue-identifier:
description: "The Linear issue's human readable identifier (e.g. ENG-123)."
description: "The Linear issue's human readable identifier (e.g. `ENG-123`)."
linear-issue-number:
description: "The Linear issue's number. (e.g. the 123 of ENG-123)"
description: "The Linear issue's number. (e.g. the `123` of `ENG-123`)"
linear-issue-title:
description: "The Linear issue's title."
linear-issue-description:
Expand Down
10 changes: 6 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ const main = async () => {
}

for (const team of teams) {
const regex = new RegExp(`${team.key}-(?<issueNumber>\d+)`, "gim");
debug(`Checking PR for indentifier ${team.key}-XYZ`);
const check = regex.exec(prBranch + " " + prTitle + " " + prBody);
// TODO: Iterate over multiple matches and not just first match
const regexString = `${team.key}-(?<issueNumber>\\d+)`;
const regex = new RegExp(regexString, "gim");
const haystack = prBranch + " " + prTitle + " " + prBody;
debug(`Checking PR for indentifier "${regexString}" in "${haystack}"`);
const check = regex.exec(haystack);
const issueNumber = check?.groups?.issueNumber;

if (issueNumber) {
debug(`Found issue number: ${issueNumber}`);
const issue = await getIssueByTeamAndNumber(
Expand All @@ -63,7 +66,7 @@ const main = async () => {
}

setFailed(
`Failed to find Linear issue identifier in PR branch, title or body.`
`Failed to find Linear issue identifier in PR branch, title, or body.`
);
return;
} catch (error) {
Expand Down

0 comments on commit 0ba63d9

Please sign in to comment.