Skip to content

Commit

Permalink
Merge pull request #11 from volkanto/cosmetic-changes
Browse files Browse the repository at this point in the history
fixes #2
  • Loading branch information
volkanto authored Jun 6, 2021
2 parents b1219a0 + b02638c commit 3e92ee8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ npm uninstall -g yaba-release-cli

Go to [Personal Access Tokens](https://github.com/settings/tokens) page on Github and generate new token to enable `yaba` CLI to access your repos.

* Give your desired name to your perosonal access token with `Note` section.
* Give your desired name to your personal access token with `Note` section.
* Choosing `repo` scope is enough to use `yaba` CLI tool.

Now, your personal access token is generated. Copy that token and define that one as an environment variable:
Expand Down Expand Up @@ -93,7 +93,7 @@ By default, if you don't specify `-o`, `-t`, `-n` and `-b` the command will prep

> **IMPORTANT NOTE:** If you don't explicitly define the release as draft with `-d`, `yaba` will directly create the release with given or pre-defined values.
## Local Setup
## Run Locally

You have to clone the repository to your local machine

Expand Down
41 changes: 30 additions & 11 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/env node

// third party lib definitions
const yargs = require("yargs");
const ora = require('ora');
const { Octokit } = require("octokit");
const helper = require('./utils/helper.js');
const pkg = require('../package.json');
const chalk = require("chalk");
const log = console.log;
const error = chalk.bold.red;
const spinner = ora();
const isOnline = require('is-online');
const supportsHyperlinks = require('supports-hyperlinks');
const hyperlinker = require('hyperlinker');

// local variables
const spinner = ora();
const octokit = new Octokit({
auth: process.env.GITHUB_ACCESS_TOKEN
});
Expand All @@ -31,18 +33,26 @@ async function run() {
.option("c", { alias: "changelog", describe: "Shows only changelog without creating the release.", type: "boolean" })
.argv;


spinner.start('Checking required ENV variables...');
if (helper.requiredEnvVariablesExist() == false) {
spinner.fail('The required env variables are not set in order to run the command.');
return;
}
spinner.succeed('Required ENV variables in place.');

if (options.repo == undefined && !helper.isGitRepo()) {
error(`The directory '${helper.retrieveCurrentDirectory()}' is not a Git repo.`);
return;
}

spinner.start('Checking internet connection.');
spinner.start('Checking internet connection...');
const isInternetUp = await isOnline();
if (!isInternetUp) {
spinner.fail('There is no internet connection!');
return;
}
spinner.succeed('Internet connection established');
spinner.succeed('Internet connection established.');

const { data: user } = await octokit.request('GET /user');
const username = user.login;
Expand Down Expand Up @@ -72,10 +82,14 @@ async function run() {
base: latestTagName,
head: headBranch
});
spinner.succeed('Changelog has been prepared...');
if (changeLog.commits.length != 0) {
spinner.succeed('Changelog has been prepared...');
} else {
spinner.succeed(chalk.yellow.underline('Nothing found to release.'));
}

if (options.changelog) {
log('\n\n' + chalk.green.underline(`${releaseRepo} changelog for upcoming release:`) + `\n\n${helper.prepareChangeLog(options.body, changeLog)}\n`);
if (changeLog.commits.length != 0 && options.changelog) {
console.log('\n\n' + chalk.green.underline(`${releaseRepo} changelog for upcoming release:`) + `\n\n${helper.prepareChangeLog(options.body, changeLog)}\n`);
}

if (!options.changelog) {
Expand All @@ -90,16 +104,21 @@ async function run() {
tag_name: helper.releaseTagName(options.tag)
});

spinner.succeed(`Release has been prepared on Github. ${newRelease.html_url}`);
// log(`${newRelease.tag_name} has been created from ${newRelease.target_commitish}. Click the link to check the release ${newRelease.html_url}`);
let releaseMessage;
if (supportsHyperlinks.stdout) {
releaseMessage = hyperlinker('Release has been prepared on Github.', `${newRelease.html_url}`);
} else {
releaseMessage = `Release has been prepared on Github. ${newRelease.html_url}`;
}
spinner.succeed(releaseMessage);

} catch (error) {
spinner.fail(`Something went wrong while preparing the release! => ${error.errors}`);
}
}

} catch (error) {
log(error);
console.log(error);
}
}

Expand Down
7 changes: 7 additions & 0 deletions bin/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ module.exports = {
retrieveHeadBranch: function(branches) {
let headBranch = branches.find(branch => branch.name === 'master' || branch.name === 'main');
return headBranch.name;
},

requiredEnvVariablesExist: function() {
if (process.env.GITHUB_ACCESS_TOKEN) {
return true;
}
return false;
}
}

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
},
"dependencies": {
"chalk": "^4.1.1",
"hyperlinker": "^1.0.0",
"is-online": "^9.0.0",
"octokit": "^1.0.5",
"ora": "^5.4.0",
"supports-hyperlinks": "^2.2.0",
"yargs": "^17.0.1"
},
"keywords": [
Expand Down

0 comments on commit 3e92ee8

Please sign in to comment.