Skip to content

Commit e86a637

Browse files
authored
Support branch for code generation (#883)
1 parent 53e3262 commit e86a637

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

scripts/generate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ const {
3535
} = require('./utils')
3636

3737
start(minimist(process.argv.slice(2), {
38-
string: ['tag']
38+
string: ['tag', 'branch']
3939
}))
4040

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

58-
cloneAndCheckout({ log, tag: opts.tag }, (err, { apiFolder, xPackFolder }) => {
58+
cloneAndCheckout({ log, tag: opts.tag, branch: opts.branch }, (err, { apiFolder, xPackFolder }) => {
5959
if (err) {
6060
log.fail(err.message)
6161
return

scripts/utils/clone-es.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const apiFolder = join(esFolder, 'rest-api-spec', 'src', 'main', 'resources', 'r
2929
const xPackFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'api')
3030

3131
function cloneAndCheckout (opts, callback) {
32-
const { log, tag } = opts
32+
const { log, tag, branch } = opts
3333
withTag(tag, callback)
3434

3535
/**
@@ -57,20 +57,29 @@ function cloneAndCheckout (opts, callback) {
5757

5858
if (fresh) {
5959
clone(checkout)
60+
} else if (opts.branch) {
61+
checkout(true)
6062
} else {
6163
checkout()
6264
}
6365

64-
function checkout () {
65-
log.text = `Checking out tag '${tag}'`
66-
git.checkout(tag, err => {
66+
function checkout (alsoPull = false) {
67+
if (branch) {
68+
log.text = `Checking out branch '${branch}'`
69+
} else {
70+
log.text = `Checking out tag '${tag}'`
71+
}
72+
git.checkout(branch || tag, err => {
6773
if (err) {
6874
if (retry++ > 0) {
6975
callback(new Error(`Cannot checkout tag '${tag}'`), { apiFolder, xPackFolder })
7076
return
7177
}
7278
return pull(checkout)
7379
}
80+
if (alsoPull) {
81+
return pull(checkout)
82+
}
7483
callback(null, { apiFolder, xPackFolder })
7584
})
7685
}

0 commit comments

Comments
 (0)