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

v5 #4

Merged
merged 17 commits into from
Nov 21, 2022
Prev Previous commit
Next Next commit
Refactor structure
  • Loading branch information
carmocca committed Nov 13, 2022
commit 13924610850faa79d10eeae8393893342142e63a
4 changes: 2 additions & 2 deletions dist/check-group/core/config_getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchConfig = void 0;
var utils_1 = require("../utils");
var user_config_parser_1 = require("./user_config_parser");
var core = __importStar(require("@actions/core"));
/**
* Fetches the app configuration from the user's repository.
Expand Down Expand Up @@ -106,7 +106,7 @@ var fetchConfig = function (context) { return __awaiter(void 0, void 0, void 0,
_a.label = 4;
case 4:
core.debug("configData: ".concat(JSON.stringify(configData)));
return [2 /*return*/, (0, utils_1.parseUserConfig)(configData)];
return [2 /*return*/, (0, user_config_parser_1.parseUserConfig)(configData)];
}
});
}); };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.comment = exports.getPrComment = exports.formPrComment = exports.PR_COMMENT_START = exports.generateProgressDetails = exports.statusToMark = exports.generateProgressSummary = exports.generateProgressReport = void 0;
exports.commentOnPr = exports.generateProgressDetails = exports.generateProgressSummary = void 0;
var generateProgressReport = function (subprojects, checksStatusLookup) {
var report = {
completed: [],
Expand Down Expand Up @@ -75,10 +75,9 @@ var generateProgressReport = function (subprojects, checksStatusLookup) {
});
return report;
};
exports.generateProgressReport = generateProgressReport;
var generateProgressSummary = function (subprojects, checksStatusLookup) {
var _a, _b;
var report = (0, exports.generateProgressReport)(subprojects, checksStatusLookup);
var report = generateProgressReport(subprojects, checksStatusLookup);
var message = "Progress: ".concat((_a = report.completed) === null || _a === void 0 ? void 0 : _a.length, " completed, ").concat((_b = report.running) === null || _b === void 0 ? void 0 : _b.length, " pending");
return message;
};
Expand All @@ -97,7 +96,6 @@ var statusToMark = function (check, checksStatusLookup) {
}
return "❓";
};
exports.statusToMark = statusToMark;
/**
* Generates a progress report for currently finished checks
* which will be posted in the status check report.
Expand All @@ -113,7 +111,7 @@ var generateProgressDetails = function (subprojects, checksStatusLookup) {
// for padding
var longestLength = Math.max.apply(Math, (subproject.checks.map(function (check) { return check.id.length; })));
subproject.checks.forEach(function (check) {
var mark = (0, exports.statusToMark)(check.id, checksStatusLookup);
var mark = statusToMark(check.id, checksStatusLookup);
var status = (check.id in checksStatusLookup) ? checksStatusLookup[check.id] : 'no_status';
status = status || 'undefined';
progress += "".concat(check.id.padEnd(longestLength, ' '), " | ").concat(mark, " | ").concat(status.padEnd(12, ' '), "\n");
Expand All @@ -127,7 +125,7 @@ var generateProgressDetails = function (subprojects, checksStatusLookup) {
longestLength = Math.max(longestLength, availableCheck.length);
}
for (var availableCheck in checksStatusLookup) {
var mark = (0, exports.statusToMark)(availableCheck, checksStatusLookup);
var mark = statusToMark(availableCheck, checksStatusLookup);
var status_2 = (availableCheck in checksStatusLookup) ? checksStatusLookup[availableCheck] : 'no_status';
status_2 = status_2 || 'undefined';
progress += "".concat(availableCheck.padEnd(longestLength, ' '), " | ").concat(mark, " | ").concat(status_2.padEnd(12, ' '), "\n");
Expand All @@ -136,16 +134,15 @@ var generateProgressDetails = function (subprojects, checksStatusLookup) {
return progress;
};
exports.generateProgressDetails = generateProgressDetails;
exports.PR_COMMENT_START = "<!-- checkgroup-comment-start -->";
var PR_COMMENT_START = "<!-- checkgroup-comment-start -->";
function formPrComment() {
return (exports.PR_COMMENT_START
return (PR_COMMENT_START
+ "\nHello! This is a test"
+ "\nThis comment was automatically generated by CheckGroup");
}
exports.formPrComment = formPrComment;
function getPrComment(context) {
return __awaiter(this, void 0, void 0, function () {
var params, commentsRes, _i, _a, comment_1;
var params, commentsRes, _i, _a, comment;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
Expand All @@ -154,18 +151,17 @@ function getPrComment(context) {
case 1:
commentsRes = _b.sent();
for (_i = 0, _a = commentsRes.data; _i < _a.length; _i++) {
comment_1 = _a[_i];
if (comment_1.body.includes(exports.PR_COMMENT_START)) {
return [2 /*return*/, { id: comment_1.id, body: comment_1.body }];
comment = _a[_i];
if (comment.body.includes(PR_COMMENT_START)) {
return [2 /*return*/, { id: comment.id, body: comment.body }];
}
}
return [2 /*return*/, { id: 0, body: "" }];
}
});
});
}
exports.getPrComment = getPrComment;
function comment(context) {
function commentOnPr(context) {
return __awaiter(this, void 0, void 0, function () {
var existingData, newComment;
return __generator(this, function (_a) {
Expand All @@ -192,4 +188,4 @@ function comment(context) {
});
});
}
exports.comment = comment;
exports.commentOnPr = commentOnPr;
21 changes: 11 additions & 10 deletions dist/check-group/core/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"use strict";
/**
* @module Core
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
Expand Down Expand Up @@ -63,12 +60,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchConfig = exports.CheckGroup = void 0;
var utils_1 = require("../utils");
/**
* @module Core
*/
var core = __importStar(require("@actions/core"));
var generate_progress_1 = require("./generate_progress");
var subproj_matching_1 = require("./subproj_matching");
var satisfy_expected_checks_1 = require("./satisfy_expected_checks");
var config_getter_1 = require("./config_getter");
Object.defineProperty(exports, "fetchConfig", { enumerable: true, get: function () { return config_getter_1.fetchConfig; } });
var utils_2 = require("../utils");
var utils_3 = require("../utils");
/**
* The orchestration class.
*/
Expand All @@ -91,7 +91,7 @@ var CheckGroup = /** @class */ (function () {
case 1:
filenames = _a.sent();
core.info("Files are: ".concat(JSON.stringify(filenames)));
subprojs = (0, utils_2.matchFilenamesToSubprojects)(filenames, this.config.subProjects);
subprojs = (0, subproj_matching_1.matchFilenamesToSubprojects)(filenames, this.config.subProjects);
core.debug("Matching subprojects are: ".concat(JSON.stringify(subprojs)));
if (core.isDebug()) {
expectedChecks = collectExpectedChecks(subprojs);
Expand Down Expand Up @@ -129,7 +129,7 @@ var CheckGroup = /** @class */ (function () {
case 1:
postedChecks = _a.sent();
core.debug("postedChecks: ".concat(JSON.stringify(postedChecks)));
conclusion = (0, utils_3.satisfyExpectedChecks)(subprojs, postedChecks);
conclusion = (0, satisfy_expected_checks_1.satisfyExpectedChecks)(subprojs, postedChecks);
this.notifyProgress(subprojs, postedChecks, conclusion);
core.endGroup();
if (conclusion === "all_passing") {
Expand Down Expand Up @@ -157,9 +157,10 @@ var CheckGroup = /** @class */ (function () {
return __awaiter(this, void 0, void 0, function () {
var summary, details;
return __generator(this, function (_a) {
summary = (0, utils_1.generateProgressSummary)(subprojs, postedChecks);
details = (0, utils_1.generateProgressDetails)(subprojs, postedChecks);
summary = (0, generate_progress_1.generateProgressSummary)(subprojs, postedChecks);
details = (0, generate_progress_1.generateProgressDetails)(subprojs, postedChecks);
core.info("".concat(this.config.customServiceName, " conclusion: '").concat(conclusion, "':\n").concat(summary, "\n").concat(details));
(0, generate_progress_1.commentOnPr)(this.context);
return [2 /*return*/];
});
});
Expand Down
21 changes: 0 additions & 21 deletions dist/check-group/utils/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/check-group/core/config_getter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CheckGroupConfig } from "../types";
import { Context } from "probot";
import { parseUserConfig } from "../utils";
import { parseUserConfig } from "./user_config_parser";
import { PullRequestEvent } from '@octokit/webhooks-types';
import * as core from '@actions/core'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ProgressReport, SubProjConfig } from "../types";
import { Context } from "probot";


export const generateProgressReport = (
const generateProgressReport = (
subprojects: SubProjConfig[],
checksStatusLookup: Record<string, string>,
): ProgressReport => {
Expand Down Expand Up @@ -52,7 +52,7 @@ export const generateProgressSummary = (
return message;
};

export const statusToMark = (
const statusToMark = (
check: string,
checksStatusLookup: Record<string, string>,
): string => {
Expand Down Expand Up @@ -112,17 +112,17 @@ export const generateProgressDetails = (
return progress;
};

export const PR_COMMENT_START = "<!-- checkgroup-comment-start -->";
const PR_COMMENT_START = "<!-- checkgroup-comment-start -->";

export function formPrComment(): string {
function formPrComment(): string {
return (
PR_COMMENT_START
+ `\nHello! This is a test`
+ "\nThis comment was automatically generated by CheckGroup"
)
}

export async function getPrComment(context: Context): Promise<{id: number; body: string}> {
async function getPrComment(context: Context): Promise<{id: number; body: string}> {
const params = context.issue()
const commentsRes = await context.octokit.rest.issues.listComments(params);
for (const comment of commentsRes.data) {
Expand All @@ -134,7 +134,7 @@ export async function getPrComment(context: Context): Promise<{id: number; body:
}


export async function comment(context: Context) {
export async function commentOnPr(context: Context) {
const existingData = await getPrComment(context);
context.log.debug(`existingData: ${JSON.stringify(existingData)}`)
const newComment = formPrComment();
Expand Down
18 changes: 9 additions & 9 deletions src/check-group/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/**
* @module Core
*/

import {
import * as core from '@actions/core'
import {
generateProgressDetails,
generateProgressSummary,
} from "../utils";
import * as core from '@actions/core'
import type { CheckGroupConfig, CheckResult } from "../types";
import type { Context } from "probot";
commentOnPr,
} from "./generate_progress";
import { matchFilenamesToSubprojects } from "./subproj_matching";
import { satisfyExpectedChecks } from "./satisfy_expected_checks";
import { fetchConfig } from "./config_getter";
import { matchFilenamesToSubprojects } from "../utils";
import { satisfyExpectedChecks } from "../utils";
import { SubProjConfig } from "../types";
import type { CheckGroupConfig, CheckResult, SubProjConfig } from "../types";
import type { Context } from "probot";

/**
* The orchestration class.
Expand Down Expand Up @@ -106,6 +105,7 @@ export class CheckGroup {
core.info(
`${this.config.customServiceName} conclusion: '${conclusion}':\n${summary}\n${details}`
)
commentOnPr(this.context)
}

/**
Expand Down
25 changes: 0 additions & 25 deletions src/check-group/utils/index.ts

This file was deleted.