chore: move getCurrentBranch to a util file (#15921)

* chore: move getCurrentBranch to a util file

* fix import
This commit is contained in:
Shelley Vohr 2018-12-03 13:28:10 -08:00 коммит произвёл GitHub
Родитель a1a431eb87
Коммит d3c58ea48c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 30 добавлений и 53 удалений

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

@ -1,7 +1,12 @@
const OUT_DIR = process.env.ELECTRON_OUT_DIR || 'Debug'
const { GitProcess } = require('dugite')
const path = require('path')
require('colors')
const pass = '\u2713'.green
const fail = '\u2717'.red
function getElectronExec () {
switch (process.platform) {
case 'darwin':
@ -19,7 +24,22 @@ function getAbsoluteElectronExec () {
return path.resolve(__dirname, '../../..', getElectronExec())
}
async function getCurrentBranch (gitDir) {
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
const currentBranch = branchDetails.stdout.trim()
console.log(`${pass} current git branch is: ${currentBranch}`)
return currentBranch
} else {
const error = GitProcess.parseError(branchDetails.stderr)
console.log(`${fail} couldn't get details current branch: `, error)
process.exit(1)
}
}
module.exports = {
getCurrentBranch,
getElectronExec,
getAbsoluteElectronExec,
OUT_DIR

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

@ -1,22 +1,25 @@
#!/usr/bin/env node
if (!process.env.CI) require('dotenv-safe').load()
require('colors')
const args = require('minimist')(process.argv.slice(2), {
boolean: ['automaticRelease', 'notesOnly', 'stable']
})
const ciReleaseBuild = require('./ci-release-build')
const { execSync } = require('child_process')
const fail = '\u2717'.red
const { GitProcess } = require('dugite')
const GitHub = require('github')
const pass = '\u2713'.green
const { execSync } = require('child_process')
const { GitProcess } = require('dugite')
const path = require('path')
const readline = require('readline')
const releaseNotesGenerator = require('./release-notes/index.js')
const { getCurrentBranch } = require('./lib/utils.js')
const versionType = args._[0]
const targetRepo = versionType === 'nightly' ? 'nightlies' : 'electron'
require('colors')
const pass = '\u2713'.green
const fail = '\u2717'.red
// TODO (future) automatically determine version based on conventional commits
// via conventional-recommended-bump
@ -53,23 +56,6 @@ async function getNewVersion (dryRun) {
}
}
async function getCurrentBranch (gitDir) {
console.log(`Determining current git branch`)
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
const currentBranch = branchDetails.stdout.trim()
console.log(`${pass} Successfully determined current git branch is ` +
`${currentBranch}`)
return currentBranch
} else {
const error = GitProcess.parseError(branchDetails.stderr)
console.log(`${fail} Could not get details for the current branch,
error was ${branchDetails.stderr}`, error)
process.exit(1)
}
}
async function getReleaseNotes (currentBranch) {
if (versionType === 'nightly') {
return 'Nightlies do not get release notes, please compare tags for info'

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

@ -3,7 +3,7 @@ const fs = require('fs')
const path = require('path')
const childProcess = require('child_process')
const GitHubApi = require('github')
const { GitProcess } = require('dugite')
const { getCurrentBranch } = require('./lib/utils.js')
const request = require('request')
const semver = require('semver')
const rootPackageJson = require('../package.json')
@ -162,21 +162,3 @@ new Promise((resolve, reject) => {
console.error(`Error: ${err}`)
process.exit(1)
})
async function getCurrentBranch () {
const gitDir = path.resolve(__dirname, '..')
console.log(`Determining current git branch`)
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
const currentBranch = branchDetails.stdout.trim()
console.log(`Successfully determined current git branch is ` +
`${currentBranch}`)
return currentBranch
} else {
const error = GitProcess.parseError(branchDetails.stderr)
console.log(`Could not get details for the current branch,
error was ${branchDetails.stderr}`, error)
process.exit(1)
}
}

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

@ -10,6 +10,7 @@ const args = require('minimist')(process.argv.slice(2), {
})
const { execSync } = require('child_process')
const { GitProcess } = require('dugite')
const { getCurrentBranch } = require('./lib/utils.js')
const GitHub = require('github')
const path = require('path')
@ -27,18 +28,6 @@ function getLastBumpCommit (tag) {
return JSON.parse(data)
}
async function getCurrentBranch (gitDir) {
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
return branchDetails.stdout.trim()
}
const error = GitProcess.parseError(branchDetails.stderr)
console.error(`${fail} couldn't get current branch: `, error)
process.exit(1)
}
async function revertBumpCommit (tag) {
const branch = await getCurrentBranch()
const commitToRevert = getLastBumpCommit(tag).hash