Rewrite/refactor for v5, migrate to TypeScript (MAJOR)

Set Jest config file in package script

Include module path

Include tests in project folders

Remove index module exports

Hardcode configuration parameters

Move parameter binding into main run function

Use alias imports

Run test sequentially

Remove cleanup (async conflict)

Revert Jest option

Increase test timeout to 15 seconds
This commit is contained in:
Paul Hatcherian 2022-04-03 17:49:40 -04:00
parent dc8f0c5755
commit 31f4e3fdf0
74 changed files with 9422 additions and 4342 deletions

View file

@ -0,0 +1,14 @@
import { ActionConfig } from '../ActionConfig';
import { UserInfo } from '../providers/UserInfo';
import { UserFormatter } from './UserFormatter';
export class CsvUserFormatter implements UserFormatter {
constructor(config: ActionConfig) {
// placeholder for consistency with other formatters
}
public Format(type: string, users: UserInfo[]): string {
return users.map(user => `${user.name} <${user.email}>`).join(', ');
}
}

View file

@ -0,0 +1,65 @@
import { TagFormatter } from './TagFormatter';
import { VersionInformation } from "../providers/VersionInformation";
import { ActionConfig } from '../ActionConfig';
/** Default tag formatter which allows a prefix to be specified */
export class DefaultTagFormatter implements TagFormatter {
private tagPrefix: string;
private namespace: string;
private namespaceSeperator: string;
constructor(config: ActionConfig) {
this.namespace = config.namespace;
this.tagPrefix = config.tagPrefix;
this.namespaceSeperator = '-'; // maybe make configurable in the future
}
public Format(versionInfo: VersionInformation): string {
const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`;
if (!!this.namespace) {
return `${result}${this.namespaceSeperator}${this.namespace}`;
}
return result;
}
public GetPattern(): string {
if (!!this.namespace) {
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]${this.namespaceSeperator}${this.namespace}`;
}
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
}
public Parse(tag: string): [major: number, minor: number, patch: number] {
let stripedTag;
if (this.tagPrefix.includes('/') && tag.includes(this.tagPrefix)) {
let tagParts = tag
.replace(this.tagPrefix, '<--!PREFIX!-->')
.split('/');
stripedTag = tagParts[tagParts.length - 1]
.replace('<--!PREFIX!-->', this.tagPrefix);
} else {
let tagParts = tag.split('/');
stripedTag = tagParts[tagParts.length - 1];
}
let versionValues = stripedTag
.substring(this.tagPrefix.length)
.slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1))
.split('.');
let major = parseInt(versionValues[0]);
let minor = versionValues.length > 1 ? parseInt(versionValues[1]) : 0;
let patch = versionValues.length > 2 ? parseInt(versionValues[2]) : 0;
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
throw `Invalid tag ${tag} (${versionValues})`;
}
return [major, minor, patch];
};
}

View file

@ -0,0 +1,20 @@
import { VersionFormatter } from './VersionFormatter';
import { VersionInformation } from "../providers/VersionInformation";
import { ActionConfig } from '../ActionConfig';
export class DefaultVersionFormatter implements VersionFormatter {
private formatString: string;
constructor(config: ActionConfig) {
this.formatString = config.versionFormat;
}
public Format(versionInfo: VersionInformation): string {
return this.formatString
.replace('${major}', versionInfo.major.toString())
.replace('${minor}', versionInfo.minor.toString())
.replace('${patch}', versionInfo.patch.toString())
.replace('${increment}', versionInfo.increment.toString());
}
}

View file

@ -0,0 +1,13 @@
import { ActionConfig } from '../ActionConfig';
import { UserInfo } from '../providers/UserInfo';
import { UserFormatter } from './UserFormatter';
export class JsonUserFormatter implements UserFormatter {
constructor(config: ActionConfig) {
// placeholder for consistency with other formatters
}
public Format(type: string, users: UserInfo[]): string {
let result: any = users.map(u => ({ name: u.name, email: u.email }));
return JSON.stringify(result).replace('\n', '');
}
}

View file

@ -0,0 +1,7 @@
import { VersionInformation } from "../providers/VersionInformation";
export interface TagFormatter {
Format(versionInfo: VersionInformation): string;
GetPattern(): string;
Parse(tag: string): [major: number, minor: number, patch: number];
}

View file

@ -0,0 +1,6 @@
import { UserInfo } from "../providers/UserInfo";
/** Formats a list of users as a string (e.g. JSON, YAML, CSV, etc) */
export interface UserFormatter {
Format(type: string, users: UserInfo[]): string;
}

View file

@ -0,0 +1,6 @@
import { VersionInformation } from "../providers/VersionInformation";
// Formatters
export interface VersionFormatter {
Format(versionInfo: VersionInformation): string;
}