From 8bbc30502d50b0160beeffae10d042de4f9c48d6 Mon Sep 17 00:00:00 2001 From: Oliver Yates Date: Fri, 16 Jul 2021 14:30:06 +0100 Subject: [PATCH 1/6] Add a project name to differentiate statuses --- .../src/github-notifier-plugin.ts | 8 +++++++- .../src/gcs-publisher-plugin.ts | 8 +++++++- .../src/s3-publisher-plugin.ts | 8 +++++++- packages/reg-suit-interface/src/core.ts | 5 +++++ packages/reg-suit-interface/src/plugin.ts | 3 ++- packages/reg-suit-util/src/cloud-storage-util.ts | 15 ++++++++++++--- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts index aabcd24a..fa9c89fb 100644 --- a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts +++ b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts @@ -53,6 +53,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin _apiPrefix!: string; _repo!: Repository; + _projectName: string | undefined; _decodeClientId(clientId: string) { const tmp = inflateRawSync(new Buffer(clientId, "base64")).toString().split("/"); @@ -77,6 +78,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin this._setCommitStatus = config.options.setCommitStatus !== false; this._apiPrefix = config.options.customEndpoint || getGhAppInfo().endpoint; this._repo = new Repository(path.join(fsUtil.prjRootDir(".git"), ".git")); + this._projectName = config.projectConfig.name; } notify(params: NotifyParams): Promise { @@ -87,7 +89,10 @@ export class GitHubNotifierPlugin implements NotifierPlugin const deletedItemsCount = deletedItems.length; const passedItemsCount = passedItems.length; const state = failedItemsCount + newItemsCount + deletedItemsCount === 0 ? "success" : "failure"; - const description = state === "success" ? "Regression testing passed" : "Regression testing failed"; + + const name = this._projectName; + const formattedName = `${name && `${name}: `}`; + const description = state === "success" ? `${formattedName}Regression testing passed` : `${formattedName}Regression testing failed`; let sha1: string; if (head.branch) { @@ -118,6 +123,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin method: "POST", body: updateStatusBody, json: true, + context: name }; this._logger.info(`Update status for ${this._logger.colors.green(updateStatusBody.sha1)} .`); this._logger.verbose("update-status: ", statusReq); diff --git a/packages/reg-publish-gcs-plugin/src/gcs-publisher-plugin.ts b/packages/reg-publish-gcs-plugin/src/gcs-publisher-plugin.ts index 17840c07..544a25eb 100644 --- a/packages/reg-publish-gcs-plugin/src/gcs-publisher-plugin.ts +++ b/packages/reg-publish-gcs-plugin/src/gcs-publisher-plugin.ts @@ -2,7 +2,7 @@ import path from "path"; import mkdirp from "mkdirp"; import { Storage, GetFilesOptions } from "@google-cloud/storage"; -import { WorkingDirectoryInfo, PublisherPlugin, PluginCreateOptions } from "reg-suit-interface"; +import { WorkingDirectoryInfo, PublisherPlugin, PluginCreateOptions, ProjectConfig } from "reg-suit-interface"; import { AbstractPublisher, RemoteFileItem, FileItem, ObjectListResult } from "reg-suit-util"; export interface PluginConfig { @@ -16,6 +16,7 @@ export class GcsPublisherPlugin extends AbstractPublisher implements PublisherPl name = "reg-publish-gcs-plugin"; private _options!: PluginCreateOptions; + private _projectOptions!: ProjectConfig; private _pluginConfig!: PluginConfig; private _gcsClient!: Storage; @@ -26,6 +27,7 @@ export class GcsPublisherPlugin extends AbstractPublisher implements PublisherPl init(config: PluginCreateOptions) { this.noEmit = config.noEmit; this.logger = config.logger; + this._projectOptions = config.projectConfig; this._options = config; this._pluginConfig = { ...config.options, @@ -60,6 +62,10 @@ export class GcsPublisherPlugin extends AbstractPublisher implements PublisherPl return this._pluginConfig.bucketName; } + protected getProjectName(): string | undefined { + return this._projectOptions.name; + } + protected getLocalGlobPattern(): string | undefined { return this._pluginConfig.pattern; } diff --git a/packages/reg-publish-s3-plugin/src/s3-publisher-plugin.ts b/packages/reg-publish-s3-plugin/src/s3-publisher-plugin.ts index 65311710..03ed38d2 100644 --- a/packages/reg-publish-s3-plugin/src/s3-publisher-plugin.ts +++ b/packages/reg-publish-s3-plugin/src/s3-publisher-plugin.ts @@ -4,7 +4,7 @@ import zlib from "zlib"; import { S3 } from "aws-sdk"; import mkdirp from "mkdirp"; -import { PublisherPlugin, PluginCreateOptions, WorkingDirectoryInfo } from "reg-suit-interface"; +import { PublisherPlugin, PluginCreateOptions, WorkingDirectoryInfo, ProjectConfig } from "reg-suit-interface"; import { FileItem, RemoteFileItem, ObjectListResult, AbstractPublisher } from "reg-suit-util"; export interface PluginConfig { @@ -21,6 +21,7 @@ export class S3PublisherPlugin extends AbstractPublisher implements PublisherPlu name = "reg-publish-s3-plugin"; private _options!: PluginCreateOptions; + private _projectOptions!: ProjectConfig; private _pluginConfig!: PluginConfig; private _s3client!: S3; @@ -31,6 +32,7 @@ export class S3PublisherPlugin extends AbstractPublisher implements PublisherPlu init(config: PluginCreateOptions) { this.noEmit = config.noEmit; this.logger = config.logger; + this._projectOptions = config.projectConfig; this._options = config; this._pluginConfig = { ...config.options, @@ -73,6 +75,10 @@ export class S3PublisherPlugin extends AbstractPublisher implements PublisherPlu return this._options.workingDirs; } + protected getProjectName(): string | undefined { + return this._projectOptions.name; + } + protected uploadItem(key: string, item: FileItem): Promise { return new Promise((resolve, reject) => { fs.readFile(item.absPath, (err, content) => { diff --git a/packages/reg-suit-interface/src/core.ts b/packages/reg-suit-interface/src/core.ts index 48d2d4c1..3bde94f1 100644 --- a/packages/reg-suit-interface/src/core.ts +++ b/packages/reg-suit-interface/src/core.ts @@ -1,5 +1,9 @@ export type AdditionalDetectionInvocationType = "none" | "cli" | "client"; +export interface ProjectConfig { + name?: string +} + export interface CoreConfig { actualDir: string; workingDir: string; @@ -21,6 +25,7 @@ export interface WorkingDirectoryInfo { } export interface RegSuitConfiguration { + project: ProjectConfig; core: CoreConfig; plugins?: { [key: string]: any; diff --git a/packages/reg-suit-interface/src/plugin.ts b/packages/reg-suit-interface/src/plugin.ts index 6f292896..aa54139d 100644 --- a/packages/reg-suit-interface/src/plugin.ts +++ b/packages/reg-suit-interface/src/plugin.ts @@ -1,5 +1,5 @@ import { Question } from "inquirer"; -import { CoreConfig, ComparisonResult, WorkingDirectoryInfo } from "./core"; +import { CoreConfig, ComparisonResult, WorkingDirectoryInfo, ProjectConfig } from "./core"; import { Logger } from "./logger"; export type PluginLogger = Logger; @@ -31,6 +31,7 @@ export interface Notifier { export interface PluginCreateOptions { coreConfig: CoreConfig; + projectConfig: ProjectConfig; workingDirs: WorkingDirectoryInfo; logger: Logger; noEmit: boolean; diff --git a/packages/reg-suit-util/src/cloud-storage-util.ts b/packages/reg-suit-util/src/cloud-storage-util.ts index a745690b..3c58fc5b 100644 --- a/packages/reg-suit-util/src/cloud-storage-util.ts +++ b/packages/reg-suit-util/src/cloud-storage-util.ts @@ -40,6 +40,7 @@ export abstract class AbstractPublisher { protected abstract getLocalGlobPattern(): string | undefined; protected abstract getBucketName(): string; protected abstract getBucketRootDir(): string | undefined; + protected abstract getProjectName(): string | undefined; protected createList(): Promise { return new Promise((resolve, reject) => { @@ -71,11 +72,19 @@ export abstract class AbstractPublisher { } protected resolveInBucket(key: string) { - if (this.getBucketRootDir()) { + if (this.getBucketRootDir() && !this.getProjectName()) { return this.getBucketRootDir() + "/" + key; - } else { - return key; } + + if (this.getBucketRootDir() && this.getProjectName()) { + return this.getBucketRootDir() + "/" + this.getProjectName() + "/" + key; + } + + if (!this.getBucketRootDir() && this.getProjectName()) { + return this.getProjectName() + "/" + key; + } + + return key; } protected fetchInternal(key: string): Promise { From b3d1a234c916f2fa01d4339c1b44ec1925cebc0f Mon Sep 17 00:00:00 2001 From: Oliver Yates Date: Fri, 16 Jul 2021 16:25:16 +0100 Subject: [PATCH 2/6] Update package.json --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5633e515..a8d7566d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,8 @@ { - "private": true, + "private": false, + "name": "reg-suit", + "version": "0.0.0", + "repository": "https://github.com/olijyat/reg-suit", "scripts": { "clean": "rimraf \"packages/*/lib\"", "build": "lerna run prepublish", From 602cbf56715f686ea3b5ec23827e30437935219a Mon Sep 17 00:00:00 2001 From: Oliver Yates Date: Mon, 19 Jul 2021 11:35:46 +0100 Subject: [PATCH 3/6] Make private --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8d7566d..bf1ff744 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "private": false, + "private": true, "name": "reg-suit", "version": "0.0.0", "repository": "https://github.com/olijyat/reg-suit", From 8f515a3c10d05158c8e883a465e7e5784757c2d5 Mon Sep 17 00:00:00 2001 From: Oliver Yates Date: Mon, 19 Jul 2021 16:01:04 +0100 Subject: [PATCH 4/6] wip --- package.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bf1ff744..a93dda28 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { - "private": true, - "name": "reg-suit", - "version": "0.0.0", - "repository": "https://github.com/olijyat/reg-suit", + "private": false, + "name": "reg-suit-olijyat", + "version": "1.0.1", "scripts": { "clean": "rimraf \"packages/*/lib\"", "build": "lerna run prepublish", @@ -21,8 +20,7 @@ "watch:core": "tsc -w -p packages/reg-suit-core/tsconfig.build.json", "watch:cli": "tsc -w -p packages/reg-suit-cli/tsconfig.build.json", "watch:util": "tsc -w -p packages/reg-suit-util/tsconfig.build.json", - "watch": "run-p watch:*", - "postinstall": "husky install" + "watch": "run-p watch:*" }, "devDependencies": { "@types/node": "14.17.4", From 3685c85183d5a6b1bb54cf291dce13b6017c47a0 Mon Sep 17 00:00:00 2001 From: Oliver Yates Date: Mon, 19 Jul 2021 16:02:20 +0100 Subject: [PATCH 5/6] Make private --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a93dda28..47e808da 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "private": false, + "private": true, "name": "reg-suit-olijyat", "version": "1.0.1", "scripts": { From ee08b4b0fd51d5ff666d552b8d54cff397e64133 Mon Sep 17 00:00:00 2001 From: Oliver Yates Date: Mon, 19 Jul 2021 16:16:52 +0100 Subject: [PATCH 6/6] wip --- package.json | 2 +- packages/reg-notify-github-plugin/package.json | 5 ++--- .../reg-notify-github-plugin/src/github-notifier-plugin.ts | 7 ++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 47e808da..06d0d350 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "name": "reg-suit-olijyat", + "name": "reg-suit", "version": "1.0.1", "scripts": { "clean": "rimraf \"packages/*/lib\"", diff --git a/packages/reg-notify-github-plugin/package.json b/packages/reg-notify-github-plugin/package.json index 9bfaa3a8..01abecab 100644 --- a/packages/reg-notify-github-plugin/package.json +++ b/packages/reg-notify-github-plugin/package.json @@ -1,6 +1,6 @@ { - "name": "reg-notify-github-plugin", - "version": "0.10.16", + "name": "reg-notify-github-plugin-olijyat", + "version": "0.0.1", "description": "Notify reg-suit result to GitHub repository", "regSuitPlugin": { "recommended": true @@ -19,7 +19,6 @@ "name": "Quramy", "email": "yosuke.kurami@gmail.com" }, - "repository": "git+https://github.com/reg-viz/reg-suit.git", "license": "MIT", "devDependencies": { "@types/jest": "26.0.24", diff --git a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts index fa9c89fb..90527f06 100644 --- a/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts +++ b/packages/reg-notify-github-plugin/src/github-notifier-plugin.ts @@ -92,7 +92,8 @@ export class GitHubNotifierPlugin implements NotifierPlugin const name = this._projectName; const formattedName = `${name && `${name}: `}`; - const description = state === "success" ? `${formattedName}Regression testing passed` : `${formattedName}Regression testing failed`; + const description = + state === "success" ? `${formattedName}Regression testing passed` : `${formattedName}Regression testing failed`; let sha1: string; if (head.branch) { @@ -118,12 +119,12 @@ export class GitHubNotifierPlugin implements NotifierPlugin const reqs = []; if (this._setCommitStatus) { - const statusReq: rp.OptionsWithUri = { + const statusReq: any = { uri: `${this._apiPrefix}/api/update-status`, method: "POST", body: updateStatusBody, json: true, - context: name + context: name, }; this._logger.info(`Update status for ${this._logger.colors.green(updateStatusBody.sha1)} .`); this._logger.verbose("update-status: ", statusReq);