diff --git a/dist/index.js b/dist/index.js index 43cd6a945..c6519e1af 100644 --- a/dist/index.js +++ b/dist/index.js @@ -133767,6 +133767,7 @@ const Joi = __nccwpck_require__(44010) const { SORT_BY, SORT_DIRECTIONS } = __nccwpck_require__(11940) const { DEFAULT_CONFIG } = __nccwpck_require__(85869) const { validateReplacers, validateAutolabeler } = __nccwpck_require__(47282) +const merge = __nccwpck_require__(56323) const schema = (context) => { const defaultBranch = _.get( @@ -133906,7 +133907,8 @@ const schema = (context) => { } const validateSchema = (context, repoConfig) => { - const { error, value: config } = schema(context).validate(repoConfig, { + const mergedRepoConfig = merge.all([DEFAULT_CONFIG, repoConfig]) + const { error, value: config } = schema(context).validate(mergedRepoConfig, { abortEarly: false, allowUnknown: true, }) diff --git a/lib/schema.js b/lib/schema.js index ae02f2da2..1c80cac2c 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -3,6 +3,7 @@ const Joi = require('@hapi/joi') const { SORT_BY, SORT_DIRECTIONS } = require('./sort-pull-requests') const { DEFAULT_CONFIG } = require('./default-config') const { validateReplacers, validateAutolabeler } = require('./template') +const merge = require('deepmerge') const schema = (context) => { const defaultBranch = _.get( @@ -142,7 +143,8 @@ const schema = (context) => { } const validateSchema = (context, repoConfig) => { - const { error, value: config } = schema(context).validate(repoConfig, { + const mergedRepoConfig = merge.all([DEFAULT_CONFIG, repoConfig]) + const { error, value: config } = schema(context).validate(mergedRepoConfig, { abortEarly: false, allowUnknown: true, }) diff --git a/package.json b/package.json index 16f22ed83..b7c8f6ee2 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@probot/adapter-github-actions": "3.1.0", "cli-table3": "0.6.1", "compare-versions": "4.1.3", + "deepmerge": "4.2.2", "escape-string-regexp": "4.0.0", "ignore": "5.2.0", "lodash": "4.17.21", diff --git a/test/fixtures/config/config-with-custom-version-resolver-partial.yml b/test/fixtures/config/config-with-custom-version-resolver-partial.yml new file mode 100644 index 000000000..9394819d6 --- /dev/null +++ b/test/fixtures/config/config-with-custom-version-resolver-partial.yml @@ -0,0 +1,22 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +branches: + - master +categories: + - title: '🚀 Features' + label: 'feature' + - title: '🐛 Bug fixes' + label: 'bug' + - title: '📄 Documentation' + label: 'documentation' + - title: '🧰 Maintenance' + label: 'maintenance' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +template: dummy +version-resolver: + major: + labels: + - 'major' + default: minor +exclude-labels: + - skip-changelog diff --git a/test/index.test.js b/test/index.test.js index 8c1c96892..f7044d500 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -2567,6 +2567,48 @@ describe('release-drafter', () => { expect.assertions(1) }) + + it('major beats others partial config', async () => { + getConfigMock('config-with-custom-version-resolver-partial.yml') + + nock('https://api.github.com') + .get( + '/repos/toolmantim/release-drafter-test-project/releases?per_page=100' + ) + .reply(200, [releasePayload]) + + nock('https://api.github.com') + .post('/graphql', (body) => + body.query.includes('query findCommitsWithAssociatedPullRequests') + ) + .reply(200, graphqlCommitsForking) + + nock('https://api.github.com') + .post( + '/repos/toolmantim/release-drafter-test-project/releases', + (body) => { + expect(body).toMatchInlineSnapshot(` + Object { + "body": "dummy", + "draft": true, + "name": "v3.0.0", + "prerelease": false, + "tag_name": "v3.0.0", + "target_commitish": "", + } + `) + return true + } + ) + .reply(200, releasePayload) + + await probot.receive({ + name: 'push', + payload: pushPayload, + }) + + expect.assertions(1) + }) }) describe('with commitish', () => { diff --git a/yarn.lock b/yarn.lock index abdff74c8..85fb62530 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2195,7 +2195,7 @@ deep-is@^0.1.3, deep-is@~0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= -deepmerge@^4.2.2: +deepmerge@4.2.2, deepmerge@^4.2.2: version "4.2.2" resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==