Skip to content

Commit

Permalink
Add skip if no changes option (#33)
Browse files Browse the repository at this point in the history
* Add skip on no changes option

* Resolving conflicts

* Renaming the parameter

* Added unit tests

* Updating README.md

---------

Co-authored-by: thsaravana <[email protected]>
  • Loading branch information
imbyungjun and thsaravana authored Jul 22, 2023
1 parent 7f612a3 commit 2e0c7d5
Show file tree
Hide file tree
Showing 6 changed files with 16,712 additions and 843 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory

### Inputs

- `paths` - [**required**] Comma separated paths of the generated jacoco xml files.
- `paths` - [**required**] Comma separated paths of the generated jacoco xml files
- `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*] Updates the coverage report comment instead of creating new ones. Requires `title` to work properly.
- `update-comment` - [*optional*] Updates the coverage report comment instead of creating new ones. Requires `title` to work properly
- `title` - [*optional*] Title for the Pull Request comment
- `skip-if-no-changes` - [*optional*] Comment won't be added if there is no coverage information present for the files changed

### Outputs

Expand Down
64 changes: 64 additions & 0 deletions __tests__/action_single.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,70 @@ describe("Single report", function () {
const out = output.mock.calls[1];
expect(out).toEqual(["coverage-changed-files", 63.64]);
});

describe("Skip if no changes set to true", function () {

github.context = context;

function mockInput() {
core.getInput = jest.fn((c) => {
switch (c) {
case "skip-if-no-changes":
return "true";
default:
return getInput(c)
}
});
}

it("Add comment when coverage present for changes files", async () => {
mockInput();

await action.action();

expect(createComment.mock.calls[0][0].body)
.toEqual(`|File|Coverage [63.64%]|:green_apple:|
|:-|:-:|:-:|
|[StringOp.java](https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java)|100%|:green_apple:|
|[Math.kt](https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt)|46.67%|:x:|
|Total Project Coverage|49.02%|:green_apple:|
|:-|:-:|:-:|`);
})

it("Don't add comment when coverage absent for changes files", async () => {
mockInput();
const compareCommitsResponse = {
data: {
files: [
{
filename: "src/main/kotlin/com/madrapps/jacoco/asset.yml",
blob_url:
"https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/asset.yml",
},
],
},
};
github.getOctokit = jest.fn(() => {
return {
repos: {
compareCommits: jest.fn(() => {
return compareCommitsResponse;
}),
},
issues: {
createComment: createComment,
listComments: listComments,
updateComment: updateComment,
},
};
});

await action.action();

expect(createComment).not.toHaveBeenCalled()
})
})
});

describe("Pull Request Target event", function () {
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
description: "Update the coverage report comment instead of creating new ones. Requires title to works properly."
required: false
default: "false"
skip-if-no-changes:
description: "Comment won't be added if there is no coverage information present for the files changed"
required: false
default: "false"
debug-mode:
description: "Run the action in debug mode and get debug logs printed in console"
required: false
Expand Down
Loading

0 comments on commit 2e0c7d5

Please sign in to comment.