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

(Issue-165) Add a project name to differentiate statuses (Work in progress) #500

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"private": true,
"name": "reg-suit",
"version": "1.0.1",
"scripts": {
"clean": "rimraf \"packages/*/lib\"",
"build": "lerna run prepublish",
Expand All @@ -18,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",
Expand Down
5 changes: 2 additions & 3 deletions packages/reg-notify-github-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions packages/reg-notify-github-plugin/src/github-notifier-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin<GitHubPluginOption>

_apiPrefix!: string;
_repo!: Repository;
_projectName: string | undefined;

_decodeClientId(clientId: string) {
const tmp = inflateRawSync(new Buffer(clientId, "base64")).toString().split("/");
Expand All @@ -77,6 +78,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin<GitHubPluginOption>
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<any> {
Expand All @@ -87,7 +89,11 @@ export class GitHubNotifierPlugin implements NotifierPlugin<GitHubPluginOption>
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) {
Expand All @@ -113,11 +119,12 @@ export class GitHubNotifierPlugin implements NotifierPlugin<GitHubPluginOption>
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,
};
this._logger.info(`Update status for ${this._logger.colors.green(updateStatusBody.sha1)} .`);
this._logger.verbose("update-status: ", statusReq);
Expand Down
8 changes: 7 additions & 1 deletion packages/reg-publish-gcs-plugin/src/gcs-publisher-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,6 +16,7 @@ export class GcsPublisherPlugin extends AbstractPublisher implements PublisherPl
name = "reg-publish-gcs-plugin";

private _options!: PluginCreateOptions<any>;
private _projectOptions!: ProjectConfig;
private _pluginConfig!: PluginConfig;
private _gcsClient!: Storage;

Expand All @@ -26,6 +27,7 @@ export class GcsPublisherPlugin extends AbstractPublisher implements PublisherPl
init(config: PluginCreateOptions<PluginConfig>) {
this.noEmit = config.noEmit;
this.logger = config.logger;
this._projectOptions = config.projectConfig;
this._options = config;
this._pluginConfig = {
...config.options,
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 7 additions & 1 deletion packages/reg-publish-s3-plugin/src/s3-publisher-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,6 +21,7 @@ export class S3PublisherPlugin extends AbstractPublisher implements PublisherPlu
name = "reg-publish-s3-plugin";

private _options!: PluginCreateOptions<any>;
private _projectOptions!: ProjectConfig;
private _pluginConfig!: PluginConfig;
private _s3client!: S3;

Expand All @@ -31,6 +32,7 @@ export class S3PublisherPlugin extends AbstractPublisher implements PublisherPlu
init(config: PluginCreateOptions<PluginConfig>) {
this.noEmit = config.noEmit;
this.logger = config.logger;
this._projectOptions = config.projectConfig;
this._options = config;
this._pluginConfig = {
...config.options,
Expand Down Expand Up @@ -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<FileItem> {
return new Promise((resolve, reject) => {
fs.readFile(item.absPath, (err, content) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/reg-suit-interface/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export type AdditionalDetectionInvocationType = "none" | "cli" | "client";

export interface ProjectConfig {
name?: string
}

export interface CoreConfig {
actualDir: string;
workingDir: string;
Expand All @@ -21,6 +25,7 @@ export interface WorkingDirectoryInfo {
}

export interface RegSuitConfiguration {
project: ProjectConfig;
core: CoreConfig;
plugins?: {
[key: string]: any;
Expand Down
3 changes: 2 additions & 1 deletion packages/reg-suit-interface/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,6 +31,7 @@ export interface Notifier {

export interface PluginCreateOptions<T = undefined> {
coreConfig: CoreConfig;
projectConfig: ProjectConfig;
workingDirs: WorkingDirectoryInfo;
logger: Logger;
noEmit: boolean;
Expand Down
15 changes: 12 additions & 3 deletions packages/reg-suit-util/src/cloud-storage-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileItem[]> {
return new Promise<string[]>((resolve, reject) => {
Expand Down Expand Up @@ -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<any> {
Expand Down