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 skip on no changes option #33

Merged
merged 6 commits into from
Jul 22, 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
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