Skip to content

Commit

Permalink
feat: receive branch name from input parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdevpereira committed Sep 26, 2022
1 parent c9183b9 commit d0f04a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
githubToken:
description: "The github token that will be used to comment the results on available pull requests."
required: true
branchName:
description: "The name of the branch that triggered the workflow."
required: true
cloudflareProjectName:
description: "The name of the project on Cloudflare that will receive the coverage report."
required: true
Expand Down
30 changes: 14 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const COVERAGE_OUTPUT_FOLDER = "./coverage";
const input = {
framework: core.getInput("framework"),
githubToken: core.getInput("githubToken", { required: true }),
branchName: core.getInput("branchName", { required: true }),
cloudflareProjectName: core.getInput("cloudflareProjectName", {
required: true,
}),
Expand Down Expand Up @@ -114,14 +115,14 @@ const COVERAGE_OUTPUT_FOLDER = "./coverage";
* https://octokit.github.io/rest.js/v19
**/
core.startGroup("Comment on available pull requests...");
const octokit = new github.getOctokit(input.githubToken);
const octokit = github.getOctokit(input.githubToken);

const BRANCH_NAME = github.context.ref;
const BRANCH_COMMIT = commitShortHash;
const UPLOAD_URL = `https://${commitShortHash}.${input.baseCloudflareDeploymentUrl}`;
core.info("BRANCH_NAME: ", BRANCH_NAME);
core.info("BRANCH_COMMIT: ", BRANCH_COMMIT);
core.info("UPLOAD_URL: ", UPLOAD_URL);
core.info(`BRANCH_NAME: ${input.branchName}`);
core.info(`BRANCH_COMMIT: ${BRANCH_COMMIT}`);
core.info(`UPLOAD_URL: ${UPLOAD_URL}`);

// Get coverage summary with retries
const getCoverageSummary = async (
Expand Down Expand Up @@ -163,12 +164,11 @@ const COVERAGE_OUTPUT_FOLDER = "./coverage";
}
};

// Get open pull requests for $BRANCH_NAME
const { data: pulls } = await octokit.rest.search.issuesAndPullRequests({
q: `is:pr state:open repo:${github.context.repo.owner}/${github.context.repo.repo} head:${BRANCH_NAME}`,
q: `is:pr state:open repo:${github.context.repo.owner}/${github.context.repo.repo} head:${input.branchName}`,
});

core.info("Pull requests available: ", pulls);
core.info(`Pull requests available: ${JSON.stringify(pulls)}`);

if (pulls.total_count > 0) {
pulls.items.forEach(async (pull) => {
Expand Down Expand Up @@ -240,19 +240,17 @@ const COVERAGE_OUTPUT_FOLDER = "./coverage";
if (headAvgPercentage > baseAvgPercentage) {
coverageMessage = `\n> Wooo 🎉, the tests are passing and the coverage percentage **increased** with this pull request, well done! 👏\n> ${
pullRequest.base.ref
}: **${Math.round(
baseAvgPercentage,
-1
)}%** | ${BRANCH_NAME}: **${Math.round(headAvgPercentage, -1)}%**`;
}: **${Math.round(baseAvgPercentage, -1)}%** | ${
input.branchName
}: **${Math.round(headAvgPercentage, -1)}%**`;
} else if (headAvgPercentage === baseAvgPercentage) {
coverageMessage = `\n> Good job 👌, the tests are passing and the coverage percentage remained intact.`;
} else {
coverageMessage = `\n> Tests are passing but the coverage percentage **is decreased** 😱 by this pull request, read coverage report below for more details.\n\n🔻 ${
pullRequest.base.ref
}: **${Math.round(
baseAvgPercentage,
-1
)}%** | ${BRANCH_NAME}: **${Math.round(headAvgPercentage, -1)}%** 🔻`;
}: **${Math.round(baseAvgPercentage, -1)}%** | ${
input.branchName
}: **${Math.round(headAvgPercentage, -1)}%** 🔻`;
}

let coverageSummaryTable = `
Expand Down Expand Up @@ -328,7 +326,7 @@ const COVERAGE_OUTPUT_FOLDER = "./coverage";
- Time: **${timeTaken}**
</details>
> Coverage data is based on head **${BRANCH_NAME}** (\`${BRANCH_COMMIT}\`) compared to base **${pullRequest.base.ref}** (\`${shortBaseSha}\`).
> Coverage data is based on head **${input.branchName}** (\`${BRANCH_COMMIT}\`) compared to base **${pullRequest.base.ref}** (\`${shortBaseSha}\`).
[View full coverage report 🔗](${UPLOAD_URL})`;

Expand Down

0 comments on commit d0f04a9

Please sign in to comment.