Skip to content

Commit 7921ef9

Browse files
feat: add app name configuration property (#88)
* feat: update docs * feat: build title based on input param * chore: build new version * test: response from barecheck api * feat: change app-name input for testing * fix: remove console.log * test: add unit test when there error during token fetch * fix: change conditions
1 parent fff1159 commit 7921ef9

14 files changed

Lines changed: 171 additions & 31 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ jobs:
5959
minimum-ratio: 0
6060
send-summary-comment: true
6161
show-annotations: "warning"
62+
app-name: "Github Action"

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To integrate with this Github Action, you can just use following configuration i
3030
```yml
3131
- name: Generate Code Coverage report
3232
id: code-coverage
33-
uses: barecheck/code-coverage-action@v0.4.0
33+
uses: barecheck/code-coverage-action@v0.5.0
3434
with:
3535
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
3636
lcov-file: "./coverage/lcov.info"
@@ -52,6 +52,7 @@ To integrate with this Github Action, you can just use following configuration i
5252
| `send-summary-comment` | **no** | true | Option to send Github code coverage comment based on the changes that were made in PR |
5353
| `show-annotations` | **no** | 'warning' | Option to enable Github anotation that would show uncovered files in review tab. Options: ' ' \| warning \| error |
5454
| `minimum-ratio` | **no** | '' | Percantage of uncovered lines that is allowed for new changes |
55+
| `app-name` | **no** | '' | Application name should be used once you have more then one report in your workflow. |
5556

5657
## Workflow Example
5758

@@ -110,7 +111,7 @@ jobs:
110111
# Compares two code coverage files and generates report as a comment
111112
- name: Generate Code Coverage report
112113
id: code-coverage
113-
uses: barecheck/code-coverage-action@v0.4.0
114+
uses: barecheck/code-coverage-action@v0.5.0
114115
with:
115116
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
116117
lcov-file: "./coverage/lcov.info"
@@ -120,6 +121,34 @@ jobs:
120121
show-annotations: "warning" # Possible options warning|error
121122
```
122123

124+
## Use cases
125+
126+
### Monorepo support
127+
128+
If you have monorepo with more then one application and want to have different code coverage reports you can use `app-name` input property to define different application names that would be used as a part of title.
129+
130+
```yml
131+
- name: Application1 - Generate Code Coverage report
132+
id: code-coverage
133+
uses: barecheck/code-coverage-action@v0.5.0
134+
with:
135+
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
136+
lcov-file: "./coverage/lcov.info"
137+
base-lcov-file: "./coverage/base-lcov.info"
138+
app-name: "Application 1"
139+
```
140+
141+
```yml
142+
- name: Application2 - Generate Code Coverage report
143+
id: code-coverage
144+
uses: barecheck/code-coverage-action@v0.5.0
145+
with:
146+
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
147+
lcov-file: "./coverage/lcov.info"
148+
base-lcov-file: "./coverage/base-lcov.info"
149+
app-name: "Application 2"
150+
```
151+
123152
## Contributing
124153

125154
- Clone this repository

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ inputs:
3030
description: "Shows annotations with uncovered lines in the review. Options: warning|error"
3131
default: "warning"
3232
required: false
33+
app-name:
34+
description: "Application name should be used once you have more then one report in your workflow."
35+
default: ""
36+
required: false
3337
outputs:
3438
percentage:
3539
description: "Total Percentage coverage"

dist/index.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9900,12 +9900,12 @@ function wrappy (fn, cb) {
99009900
/***/ 4570:
99019901
/***/ ((module) => {
99029902

9903-
const commentTitle = "Barecheck - Code coverage report";
9903+
const githubCommentTitle = "Code coverage report";
99049904

99059905
const barecheckApiUrl = "https://api.barecheck.com/graphql";
99069906

99079907
module.exports = {
9908-
commentTitle,
9908+
githubCommentTitle,
99099909
barecheckApiUrl
99109910
};
99119911

@@ -9964,7 +9964,7 @@ const getChangedFiles = __nccwpck_require__(397);
99649964
const createOrUpdateComment = __nccwpck_require__(8646);
99659965
const buildBody = __nccwpck_require__(681);
99669966

9967-
const { commentTitle } = __nccwpck_require__(4570);
9967+
const { buildGithubCommentTitle } = __nccwpck_require__(1006);
99689968

99699969
const sendSummaryComment = async (
99709970
coverageDiff,
@@ -9984,9 +9984,9 @@ const sendSummaryComment = async (
99849984
totalCoverage,
99859985
compareFileData
99869986
);
9987-
9987+
const githubCommentTitle = buildGithubCommentTitle();
99889988
// we can add an option how comments should be added create | update | none
9989-
await createOrUpdateComment(commentTitle, body);
9989+
await createOrUpdateComment(githubCommentTitle, body);
99909990
}
99919991
};
99929992

@@ -10052,7 +10052,7 @@ module.exports = {
1005210052
/***/ 681:
1005310053
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1005410054

10055-
const { commentTitle } = __nccwpck_require__(4570);
10055+
const { buildGithubCommentTitle } = __nccwpck_require__(1006);
1005610056
const { uncoveredFileLinesByFileNames } = __nccwpck_require__(3318);
1005710057
const { mergeFileLinesWithChangedFiles } = __nccwpck_require__(3257);
1005810058

@@ -10065,7 +10065,7 @@ const buildFullMessage = (
1006510065
) => {
1006610066
const coverageDiffOutput = coverageDiff < 0 ? "▾" : "▴";
1006710067
const trendArrow = coverageDiff === 0 ? "" : coverageDiffOutput;
10068-
const header = commentTitle;
10068+
const header = buildGithubCommentTitle();
1006910069
const descTotal = `Total: <b>${totalCoverage}%</b>`;
1007010070
const descCoverageDiff = `Your code coverage diff: <b>${coverageDiff}% ${trendArrow}</b>`;
1007110071
const description = `${descTotal}\n\n${descCoverageDiff}`;
@@ -10328,6 +10328,25 @@ const updateComment = async (commentId, body) => {
1032810328
module.exports = updateComment;
1032910329

1033010330

10331+
/***/ }),
10332+
10333+
/***/ 1006:
10334+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
10335+
10336+
const { getAppName } = __nccwpck_require__(6);
10337+
const { githubCommentTitle } = __nccwpck_require__(4570);
10338+
10339+
const buildGithubCommentTitle = () => {
10340+
const appName = getAppName();
10341+
10342+
return `${appName !== "" ? appName : "Barecheck"} - ${githubCommentTitle}`;
10343+
};
10344+
10345+
module.exports = {
10346+
buildGithubCommentTitle
10347+
};
10348+
10349+
1033110350
/***/ }),
1033210351

1033310352
/***/ 6:
@@ -10355,13 +10374,16 @@ const getShowAnnotations = () => {
1035510374

1035610375
const getGithubToken = () => core.getInput("github-token");
1035710376

10377+
const getAppName = () => core.getInput("app-name");
10378+
1035810379
const getBarecheckGithubAppToken = () =>
1035910380
core.getInput("barecheck-github-app-token");
1036010381

1036110382
module.exports = {
1036210383
getShowAnnotations,
1036310384
getGithubToken,
10364-
getBarecheckGithubAppToken
10385+
getBarecheckGithubAppToken,
10386+
getAppName
1036510387
};
1036610388

1036710389

@@ -10512,15 +10534,15 @@ const createGithubAccessToken = async (githubAppToken) => {
1051210534
githubAppToken
1051310535
};
1051410536

10515-
const { data } = await makeRequest(query, variables);
10537+
const response = await makeRequest(query, variables);
1051610538

10517-
if (!data.createGithubAccessToken.success) {
10539+
if (!response.data && !response.data.createGithubAccessToken.success) {
1051810540
throw new Error(
1051910541
"Couldn't fetch access token for Github application. Check if you use the correct `BARECHECK_GITHUB_APP_TOKEN`"
1052010542
);
1052110543
}
1052210544

10523-
return data.createGithubAccessToken;
10545+
return response.data.createGithubAccessToken;
1052410546
};
1052510547

1052610548
module.exports = {

src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const commentTitle = "Barecheck - Code coverage report";
1+
const githubCommentTitle = "Code coverage report";
22

33
const barecheckApiUrl = "https://api.barecheck.com/graphql";
44

55
module.exports = {
6-
commentTitle,
6+
githubCommentTitle,
77
barecheckApiUrl
88
};

src/features/sendSummaryComment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getChangedFiles = require("../github/getChangedFiles");
44
const createOrUpdateComment = require("../github/createOrUpdateComment");
55
const buildBody = require("../github/comment/buildBody");
66

7-
const { commentTitle } = require("../config");
7+
const { buildGithubCommentTitle } = require("../github/utils");
88

99
const sendSummaryComment = async (
1010
coverageDiff,
@@ -24,9 +24,9 @@ const sendSummaryComment = async (
2424
totalCoverage,
2525
compareFileData
2626
);
27-
27+
const githubCommentTitle = buildGithubCommentTitle();
2828
// we can add an option how comments should be added create | update | none
29-
await createOrUpdateComment(commentTitle, body);
29+
await createOrUpdateComment(githubCommentTitle, body);
3030
}
3131
};
3232

src/github/comment/buildBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { commentTitle } = require("../../config");
1+
const { buildGithubCommentTitle } = require("../utils");
22
const { uncoveredFileLinesByFileNames } = require("../../lcov");
33
const { mergeFileLinesWithChangedFiles } = require("../../coverage");
44

@@ -11,7 +11,7 @@ const buildFullMessage = (
1111
) => {
1212
const coverageDiffOutput = coverageDiff < 0 ? "▾" : "▴";
1313
const trendArrow = coverageDiff === 0 ? "" : coverageDiffOutput;
14-
const header = commentTitle;
14+
const header = buildGithubCommentTitle();
1515
const descTotal = `Total: <b>${totalCoverage}%</b>`;
1616
const descCoverageDiff = `Your code coverage diff: <b>${coverageDiff}% ${trendArrow}</b>`;
1717
const description = `${descTotal}\n\n${descCoverageDiff}`;

src/github/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { getAppName } = require("../input");
2+
const { githubCommentTitle } = require("../config");
3+
4+
const buildGithubCommentTitle = () => {
5+
const appName = getAppName();
6+
7+
return `${appName !== "" ? appName : "Barecheck"} - ${githubCommentTitle}`;
8+
};
9+
10+
module.exports = {
11+
buildGithubCommentTitle
12+
};

src/input.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ const getShowAnnotations = () => {
2020

2121
const getGithubToken = () => core.getInput("github-token");
2222

23+
const getAppName = () => core.getInput("app-name");
24+
2325
const getBarecheckGithubAppToken = () =>
2426
core.getInput("barecheck-github-app-token");
2527

2628
module.exports = {
2729
getShowAnnotations,
2830
getGithubToken,
29-
getBarecheckGithubAppToken
31+
getBarecheckGithubAppToken,
32+
getAppName
3033
};

src/services/barecheckApi.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ const createGithubAccessToken = async (githubAppToken) => {
3232
githubAppToken
3333
};
3434

35-
const { data } = await makeRequest(query, variables);
35+
const response = await makeRequest(query, variables);
3636

37-
if (!data.createGithubAccessToken.success) {
37+
if (!response.data || !response.data.createGithubAccessToken.success) {
3838
throw new Error(
3939
"Couldn't fetch access token for Github application. Check if you use the correct `BARECHECK_GITHUB_APP_TOKEN`"
4040
);
4141
}
4242

43-
return data.createGithubAccessToken;
43+
return response.data.createGithubAccessToken;
4444
};
4545

4646
module.exports = {

0 commit comments

Comments
 (0)