Skip to content

Commit

Permalink
Add issue number input parameter
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
MishaKav committed Oct 27, 2024
1 parent d742388 commit 68891e8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>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<br/>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

Expand Down Expand Up @@ -77,7 +78,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. `runs-o
> | Lines | Statements | Branches | Functions |
> | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ------------ | ---------- |
> | <a href="https://github.com/MishaKav/api-testing-example/blob/725508e4be6d3bc9d49fa611bd9fba96d5374a13/README.md"><img alt="Coverage: 78%" src="https://img.shields.io/badge/Coverage-78%25-yellow.svg" /></a><br/> | 76.74% (33/43) | 33.33% (2/6) | 100% (0/0) |
>

> ## My JUnit Title
>
> | Tests | Skipped | Failures | Errors | Time |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/create-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function main(): Promise<void> {
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}`)
Expand Down Expand Up @@ -95,6 +96,7 @@ async function main(): Promise<void> {
reportOnlyChangedFiles,
multipleFiles,
multipleJunitFiles,
issueNumber: issueNumber ? parseInt(issueNumber) : undefined,
}

if (eventName === 'pull_request' && payload) {
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Options {
changedFiles?: ChangedFiles | null
multipleFiles?: string[]
multipleJunitFiles?: string[]
issueNumber?: number
}

export interface ChangedFiles {
Expand Down

0 comments on commit 68891e8

Please sign in to comment.