From 06486fb1992eeb3fb4f8e9ec9fc1930f37dc1260 Mon Sep 17 00:00:00 2001 From: Volkan Tokmak Date: Sat, 1 Oct 2022 00:32:56 +0200 Subject: [PATCH 1/5] feat: introduces tag cretion for hot fix releases --- bin/index.js | 2 +- bin/utils/command.js | 5 +++++ bin/utils/flow.js | 5 +++-- bin/utils/helper.js | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/index.js b/bin/index.js index 70eda18..6163920 100755 --- a/bin/index.js +++ b/bin/index.js @@ -69,7 +69,7 @@ async function prepareRelease(changeLog, repoOwner, releaseRepo, lastReleaseTag) let changeLogDetails = templateUtils.generateChangelog(preparedChangeLog, repoOwner, releaseRepo, lastReleaseTag, helper.releaseTagName(options.tag)); let releaseName = helper.releaseName(options.releaseName) const releaseUrl = await flow.createRelease(repoOwner, releaseRepo, options.draft, releaseName, - changeLogDetails, options.tag); + changeLogDetails, options.tag, options.hotfix); // play yaba sound if the release successfully created helper.playSound(options.sound); diff --git a/bin/utils/command.js b/bin/utils/command.js index 7a32092..358443e 100644 --- a/bin/utils/command.js +++ b/bin/utils/command.js @@ -19,6 +19,11 @@ const commands = yargs describe: "Creates the release as draft.", type: "boolean" }) + .option("h", { + alias: "hotfix", + describe: "Prepares the release with hotfix tag.", + type: "boolean" + }) .option("c", { alias: "changelog", describe: "Shows only changelog without creating the release.", diff --git a/bin/utils/flow.js b/bin/utils/flow.js index 612fe1a..d950c83 100755 --- a/bin/utils/flow.js +++ b/bin/utils/flow.js @@ -169,9 +169,10 @@ module.exports = { * @param name the name/title of the release * @param body the changelog to be defined in the release * @param tag_name the tag name + * @param hotfix checks if the tag name must be created as hotfix or not * @returns {Promise} */ - createRelease: async function (owner, repo, draft, name, body, tag_name) { + createRelease: async function (owner, repo, draft, name, body, tag_name, hotfix) { try { spinner.start('Preparing the release...'); @@ -182,7 +183,7 @@ module.exports = { draft: draft, name: helper.releaseName(name), body: body, - tag_name: helper.releaseTagName(tag_name) + tag_name: helper.releaseTagName(tag_name, hotfix) }); // if the user terminal supports hyperlink, this will be a clickable link, otherwise prints plain text. diff --git a/bin/utils/helper.js b/bin/utils/helper.js index 4f46534..1457f92 100755 --- a/bin/utils/helper.js +++ b/bin/utils/helper.js @@ -22,12 +22,16 @@ module.exports = { * this prepares the tag name in 'prod_global_yyyy-MM-dd.1' format. * * @param tagName the given tag name + * @param hotfix checks if the tag name must be created as hotfix or not * @returns {string|*} the prepared tag name */ - releaseTagName: function (tagName) { + releaseTagName: function (tagName, hotfix) { if (stringUtils.isBlank(tagName)) { const currentDate = format(new Date(), constants.TAG_DATE_FORMAT); + if (hotfix) { + return `hotfix_prod_globl_${currentDate}.1`; + } return `prod_global_${currentDate}.1`; } From ed3b84767dd36e69249af3edd00decbc84bfad7c Mon Sep 17 00:00:00 2001 From: Volkan Tokmak Date: Sat, 1 Oct 2022 03:54:11 +0200 Subject: [PATCH 2/5] changes hotfix command to 'f' --- bin/utils/command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/utils/command.js b/bin/utils/command.js index 358443e..0a76f32 100644 --- a/bin/utils/command.js +++ b/bin/utils/command.js @@ -19,7 +19,7 @@ const commands = yargs describe: "Creates the release as draft.", type: "boolean" }) - .option("h", { + .option("f", { alias: "hotfix", describe: "Prepares the release with hotfix tag.", type: "boolean" From 1edd1178a0bbf321144fb5d9eac4fafaf44ef01a Mon Sep 17 00:00:00 2001 From: Volkan Tokmak Date: Sat, 1 Oct 2022 04:03:04 +0200 Subject: [PATCH 3/5] changes hotfix release name --- bin/index.js | 2 +- bin/utils/flow.js | 2 +- bin/utils/helper.js | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/index.js b/bin/index.js index 6163920..cd2c31d 100755 --- a/bin/index.js +++ b/bin/index.js @@ -67,7 +67,7 @@ async function prepareRelease(changeLog, repoOwner, releaseRepo, lastReleaseTag) if (hasReleaseCreatePermission) { let preparedChangeLog = helper.prepareChangeLog(options.body, changeLog); let changeLogDetails = templateUtils.generateChangelog(preparedChangeLog, repoOwner, releaseRepo, lastReleaseTag, helper.releaseTagName(options.tag)); - let releaseName = helper.releaseName(options.releaseName) + let releaseName = helper.releaseName(options.releaseName, options.hotfix); const releaseUrl = await flow.createRelease(repoOwner, releaseRepo, options.draft, releaseName, changeLogDetails, options.tag, options.hotfix); diff --git a/bin/utils/flow.js b/bin/utils/flow.js index d950c83..7cc4e05 100755 --- a/bin/utils/flow.js +++ b/bin/utils/flow.js @@ -181,7 +181,7 @@ module.exports = { owner: owner, repo: repo, draft: draft, - name: helper.releaseName(name), + name: name, body: body, tag_name: helper.releaseTagName(tag_name, hotfix) }); diff --git a/bin/utils/helper.js b/bin/utils/helper.js index 1457f92..e7cda6f 100755 --- a/bin/utils/helper.js +++ b/bin/utils/helper.js @@ -42,10 +42,15 @@ module.exports = { * prepares the title of the release. if the given {@code name} is blank, this prepares * the title in 'Global release yyyy-MM-dd' format. * @param name the given release name + * @param hotfix checks if the release name must be created as hotfix or not * @returns {string|*} */ - releaseName: function (name) { - return stringUtils.isBlank(name) ? `Global release ${this.releaseDate()}` : name; + releaseName: function (name, hotfix) { + if(stringUtils.isBlank(name)) { + let releaseName = `Global release ${this.releaseDate()}`; + return hotfix ? 'Hotfix - ' + releaseName : releaseName; + } + return name; }, /** From b2259c14c2a9cb8ce6af64db0f65c1b53489bc19 Mon Sep 17 00:00:00 2001 From: Volkan Tokmak Date: Sat, 1 Oct 2022 17:07:49 +0200 Subject: [PATCH 4/5] adds check not to create hotfix over master/main branches --- bin/index.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/bin/index.js b/bin/index.js index cd2c31d..477ae55 100755 --- a/bin/index.js +++ b/bin/index.js @@ -7,6 +7,7 @@ const flow = require('./utils/flow.js'); const options = require('./utils/command.js').options; const templateUtils = require('./utils/template-utils.js'); const boxen = require('boxen'); +const { exec } = require('child_process'); runYaba(); @@ -17,18 +18,21 @@ async function runYaba() { // https://www.npmjs.com/package/tiny-updater OR https://www.npmjs.com/package/update-notifier // can be used instead below method. - await tool.checkUpdate(); // check if the yaba cli has newer version + // check if the yaba cli has newer version + await tool.checkUpdate(); + // check required ENV variables - flow.checkRequiredEnvVariables(); + // check if the current directory is git repo + checkDirectory(); - checkDirectory() // check internet connection - await flow.checkInternetConnection(); - // prepare username, repoOwner and releaseRepo + checkHotfixRelease(); + + // prepare username, repoOwner and releaseRepo const username = await flow.retrieveUsername(); const repoOwner = helper.retrieveOwner(options.owner, username); const releaseRepo = helper.retrieveReleaseRepo(options.repo); @@ -44,7 +48,7 @@ async function runYaba() { // show only changelog if (canShowChangelog(changeLog)) { - printChangelog(releaseRepo, changeLog); + printChangelog(changeLog); } // create the release @@ -99,7 +103,28 @@ function checkDirectory() { } } -function printChangelog(repoName, changeLog) { +function checkHotfixRelease() { + // check if the current branch is not main/master and command has hotfix flag + exec('git branch --show-current', (err, stdout, stderr) => { + if (err) { + console.log(`An error occurred: ${err.message}`); + process.exit(); + } + + if (stderr) { + console.error(`An error occurred: ${stderr}`); + process.exit(); + } + + const currentBranch = stdout; + if (currentBranch == 'master' || currentBranch == 'main') { + console.log(kleur.red("you can not create hotfix from main or master branches!")); + process.exit(); + } + }); +} + +function printChangelog(changeLog) { const changelogBoxOptions = { padding: 1, title: 'Changelog', From 2eb286eef526ef6384da905a11748a0676cbd85e Mon Sep 17 00:00:00 2001 From: Volkan Tokmak Date: Sat, 1 Oct 2022 17:44:52 +0200 Subject: [PATCH 5/5] fixes result of the current branch --- bin/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/index.js b/bin/index.js index 477ae55..87e8a64 100755 --- a/bin/index.js +++ b/bin/index.js @@ -116,8 +116,8 @@ function checkHotfixRelease() { process.exit(); } - const currentBranch = stdout; - if (currentBranch == 'master' || currentBranch == 'main') { + const currentBranch = stdout.trim(); + if (currentBranch === 'master' || currentBranch === 'main') { console.log(kleur.red("you can not create hotfix from main or master branches!")); process.exit(); }