From afd15a075aa8ef284a1585ff088266be8640088d Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:24:55 -0700 Subject: [PATCH 1/9] fix:readme --- README.md | 35 ++++++++++++++++++----------------- action.yml | 6 +++--- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6b8de0f..a9b25c5 100644 --- a/README.md +++ b/README.md @@ -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: @@ -43,8 +43,8 @@ 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}} @@ -52,7 +52,8 @@ jobs: - 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 }}) ``` diff --git a/action.yml b/action.yml index 8e76b32..351e375 100644 --- a/action.yml +++ b/action.yml @@ -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: From b500f3d9aec3f01cba7ed389eed821f5ab4f26ff Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:27:47 -0700 Subject: [PATCH 2/9] fix: add more pull request types --- .github/workflows/pull-request.yml | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 1efb9a9..9fdd437 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,7 +5,7 @@ on: pull_request: branches: - main - types: [opened, reopened] + types: ["opened", "edited", "reopened", "synchronize"] jobs: create-linear-issue-on-pull-request: diff --git a/src/main.ts b/src/main.ts index 63b647e..3e35bd2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -63,7 +63,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) { From 9bc931b80ef666b8e09eaf4cc81dfcbb25b6636e Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:29:53 -0700 Subject: [PATCH 3/9] fix: add debug mode to pull request workflow --- .github/workflows/pull-request.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9fdd437..2a24122 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,5 +1,8 @@ name: Find Linear Issue in Pull Request +env: + ACTIONS_STEP_DEBUG: true + on: workflow_dispatch: pull_request: From 4c4442291fed39cdf09b2b2dd347421e2ea6df6e Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:33:47 -0700 Subject: [PATCH 4/9] fix: log more information --- dist/index.js | 3 ++- src/main.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 44509fa..b55d852 100644 --- a/dist/index.js +++ b/dist/index.js @@ -98,6 +98,7 @@ const main = async () => { const regex = new RegExp(`${team.key}-(?\d+)`, "gim"); (0, core_1.debug)(`Checking PR for indentifier ${team.key}-XYZ`); const check = regex.exec(prBranch + " " + prTitle + " " + prBody); + console.log(check); // TODO: Iterate over multiple matches and not just first match const issueNumber = check?.groups?.issueNumber; if (issueNumber) { @@ -116,7 +117,7 @@ const main = async () => { } } } - (0, core_1.setFailed)(`Failed to find Linear issue identifier in PR branch, title or body.`); + (0, core_1.setFailed)(`Failed to find Linear issue identifier in PR branch, title, or body.`); return; } catch (error) { diff --git a/src/main.ts b/src/main.ts index 3e35bd2..3060ac1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -39,6 +39,7 @@ const main = async () => { const regex = new RegExp(`${team.key}-(?\d+)`, "gim"); debug(`Checking PR for indentifier ${team.key}-XYZ`); const check = regex.exec(prBranch + " " + prTitle + " " + prBody); + console.log(check); // TODO: Iterate over multiple matches and not just first match const issueNumber = check?.groups?.issueNumber; if (issueNumber) { From 6f53f4f2321363332cc85d24fa073a9b23b3ffa2 Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:42:14 -0700 Subject: [PATCH 5/9] more logging --- dist/index.js | 5 +++-- src/main.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index b55d852..43a7bfe 100644 --- a/dist/index.js +++ b/dist/index.js @@ -95,8 +95,9 @@ const main = async () => { return; } for (const team of teams) { - const regex = new RegExp(`${team.key}-(?\d+)`, "gim"); - (0, core_1.debug)(`Checking PR for indentifier ${team.key}-XYZ`); + const regexString = `${team.key}-(?\d+)`; + const regex = new RegExp(regexString, "gim"); + (0, core_1.debug)(`Checking PR for indentifier "${regexString}"`); const check = regex.exec(prBranch + " " + prTitle + " " + prBody); console.log(check); // TODO: Iterate over multiple matches and not just first match diff --git a/src/main.ts b/src/main.ts index 3060ac1..a61690e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,8 +36,9 @@ const main = async () => { } for (const team of teams) { - const regex = new RegExp(`${team.key}-(?\d+)`, "gim"); - debug(`Checking PR for indentifier ${team.key}-XYZ`); + const regexString = `${team.key}-(?\d+)`; + const regex = new RegExp(regexString, "gim"); + debug(`Checking PR for indentifier "${regexString}"`); const check = regex.exec(prBranch + " " + prTitle + " " + prBody); console.log(check); // TODO: Iterate over multiple matches and not just first match From 4e59d068a0094546b68c43b70b28f8afc55ff5ef Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:44:05 -0700 Subject: [PATCH 6/9] more logging --- src/main.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index a61690e..ad91a30 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,7 +38,11 @@ const main = async () => { for (const team of teams) { const regexString = `${team.key}-(?\d+)`; const regex = new RegExp(regexString, "gim"); - debug(`Checking PR for indentifier "${regexString}"`); + debug( + `Checking PR for indentifier "${regexString}" in "${ + prBranch + " " + prTitle + " " + prBody + }"` + ); const check = regex.exec(prBranch + " " + prTitle + " " + prBody); console.log(check); // TODO: Iterate over multiple matches and not just first match From d53dd307e41e8189c741b8d8e684d860455c43ff Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:44:33 -0700 Subject: [PATCH 7/9] more logging --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 43a7bfe..ab86e86 100644 --- a/dist/index.js +++ b/dist/index.js @@ -97,7 +97,7 @@ const main = async () => { for (const team of teams) { const regexString = `${team.key}-(?\d+)`; const regex = new RegExp(regexString, "gim"); - (0, core_1.debug)(`Checking PR for indentifier "${regexString}"`); + (0, core_1.debug)(`Checking PR for indentifier "${regexString}" in "${prBranch + " " + prTitle + " " + prBody}"`); const check = regex.exec(prBranch + " " + prTitle + " " + prBody); console.log(check); // TODO: Iterate over multiple matches and not just first match From d3453d099af8be909c8ec2cd835ef85250c56db7 Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:47:08 -0700 Subject: [PATCH 8/9] more logging --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index ab86e86..16f81b8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -95,7 +95,7 @@ const main = async () => { return; } for (const team of teams) { - const regexString = `${team.key}-(?\d+)`; + const regexString = `${team.key}-(?\\d+)`; const regex = new RegExp(regexString, "gim"); (0, core_1.debug)(`Checking PR for indentifier "${regexString}" in "${prBranch + " " + prTitle + " " + prBody}"`); const check = regex.exec(prBranch + " " + prTitle + " " + prBody); diff --git a/src/main.ts b/src/main.ts index ad91a30..cd75d3d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,7 +36,7 @@ const main = async () => { } for (const team of teams) { - const regexString = `${team.key}-(?\d+)`; + const regexString = `${team.key}-(?\\d+)`; const regex = new RegExp(regexString, "gim"); debug( `Checking PR for indentifier "${regexString}" in "${ From dddf019a174948c79e4eb769203ac70c57e78f76 Mon Sep 17 00:00:00 2001 From: Christopher Triolo Date: Sun, 8 May 2022 13:51:43 -0700 Subject: [PATCH 9/9] more logging --- dist/index.js | 8 ++++---- src/main.ts | 13 +++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index 16f81b8..855d1e7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -95,12 +95,12 @@ const main = async () => { return; } for (const team of teams) { + // TODO: Iterate over multiple matches and not just first match const regexString = `${team.key}-(?\\d+)`; const regex = new RegExp(regexString, "gim"); - (0, core_1.debug)(`Checking PR for indentifier "${regexString}" in "${prBranch + " " + prTitle + " " + prBody}"`); - const check = regex.exec(prBranch + " " + prTitle + " " + prBody); - console.log(check); - // TODO: Iterate over multiple matches and not just first match + const haystack = prBranch + " " + prTitle + " " + prBody; + (0, core_1.debug)(`Checking PR for indentifier "${regexString}" in "${haystack}"`); + const check = regex.exec(haystack); const issueNumber = check?.groups?.issueNumber; if (issueNumber) { (0, core_1.debug)(`Found issue number: ${issueNumber}`); diff --git a/src/main.ts b/src/main.ts index cd75d3d..074ca97 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,17 +36,14 @@ const main = async () => { } for (const team of teams) { + // TODO: Iterate over multiple matches and not just first match const regexString = `${team.key}-(?\\d+)`; const regex = new RegExp(regexString, "gim"); - debug( - `Checking PR for indentifier "${regexString}" in "${ - prBranch + " " + prTitle + " " + prBody - }"` - ); - const check = regex.exec(prBranch + " " + prTitle + " " + prBody); - console.log(check); - // TODO: Iterate over multiple matches and not just first match + 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(