UNPKG

@codecovevienna/gittt-cli

Version:

Tracking time with CLI into a git repository

63 lines (62 loc) 3.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigHelper = void 0; class ConfigHelper { constructor(fileHelper) { this.isInitialized = () => __awaiter(this, void 0, void 0, function* () { return (yield this.fileHelper.configDirExists()) && (yield this.fileHelper.isConfigFileValid()); }); this.findLinksByProject = (project, linkType) => __awaiter(this, void 0, void 0, function* () { const configObject = yield this.fileHelper.getConfigObject(); const foundLinks = configObject.links.filter((li) => { // TODO TBD: use different parameters as unique? e.g. more than one jira link per project? if (linkType) { return li.projectName === project.name && li.linkType === linkType; } return li.projectName === project.name; }); return foundLinks; }); this.addOrUpdateLink = (link) => __awaiter(this, void 0, void 0, function* () { const configObject = yield this.fileHelper.getConfigObject(); // TODO check if already exists const cleanLinks = configObject.links.filter((li) => { // TODO linkType can be taken from class // TODO TBD: use different parameters as unique? e.g. more than one jira link per project? return !((li.projectName === link.projectName) && (li.linkType === link.linkType)); }); cleanLinks.push(link); configObject.links = cleanLinks; yield this.fileHelper.saveConfigObject(configObject); return configObject; }); this.fileHelper = fileHelper; } static getInstance(fileHelper) { if (!ConfigHelper.instance) { if (!fileHelper) { throw new Error('ConfigHelper has to be initialized with a FileHelper'); } ConfigHelper.instance = new ConfigHelper(fileHelper); } return ConfigHelper.instance; } static getNewInstance(fileHelper) { if (!fileHelper) { throw new Error('ConfigHelper has to be initialized with a FileHelper'); } ConfigHelper.instance = new ConfigHelper(fileHelper); return ConfigHelper.getInstance(fileHelper); } } exports.ConfigHelper = ConfigHelper;