UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

42 lines (41 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GithubContentManager = void 0; const github_content_service_1 = require("./github-content-service"); const file_system_utils_1 = require("../../utils/file-system-utils"); const string_utils_1 = require("../../utils/string-utils"); class GithubContentManager { constructor() { } async uploadOrUpdateContent(params) { let response = null; try { response = await github_content_service_1.GithubContentService.instance.getContent(params.githubCredential, params.ownerAndRepository, params.branch, params.remoteFilePath); } catch { } if (!params?.filePath && !params?.fileContent) { throw new Error("filePath and fileContent are required"); } const fileContentBase64 = string_utils_1.StringUtils.encodeBase64(params?.filePath ? file_system_utils_1.FileSystemUtils.loadFile(params.filePath) : params.fileContent || ""); if (response?.content?.replace(/\n/g, "") === fileContentBase64) { return { sha: response.sha, url: response.htmlUrl, }; } return github_content_service_1.GithubContentService.instance.uploadContent({ branch: params.branch, commitMessage: params.commitMessage, githubCredential: params.githubCredential, ownerAndRepository: params.ownerAndRepository, fileContentBase64: fileContentBase64, remoteFilePath: params.remoteFilePath, remoteSHA: response?.sha, }); } static get instance() { if (!this._instance) this._instance = new this(); return this._instance; } } exports.GithubContentManager = GithubContentManager;