Skip to content

Commit

Permalink
Support branch for code generation (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Jun 18, 2019
1 parent 6707a86 commit a4f893d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ const {
} = require('./utils')

start(minimist(process.argv.slice(2), {
string: ['tag']
string: ['tag', 'branch']
}))

function start (opts) {
const log = ora('Loading Elasticsearch Repository').start()
if (semver.valid(opts.tag) === null) {
if (opts.branch == null && semver.valid(opts.tag) === null) {
log.fail(`Missing or invalid tag: ${opts.tag}`)
return
}
Expand All @@ -55,7 +55,7 @@ function start (opts) {
log.text = 'Cleaning API folder...'
rimraf.sync(join(apiOutputFolder, '*.js'))

cloneAndCheckout({ log, tag: opts.tag }, (err, { apiFolder, xPackFolder }) => {
cloneAndCheckout({ log, tag: opts.tag, branch: opts.branch }, (err, { apiFolder, xPackFolder }) => {
if (err) {
log.fail(err.message)
return
Expand Down
17 changes: 13 additions & 4 deletions scripts/utils/clone-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const apiFolder = join(esFolder, 'rest-api-spec', 'src', 'main', 'resources', 'r
const xPackFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'api')

function cloneAndCheckout (opts, callback) {
const { log, tag } = opts
const { log, tag, branch } = opts
withTag(tag, callback)

/**
Expand Down Expand Up @@ -57,20 +57,29 @@ function cloneAndCheckout (opts, callback) {

if (fresh) {
clone(checkout)
} else if (opts.branch) {
checkout(true)
} else {
checkout()
}

function checkout () {
log.text = `Checking out tag '${tag}'`
git.checkout(tag, err => {
function checkout (alsoPull = false) {
if (branch) {
log.text = `Checking out branch '${branch}'`
} else {
log.text = `Checking out tag '${tag}'`
}
git.checkout(branch || tag, err => {
if (err) {
if (retry++ > 0) {
callback(new Error(`Cannot checkout tag '${tag}'`), { apiFolder, xPackFolder })
return
}
return pull(checkout)
}
if (alsoPull) {
return pull(checkout)
}
callback(null, { apiFolder, xPackFolder })
})
}
Expand Down

0 comments on commit a4f893d

Please sign in to comment.