Skip to content

Commit

Permalink
Merge pull request #2 from quicktype/use-comment
Browse files Browse the repository at this point in the history
Use comment
  • Loading branch information
jassmith authored May 23, 2020
2 parents ffa26c1 + ad97769 commit 5f0bd9c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
14 changes: 9 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29690,27 +29690,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.publishTestResults = void 0;
const github = __importStar(__webpack_require__(469));
const config_1 = __webpack_require__(478);
function createCheckWithAnnotations(summary, conclusion, octokit) {
function createCheck(summary, conclusion, githubKit) {
return __awaiter(this, void 0, void 0, function* () {
const commentRequest = Object.assign(Object.assign({}, github.context.repo), { issue_number: github.context.issue.number, body: summary });
const checkRequest = Object.assign(Object.assign({}, github.context.repo), { head_sha: github.context.sha, name: "Storyshots", conclusion, output: {
title: "Jest Test Results",
summary,
} });
try {
yield octokit.checks.create(checkRequest);
if (conclusion === "failure") {
yield githubKit.issues.createComment(commentRequest);
}
yield githubKit.checks.create(checkRequest);
}
catch (error) {
throw new Error(`Request to create annotations failed - request: ${JSON.stringify(checkRequest)} - error: ${error.message} `);
throw new Error(`Request to create annotations failed - request: ${JSON.stringify(commentRequest)} - error: ${error.message} `);
}
});
}
function publishTestResults(testInformation) {
return __awaiter(this, void 0, void 0, function* () {
const { time, passed, failed, total, conclusion } = testInformation;
const octokit = new github.GitHub(config_1.config.accessToken);
const githubKit = new github.GitHub(config_1.config.accessToken);
const summary = "#### These are all the test results I was able to find from your jest-junit reporter\n" +
`**${total}** tests were completed in **${time}s** with **${passed}** passed ✔ and **${failed}** failed ✖ tests.`;
yield createCheckWithAnnotations(summary, conclusion, octokit);
yield createCheck(summary, conclusion, githubKit);
});
}
exports.publishTestResults = publishTestResults;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "jest-storyshots-reporter",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"description": "Github actions for reporting jest storyshots results",
"main": "lib/main.js",
"scripts": {
"build": "tsc --extendedDiagnostics",
"buildpack": "npm run build && npm run pack",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
Expand Down
26 changes: 18 additions & 8 deletions src/github-api.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import * as github from "@actions/github";
import { config } from "./config";
import * as octorest from "@octokit/rest";
import * as octokit from "@octokit/rest";

type Conclusion = "success" | "failure" | "neutral" | "cancelled" | "timed_out" | "action_required" | undefined;

async function createCheck(summary: string, conclusion: Conclusion, octokit: github.GitHub) {
const checkRequest: octorest.Octokit.RequestOptions & octorest.Octokit.ChecksCreateParams = {
async function createCheck(summary: string, conclusion: Conclusion, githubKit: github.GitHub) {
const commentRequest: octokit.Octokit.RequestOptions & octokit.Octokit.IssuesCreateCommentParams = {
...github.context.repo,
issue_number: github.context.issue.number,
body: summary,
};

const checkRequest: octokit.Octokit.RequestOptions & octokit.Octokit.ChecksCreateParams = {
...github.context.repo,
head_sha: github.context.sha,
name: "Storyshots",
conclusion,
output: {
title: "Jest Test Results",
summary,
text: summary,
},
};

try {
await octokit.checks.create(checkRequest);
if (conclusion === "failure") {
await githubKit.issues.createComment(commentRequest);
}
await githubKit.checks.create(checkRequest);
} catch (error) {
throw new Error(
`Request to create annotations failed - request: ${JSON.stringify(checkRequest)} - error: ${error.message} `
`Request to create annotations failed - request: ${JSON.stringify(commentRequest)} - error: ${
error.message
} `
);
}
}
Expand All @@ -37,10 +47,10 @@ interface TestInfo {
export async function publishTestResults(testInformation: TestInfo) {
const { time, passed, failed, total, conclusion } = testInformation;

const octokit = new github.GitHub(config.accessToken);
const githubKit = new github.GitHub(config.accessToken);
const summary =
"#### These are all the test results I was able to find from your jest-junit reporter\n" +
`**${total}** tests were completed in **${time}s** with **${passed}** passed ✔ and **${failed}** failed ✖ tests.`;

await createCheck(summary, conclusion, octokit);
await createCheck(summary, conclusion, githubKit);
}

0 comments on commit 5f0bd9c

Please sign in to comment.