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

Customize the pass and fail emojis #53

Merged
merged 5 commits into from
Jul 25, 2023
Merged
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
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ for [Creating a workflow file](https://help.github.com/en/articles/configuring-a
- `token` - [**required**] Github personal token to add commits to Pull Request
- `min-coverage-overall` - [*optional*] The minimum code coverage that is required to pass for overall project
- `min-coverage-changed-files` - [*optional*] The minimum code coverage that is required to pass for changed files
- `update-comment` - [*optional*] If true, updates the previous coverage report comment instead of creating new one.
- `update-comment` - [*optional* {default: false}] If true, updates the previous coverage report comment instead of creating new one.
Requires `title` to work properly
- `title` - [*optional*] Title for the Pull Request comment
- `skip-if-no-changes` - [*optional*] If true, comment won't be added if there is no coverage information present for
- `skip-if-no-changes` - [*optional* {default: false}] If true, comment won't be added if there is no coverage information present for
the files changed
- `debug-mode` - [*optional*] If true, run the action in debug mode and get debug logs printed in console
- `pass-emoji` - [*optional* {default: :green_apple:}] Emoji to use for pass status shown when 'coverage >= min coverage' (should be a Github supported emoji).
- `fail-emoji` - [*optional* {default: :x:}] Emoji to use for fail status shown when 'coverage < min coverage' (should be a Github supported emoji).
- `debug-mode` - [*optional* {default: false}] If true, run the action in debug mode and get debug logs printed in console

### Outputs

Expand Down Expand Up @@ -139,6 +141,26 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p
min-coverage-changed-files: 60
```

4. When you need to customize the pass/fail emojis in the comment

> Set the `pass-emoji` and `fail-emoji` to a valid emoji supported in Github.
> Refer [sample pull request](https://github.com/thsaravana/jacoco-android-playground/pull/10) and
> its [workflow](https://github.com/thsaravana/jacoco-android-playground/blob/testing-custom-emoji-support/.github/workflows/coverage.yml)

```yaml
- name: Jacoco Report to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
title: ':lobster: Coverage Report'
pass-emoji: ':green_circle:'
fail-emoji: ':red_circle:'
```

## Troubleshooting

1. If the PR is created by bots like _dependabot_, then the GITHUB_TOKEN won't have sufficient access to write the
Expand Down
4 changes: 4 additions & 0 deletions __tests__/action_aggregate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe('Aggregate report', function () {
return 45
case 'min-coverage-changed-files':
return 60
case 'pass-emoji':
return ':green_apple:'
case 'fail-emoji':
return ':x:'
case 'debug-mode':
return 'true'
}
Expand Down
4 changes: 4 additions & 0 deletions __tests__/action_multiple.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ describe('Multiple reports', function () {
return 45
case 'min-coverage-changed-files':
return 60
case 'pass-emoji':
return ':green_apple:'
case 'fail-emoji':
return ':x:'
case 'debug-mode':
return 'false'
}
Expand Down
71 changes: 51 additions & 20 deletions __tests__/action_single.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe('Single report', function () {
return 45
case 'min-coverage-changed-files':
return 60
case 'pass-emoji':
return ':green_apple:'
case 'fail-emoji':
return ':x:'
case 'debug-mode':
return 'true'
}
Expand Down Expand Up @@ -97,6 +101,26 @@ describe('Single report', function () {
|[Math.kt](https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt)|46.67%|:x:|`)
})

it('set overall coverage output', async () => {
initContext(eventName, payload)
core.setOutput = output

await action.action()

const out = output.mock.calls[0]
expect(out).toEqual(['coverage-overall', 49.02])
})

it('set changed files coverage output', async () => {
initContext(eventName, payload)
core.setOutput = output

await action.action()

const out = output.mock.calls[1]
expect(out).toEqual(['coverage-changed-files', 63.64])
})

describe('With update-comment ON', function () {
const title = 'JaCoCo Report'
function mockInput(key) {
Expand Down Expand Up @@ -172,26 +196,6 @@ describe('Single report', function () {
})
})

it('set overall coverage output', async () => {
initContext(eventName, payload)
core.setOutput = output

await action.action()

const out = output.mock.calls[0]
expect(out).toEqual(['coverage-overall', 49.02])
})

it('set changed files coverage output', async () => {
initContext(eventName, payload)
core.setOutput = output

await action.action()

const out = output.mock.calls[1]
expect(out).toEqual(['coverage-changed-files', 63.64])
})

describe('Skip if no changes set to true', function () {
function mockInput() {
core.getInput = jest.fn((c) => {
Expand Down Expand Up @@ -254,6 +258,33 @@ describe('Single report', function () {
expect(createComment).not.toHaveBeenCalled()
})
})

describe('With custom emoji', function () {
it('publish proper comment', async () => {
initContext(eventName, payload)
core.getInput = jest.fn((key) => {
switch (key) {
case 'pass-emoji':
return ':green_circle:'
case 'fail-emoji':
return 'red_circle'
default:
return getInput(key)
}
})

await action.action()

expect(createComment.mock.calls[0][0].body)
.toEqual(`|Total Project Coverage|49.02%|:green_circle:|
|:-|:-:|:-:|

|File|Coverage [63.64%]||
|:-|:-:|:-:|
|[StringOp.java](https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java)|100%|:green_circle:|
|[Math.kt](https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt)|46.67%|red_circle|`)
})
})
})

describe('Pull Request Target event', function () {
Expand Down
51 changes: 38 additions & 13 deletions __tests__/render.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const render = require('../src/render')

describe('get PR Comment', function () {
const emoji = {
pass: ':green_apple:',
fail: ':x:',
}
describe('no modules', function () {
const project = {
modules: [],
'coverage-changed-files': 100,
}
it('coverage greater than min coverage', function () {
const comment = render.getPRComment(49.23, project, 30, 50)
const comment = render.getPRComment(49.23, project, 30, 50, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:green_apple:|
|:-|:-:|:-:|
Expand All @@ -17,7 +21,7 @@ describe('get PR Comment', function () {
})

it('coverage lesser than min coverage', function () {
const comment = render.getPRComment(49.23, project, 70, 50)
const comment = render.getPRComment(49.23, project, 70, 50, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:x:|
|:-|:-:|:-:|
Expand All @@ -27,7 +31,14 @@ describe('get PR Comment', function () {
})

it('with title', function () {
const comment = render.getPRComment(49.23, project, 70, 50, 'Coverage')
const comment = render.getPRComment(
49.23,
project,
70,
50,
'Coverage',
emoji
)
expect(comment).toEqual(
`### Coverage
|Total Project Coverage|49.23%|:x:|
Expand Down Expand Up @@ -70,7 +81,7 @@ describe('get PR Comment', function () {
}

it('coverage greater than min coverage for overall project', function () {
const comment = render.getPRComment(49.23, project, 30, 60)
const comment = render.getPRComment(49.23, project, 30, 60, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:green_apple:|
|:-|:-:|:-:|
Expand All @@ -83,7 +94,7 @@ describe('get PR Comment', function () {
})

it('coverage lesser than min coverage for overall project', function () {
const comment = render.getPRComment(49.23, project, 50, 64)
const comment = render.getPRComment(49.23, project, 50, 64, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:x:|
|:-|:-:|:-:|
Expand All @@ -96,7 +107,7 @@ describe('get PR Comment', function () {
})

it('coverage lesser than min coverage for changed files', function () {
const comment = render.getPRComment(49.23, project, 30, 80)
const comment = render.getPRComment(49.23, project, 30, 80, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:green_apple:|
|:-|:-:|:-:|
Expand All @@ -109,7 +120,7 @@ describe('get PR Comment', function () {
})

it('coverage greater than min coverage for changed files', function () {
const comment = render.getPRComment(49.23, project, 50, 20)
const comment = render.getPRComment(49.23, project, 50, 20, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:x:|
|:-|:-:|:-:|
Expand All @@ -122,7 +133,14 @@ describe('get PR Comment', function () {
})

it('with title', function () {
const comment = render.getPRComment(49.23, project, 50, 20, 'Coverage')
const comment = render.getPRComment(
49.23,
project,
50,
20,
'Coverage',
emoji
)
expect(comment).toEqual(
`### Coverage
|Total Project Coverage|49.23%|:x:|
Expand Down Expand Up @@ -182,7 +200,7 @@ describe('get PR Comment', function () {
}

it('coverage greater than min coverage for overall project', function () {
const comment = render.getPRComment(49.23, project, 30, 60)
const comment = render.getPRComment(49.23, project, 30, 60, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:green_apple:|
|:-|:-:|:-:|
Expand All @@ -206,7 +224,7 @@ describe('get PR Comment', function () {
})

it('coverage lesser than min coverage for overall project', function () {
const comment = render.getPRComment(49.23, project, 50, 64)
const comment = render.getPRComment(49.23, project, 50, 64, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:x:|
|:-|:-:|:-:|
Expand All @@ -230,7 +248,7 @@ describe('get PR Comment', function () {
})

it('coverage lesser than min coverage for changed files', function () {
const comment = render.getPRComment(49.23, project, 30, 80)
const comment = render.getPRComment(49.23, project, 30, 80, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:green_apple:|
|:-|:-:|:-:|
Expand All @@ -254,7 +272,7 @@ describe('get PR Comment', function () {
})

it('coverage greater than min coverage for changed files', function () {
const comment = render.getPRComment(49.23, project, 50, 20)
const comment = render.getPRComment(49.23, project, 50, 20, '', emoji)
expect(comment).toEqual(
`|Total Project Coverage|49.23%|:x:|
|:-|:-:|:-:|
Expand All @@ -278,7 +296,14 @@ describe('get PR Comment', function () {
})

it('with title', function () {
const comment = render.getPRComment(49.23, project, 50, 20, 'Coverage')
const comment = render.getPRComment(
49.23,
project,
50,
20,
'Coverage',
emoji
)
expect(comment).toEqual(
`### Coverage
|Total Project Coverage|49.23%|:x:|
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ inputs:
description: "Comment won't be added if there is no coverage information present for the files changed"
required: false
default: 'false'
pass-emoji:
description: 'Github emoji to use for pass status shown when coverage greater than min coverage (should be a Github supported emoji)'
required: false
default: ':green_apple:'
fail-emoji:
description: 'Github emoji to use for fail status shown when coverage lesser than min coverage (should be a Github supported emoji)'
required: false
default: ':x:'
debug-mode:
description: 'Run the action in debug mode and get debug logs printed in console'
required: false
Expand Down
Loading