Commit b4ebf593 authored by Dan Allen's avatar Dan Allen

Merge issue-25-playbook-default-branch-pattern branch into master

resolves #25 playbook default branch pattern

See merge request antora/antora-direct!15
parents 3f2e9ebf acfd7bcc
Pipeline #13220416 passed with stages
in 2 minutes and 59 seconds
......@@ -6,4 +6,4 @@ const buildPlaybook = require('../packages/playbook/lib/playbook-builder')
const playbook = buildPlaybook()
// test
console.log(playbook.site.title)
console.log(playbook)
......@@ -30,7 +30,7 @@ module.exports = async (playbook) => {
return isLocalRepo ? _.last(branches) : _.first(branches)
})
.values()
.filter(({ branchName }) => branchMatches(branchName, repo.branches))
.filter(({ branchName }) => branchMatches(branchName, repo.branches || playbook.content.branches))
.map(async ({ branch, branchName, isHead, isLocal }) => {
let files
if (isLocalRepo && !isBare && isHead) {
......@@ -136,7 +136,7 @@ function getBranchInfo (branch) {
return { branch, branchName, isLocal, isHead }
}
function branchMatches (branchName, branchPattern = '*') {
function branchMatches (branchName, branchPattern) {
if (Array.isArray(branchPattern)) {
return branchPattern.some((pattern) => isMatch(branchName, pattern))
}
......
......@@ -32,7 +32,12 @@ describe('aggregateContent()', () => {
beforeEach(() => {
cleanRepos()
playbook = { content: { sources: [] } }
playbook = {
content: {
sources: [],
branches: ['v*', 'master'],
},
}
})
afterEach(cleanRepos)
......@@ -148,23 +153,6 @@ describe('aggregateContent()', () => {
await repo.createBranch({ name: 'the-component', version: 'v3.0.0' })
}
describe('should read all branches in source repository', () => {
testAll(async (repo) => {
await initRepoWithBranches(repo)
playbook.content.sources.push({ location: repo.location })
const corpus = aggregateContent(playbook)
return expect(corpus)
.to.be.fulfilled()
.then((theCorpus) => {
expect(theCorpus).to.have.lengthOf(4)
expect(theCorpus[0]).to.deep.include({ name: 'the-component', version: 'unknown' })
expect(theCorpus[1]).to.deep.include({ name: 'the-component', version: 'v1.0.0' })
expect(theCorpus[2]).to.deep.include({ name: 'the-component', version: 'v2.0.0' })
expect(theCorpus[3]).to.deep.include({ name: 'the-component', version: 'v3.0.0' })
})
})
})
describe('should filter branches by exact name', () => {
testAll(async (repo) => {
await initRepoWithBranches(repo)
......@@ -220,6 +208,35 @@ describe('aggregateContent()', () => {
})
})
describe('should filter branches using playbook default filter "content.branches"', () => {
testAll(async (repo) => {
await initRepoWithBranches(repo)
playbook.content.sources.push({ location: repo.location })
playbook.content.branches = ['v1.0.0', 'v2*']
const corpus = aggregateContent(playbook)
return expect(corpus)
.to.be.fulfilled()
.then((theCorpus) => {
expect(theCorpus).to.have.lengthOf(2)
expect(theCorpus[0]).to.deep.include({ name: 'the-component', version: 'v1.0.0' })
expect(theCorpus[1]).to.deep.include({ name: 'the-component', version: 'v2.0.0' })
})
})
testAll(async (repo) => {
await initRepoWithBranches(repo)
playbook.content.sources.push({ location: repo.location })
playbook.content.branches = 'v1.0.*'
const corpus = aggregateContent(playbook)
return expect(corpus)
.to.be.fulfilled()
.then((theCorpus) => {
expect(theCorpus).to.have.lengthOf(1)
expect(theCorpus[0]).to.deep.include({ name: 'the-component', version: 'v1.0.0' })
})
})
})
async function initRepoWithFiles (repo) {
await repo.initRepo({ name: 'the-component', version: 'v1.2.3' })
await repo.addFixtureFiles([
......
......@@ -57,6 +57,11 @@ module.exports = {
default: [],
env: 'CONTENT_SOURCES',
},
branches: {
doc: 'The default branch pattern to use when no specific pattern is provided',
format: Array,
default: ['v*', 'master'],
},
},
ui: {
location: {
......
one:
one: one
two: 42
three: false
four: John
......@@ -75,6 +75,7 @@ describe('buildPlaybook()', () => {
const csonSpec = path.resolve(__dirname, 'fixtures', 'spec-sample.cson')
const iniSpec = path.resolve(__dirname, 'fixtures', 'spec-sample.ini')
const badSpec = path.resolve(__dirname, 'fixtures', 'bad-spec-sample.yml')
const coerceValueSpec = path.resolve(__dirname, 'fixtures', 'coerce-value-spec-sample.yml')
const defaultSchemaSpec = path.resolve(__dirname, 'fixtures', 'default-schema-spec-sample.yml')
it('should throw error if no playbook spec file can be loaded', () => {
......@@ -205,4 +206,12 @@ describe('buildPlaybook()', () => {
expect(playbook.site.url).to.equal('https://example.com')
expect(playbook.site.title).to.equal('Example site')
})
it('should coerce a String value to an Array', () => {
process.env.PLAYBOOK = coerceValueSpec
const playbook = buildPlaybook(schema)
expectedPlaybook.one.one = 'one'
expectedPlaybook.four = ['John']
expect(playbook).to.eql(expectedPlaybook)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment