From 68891e818b40bb96cc4be2435c4168fd1dd4a44b Mon Sep 17 00:00:00 2001 From: Misha Kav Date: Sun, 27 Oct 2024 15:09:19 -0400 Subject: [PATCH] Add issue number input parameter Fixes #97 Add the ability to specify the issue number of the issue being commented on as an optional argument. * Add `issue-number` input parameter in `action.yml` to specify the issue number. * Update `createComment` function in `src/create-comment.ts` to accept `issueNumber` from `options` if provided, otherwise fallback to the current logic. * Add logic in `src/index.ts` to retrieve the `issue-number` input parameter and pass it to the `createComment` function. * Update `README.md` to include documentation for the new `issue-number` input parameter. * Add `issueNumber` to `Options` interface in `src/types.d.ts`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/MishaKav/jest-coverage-comment/issues/97?shareId=XXXX-XXXX-XXXX-XXXX). --- README.md | 3 ++- action.yml | 4 ++++ src/create-comment.ts | 2 +- src/index.ts | 2 ++ src/types.d.ts | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed19cfd..a89c4c4 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. `runs-o | `multiple-files` | | '' | You can pass array of `json-summary.json` files and generate single comment with table of results
Single line should look like `Title1, ./path/to/json-summary.json` | | `multiple-junitxml-files` | | '' | You can pass array of `junit.xml` files and generate single comment with table of results
Single line should look like `Title1, ./path/to/junit.xml` | | `unique-id-for-comment` | | '' | When running in a matrix, pass the matrix value, so each comment will be updated its own comment `unique-id-for-comment: ${{ matrix.node-version }}` | +| `issue-number` | | '' | Specify the issue number to comment on | ## Output Variables @@ -77,7 +78,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. `runs-o > | Lines | Statements | Branches | Functions | > | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ------------ | ---------- | > | Coverage: 78%
| 76.74% (33/43) | 33.33% (2/6) | 100% (0/0) | -> + > ## My JUnit Title > > | Tests | Skipped | Failures | Errors | Time | diff --git a/action.yml b/action.yml index 3d08c72..f88ed6a 100644 --- a/action.yml +++ b/action.yml @@ -104,6 +104,10 @@ inputs: default: '' required: false + issue-number: + description: 'Specify the issue number to comment on (when triggering the workflow manually)' + required: false + outputs: coverage: description: 'Value indicating the coverage percentage of your report based on Jest, example 78' diff --git a/src/create-comment.ts b/src/create-comment.ts index 7161aa9..217fc3e 100644 --- a/src/create-comment.ts +++ b/src/create-comment.ts @@ -13,7 +13,7 @@ export async function createComment( const { repo, owner } = context.repo const octokit = getOctokit(options.token) - const issue_number = payload.pull_request ? payload.pull_request.number : 0 + const issue_number = options.issueNumber || (payload.pull_request ? payload.pull_request.number : 0) if (body.length > MAX_COMMENT_LENGTH) { const warningsArr = [ diff --git a/src/index.ts b/src/index.ts index 2bd2e62..b23a88d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,6 +59,7 @@ async function main(): Promise { const uniqueIdForComment = core.getInput('unique-id-for-comment', { required: false, }) + const issueNumber = core.getInput('issue-number', { required: false }) const serverUrl = context.serverUrl || 'https://github.com' core.info(`Uses Github URL: ${serverUrl}`) @@ -95,6 +96,7 @@ async function main(): Promise { reportOnlyChangedFiles, multipleFiles, multipleJunitFiles, + issueNumber: issueNumber ? parseInt(issueNumber) : undefined, } if (eventName === 'pull_request' && payload) { diff --git a/src/types.d.ts b/src/types.d.ts index c4ee608..b464fb6 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -25,6 +25,7 @@ export interface Options { changedFiles?: ChangedFiles | null multipleFiles?: string[] multipleJunitFiles?: string[] + issueNumber?: number } export interface ChangedFiles {