Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add issue number input parameter #101

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog of the Jest Coverage Comment

## [Jest Coverage Comment 1.0.28](https://github.com/MishaKav/jest-coverage-comment/tree/v1.0.28)

**Release Date:** 2024-10-27

#### Changes

- Add the ability to specify the `issue-number` of the issue being commented on as an optional argument. Helpfull when triggering the workflow manually (for example `workflow_dispatch` event)

## [Jest Coverage Comment 1.0.27](https://github.com/MishaKav/jest-coverage-comment/tree/v1.0.27)

**Release Date:** 2024-09-18
Expand Down
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
4 changes: 3 additions & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-coverage-comment",
"version": "1.0.27",
"version": "1.0.28",
"description": "Comments a pull request or commit with the jest code coverage badge, full report and tests summary",
"author": "Misha Kav <[email protected]>",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion src/create-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ 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