chore: reuse parsing expression

This commit is contained in:
Ivan Peshev 2019-10-24 14:27:01 +03:00 коммит произвёл Ivan Peshev
Родитель 4733b6bb72
Коммит 6c2fb064e0
4 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@ -2,6 +2,7 @@ const analyzeCommits = require('@semantic-release/commit-analyzer')
const SemanticReleaseError = require('@semantic-release/error')
const execSync = require('child_process').execSync;
const lastTag = require('./lastTag');
const utils = require('./utils');
const until = f => array => {
const first = array[0];
@ -23,7 +24,7 @@ const lastTaggedRelease = () => {
module.exports = function (pluginConfig, config, cb) {
// run standard commit analysis
return analyzeCommits(pluginConfig, config, function(error, type) {
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || config.env.GITHUB_REF.split('/').slice(-1)[0];
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || utils.ghParseBranch(config.env.GITHUB_REF);
const branchTags = config.options.branchTags;
const distTag = branchTags && branchTags[branch];

Просмотреть файл

@ -1,6 +1,6 @@
const defaultLastRelease = require('@semantic-release/last-release-npm');
const lastTag = require('./lastTag');
const utils = require('./utils');
module.exports = function (pluginConfig, config, cb) {
let branch;
let oldTag;
@ -8,7 +8,7 @@ module.exports = function (pluginConfig, config, cb) {
if (config.env.TRAVIS) {
branch = config.env.TRAVIS_BRANCH;
} else if (config.env.GITHUB_REF) {
branch = config.env.GITHUB_REF.split('/').slice(-1)[0];
branch = utils.ghParseBranch(config.env.GITHUB_REF);
} else {
branch = config.env.GIT_LOCAL_BRANCH;
}

6
utils.js Normal file
Просмотреть файл

@ -0,0 +1,6 @@
let utils = {};
utils.ghParseBranch = branch => branch.split('/').slice(-1)[0];
module.exports = utils;

Просмотреть файл

@ -1,3 +1,5 @@
const utils = require('./utils');
module.exports = function (pluginConfig, config, cb) {
let branch;
let defaultVerifyConditions;
@ -7,7 +9,7 @@ module.exports = function (pluginConfig, config, cb) {
branch = config.env.TRAVIS_BRANCH;
} else if (config.env.GITHUB_REF) {
defaultVerifyConditions = require('condition-github-actions');
branch = config.env.GITHUB_REF.split('/').slice(-1)[0];
branch = utils.ghParseBranch(config.env.GITHUB_REF);
} else {
defaultVerifyConditions = require('@krux/condition-jenkins');
branch = config.env.GIT_LOCAL_BRANCH;