diff --git a/lib/plugins/branches.js b/lib/plugins/branches.js index ec3ab7c7..927439c1 100644 --- a/lib/plugins/branches.js +++ b/lib/plugins/branches.js @@ -79,6 +79,8 @@ module.exports = class Branches extends ErrorStash { this.log.debug(`There are changes for branch ${JSON.stringify(params)}\n ${JSON.stringify(changes)} \n Branch protection will be applied`) if (this.nop) { resArray.push(new NopCommand(this.constructor.name, this.repo, null, results)) + } else { + this.log.info(`Applying branch protection changes to ${params.branch} branch of ${this.repo.owner}/${this.repo.repo} (the diff is logged at debug level)`) } Object.assign(params, requiredBranchProtectionDefaults, this.reformatAndReturnBranchProtection(structuredClone(result.data)), Overrides.removeOverrides(overrides, branch.protection, result.data), { headers: previewHeaders }) diff --git a/lib/plugins/diffable.js b/lib/plugins/diffable.js index 1b577416..d611ae03 100644 --- a/lib/plugins/diffable.js +++ b/lib/plugins/diffable.js @@ -92,6 +92,8 @@ module.exports = class Diffable extends ErrorStash { } else { if (this.nop) { resArray.push(new NopCommand(this.constructor.name, this.repo, null, results, 'INFO')) + } else { + this.log.info(`Applying ${this.constructor.name} changes to ${this.repo.owner}/${this.repo.repo} (the diff is logged at debug level)`) } } diff --git a/lib/plugins/repository.js b/lib/plugins/repository.js index ca769264..2627b39c 100644 --- a/lib/plugins/repository.js +++ b/lib/plugins/repository.js @@ -88,11 +88,11 @@ module.exports = class Repository extends ErrorStash { // const results = JSON.stringify(changes, null, 2) const results = { msg: `${this.constructor.name} settings changes`, additions: changes.additions, modifications: changes.modifications, deletions: changes.deletions } - this.log.debug(`Result of comparing repo for changes = ${results}`) + this.log.debug(`Result of comparing repo for changes = ${JSON.stringify(results)}`) // const topicResults = JSON.stringify(topicChanges, null, 2) const topicResults = { msg: `${this.constructor.name} settings changes for topics`, additions: topicChanges.additions, modifications: topicChanges.modifications, deletions: topicChanges.deletions } - this.log.debug(`Result of comparing topics for changes source ${JSON.stringify(resp.data.topics)} target ${JSON.stringify(this.topics)} = ${topicResults}`) + this.log.debug(`Result of comparing topics for changes source ${JSON.stringify(resp.data.topics)} target ${JSON.stringify(this.topics)} = ${JSON.stringify(topicResults)}`) if (this.nop && changes.hasChanges) { resArray.push(new NopCommand('Repository', this.repo, null, results)) @@ -102,10 +102,16 @@ module.exports = class Repository extends ErrorStash { } const promises = [] if (topicChanges.hasChanges) { + if (!this.nop) { + this.log.info(`Applying topic changes to ${this.repo.owner}/${this.repo.repo} (the diff is logged at debug level)`) + } promises.push(this.updatetopics(resp.data, resArray)) } if (changes.hasChanges) { this.log.debug('There are repo changes') + if (!this.nop) { + this.log.info(`Applying repository settings changes to ${this.repo.owner}/${this.repo.repo} (the diff is logged at debug level)`) + } let updateDefaultBranchPromise = Promise.resolve() if (this.settings.default_branch && (resp.data.default_branch !== this.settings.default_branch)) { this.log.debug('There is a rename of the default branch') diff --git a/test/unit/lib/plugins/autolinks.test.js b/test/unit/lib/plugins/autolinks.test.js index 02829daa..9d5d61f0 100644 --- a/test/unit/lib/plugins/autolinks.test.js +++ b/test/unit/lib/plugins/autolinks.test.js @@ -5,7 +5,7 @@ describe('Autolinks', () => { let github function configure (config) { - const log = { debug: jest.fn(), error: console.error } + const log = { debug: jest.fn(), info: jest.fn(), error: console.error } const nop = false const errors = [] return new Autolinks(nop, github, repo, config, log, errors) diff --git a/test/unit/lib/plugins/branches.test.js b/test/unit/lib/plugins/branches.test.js index f6aa2d0a..065ac5a1 100644 --- a/test/unit/lib/plugins/branches.test.js +++ b/test/unit/lib/plugins/branches.test.js @@ -8,6 +8,7 @@ describe('Branches', () => { const log = jest.fn() log.debug = jest.fn() log.error = jest.fn() + log.info = jest.fn() function configure (config) { const nop = false @@ -73,6 +74,19 @@ describe('Branches', () => { }) }) + it('logs the applied branch protection change at info level', () => { + const plugin = configure( + [{ + name: 'master', + protection: { enforce_admins: true } + }] + ) + + return plugin.sync().then(() => { + expect(log.info).toHaveBeenCalledWith(expect.stringContaining('Applying branch protection changes to master branch of bkeepers/test')) + }) + }) + describe('when the "protection" config is empty object', () => { it('removes branch protection', () => { const plugin = configure( @@ -183,7 +197,6 @@ describe('Branches', () => { ) return plugin.sync().then(() => { - expect(github.rest.repos.updateBranchProtection).toHaveBeenCalledWith(expect.objectContaining({ owner: 'bkeepers', repo: 'test', @@ -305,7 +318,6 @@ describe('Branches', () => { ) return plugin.sync().then(() => { - expect(github.rest.repos.updateBranchProtection).toHaveBeenCalledWith(expect.objectContaining({ owner: 'bkeepers', repo: 'test', diff --git a/test/unit/lib/plugins/collaborators.test.js b/test/unit/lib/plugins/collaborators.test.js index f0100795..13587642 100644 --- a/test/unit/lib/plugins/collaborators.test.js +++ b/test/unit/lib/plugins/collaborators.test.js @@ -4,7 +4,7 @@ describe('Collaborators', () => { let github function configure (config) { - const log = { debug: jest.fn(), error: console.error } + const log = { debug: jest.fn(), info: jest.fn(), error: console.error } return new Collaborators(undefined, github, { owner: 'bkeepers', repo: 'test' }, config, log) } diff --git a/test/unit/lib/plugins/custom_properties.test.js b/test/unit/lib/plugins/custom_properties.test.js index 55fbbf74..123270bc 100644 --- a/test/unit/lib/plugins/custom_properties.test.js +++ b/test/unit/lib/plugins/custom_properties.test.js @@ -18,7 +18,7 @@ describe('CustomProperties', () => { request: jest.fn() } - log = { debug: jest.fn(), error: console.error } + log = { debug: jest.fn(), info: jest.fn(), error: console.error } }) describe('Custom Properties plugin', () => { diff --git a/test/unit/lib/plugins/environments.test.js b/test/unit/lib/plugins/environments.test.js index 31fbb1cd..7eaa22d0 100644 --- a/test/unit/lib/plugins/environments.test.js +++ b/test/unit/lib/plugins/environments.test.js @@ -10,7 +10,7 @@ describe('Environments Plugin test suite', () => { const PrimaryEnvironmentNamesBeingTested = ['wait-timer_environment', 'wait-timer_2_environment', 'reviewers_environment', 'prevent-self-review_environment', 'deployment-branch-policy_environment', 'deployment-branch-policy-custom_environment', 'deployment-branch-policy-custom_environment_legacy', 'variables_environment', 'deployment-protection-rules_environment', 'new_environment', 'old_environment'] const EnvironmentNamesForTheNewEnvironmentsTest = ['new-wait-timer', 'new-reviewers', 'new-prevent-self-review', 'new-deployment-branch-policy', 'new-deployment-branch-policy-custom', 'new-deployment-branch-policy-custom-legacy', 'new-variables', 'new-deployment-protection-rules'] const AllEnvironmentNamesBeingTested = PrimaryEnvironmentNamesBeingTested.concat(EnvironmentNamesForTheNewEnvironmentsTest) - const log = { debug: jest.fn(), error: console.error } + const log = { debug: jest.fn(), info: jest.fn(), error: console.error } const errors = [] function fillEnvironment (attrs) { @@ -1409,7 +1409,7 @@ describe('nopifyRequest', () => { github = { request: jest.fn(() => Promise.resolve(true)) }; - plugin = new Environments(undefined, github, { owner: org, repo }, [], { debug: jest.fn(), error: console.error }, []); + plugin = new Environments(undefined, github, { owner: org, repo }, [], { debug: jest.fn(), info: jest.fn(), error: console.error }, []); }); it('should make a request when nop is false', async () => { diff --git a/test/unit/lib/plugins/labels.test.js b/test/unit/lib/plugins/labels.test.js index 1d1bd51b..3f6ebe9d 100644 --- a/test/unit/lib/plugins/labels.test.js +++ b/test/unit/lib/plugins/labels.test.js @@ -28,7 +28,7 @@ describe('Labels', () => { } } } - log = { debug: jest.fn(), error: console.error } + log = { debug: jest.fn(), info: jest.fn(), error: console.error } }) describe('sync', () => { @@ -50,6 +50,8 @@ describe('Labels', () => { ]) return plugin.sync().then(() => { + expect(log.info).toHaveBeenCalledWith(expect.stringContaining('Applying Labels changes to bkeepers/test')) + expect(github.rest.issues.deleteLabel).toHaveBeenCalledWith({ owner: 'bkeepers', repo: 'test', diff --git a/test/unit/lib/plugins/repository.test.js b/test/unit/lib/plugins/repository.test.js index f3b04115..3ade857b 100644 --- a/test/unit/lib/plugins/repository.test.js +++ b/test/unit/lib/plugins/repository.test.js @@ -50,6 +50,7 @@ describe('Repository', () => { description: 'Hello World!', mediaType: { previews: ['nebula-preview'] } }) + expect(log.info).toHaveBeenCalledWith(expect.stringContaining('Applying repository settings changes to bkeepers/test')) }) }) @@ -81,6 +82,7 @@ describe('Repository', () => { previews: ['mercy'] } }) + expect(log.info).toHaveBeenCalledWith(expect.stringContaining('Applying topic changes to bkeepers/test')) }) }) }) diff --git a/test/unit/lib/plugins/rulesets.test.js b/test/unit/lib/plugins/rulesets.test.js index 15a9fee6..5c172825 100644 --- a/test/unit/lib/plugins/rulesets.test.js +++ b/test/unit/lib/plugins/rulesets.test.js @@ -86,6 +86,7 @@ describe('Rulesets', () => { let github const log = jest.fn() log.debug = jest.fn() + log.info = jest.fn() log.error = jest.fn() function configure (config, scope = 'repo', noop = false) { diff --git a/test/unit/lib/plugins/teams.test.js b/test/unit/lib/plugins/teams.test.js index 5d122665..98bb2821 100644 --- a/test/unit/lib/plugins/teams.test.js +++ b/test/unit/lib/plugins/teams.test.js @@ -15,7 +15,7 @@ describe('Teams', () => { const org = 'bkeepers' function configure (config) { - const log = { debug: jest.fn(), error: jest.fn(), warn: console.warn } + const log = { debug: jest.fn(), info: jest.fn(), error: jest.fn(), warn: console.warn } const errors = [] return new Teams(undefined, github, { owner: 'bkeepers', repo: 'test' }, config, log, errors) } diff --git a/test/unit/lib/plugins/variables.test.js b/test/unit/lib/plugins/variables.test.js index 91c06239..ca0cb3a8 100644 --- a/test/unit/lib/plugins/variables.test.js +++ b/test/unit/lib/plugins/variables.test.js @@ -8,7 +8,7 @@ describe('Variables', () => { const repo = 'test' function configure (nop = false, entries = [{ name: 'test', value: 'test' }]) { - const log = { debug: jest.fn(), error: console.error } + const log = { debug: jest.fn(), info: jest.fn(), error: console.error } const errors = [] return new Variables(nop, github, { owner: org, repo }, entries, log, errors) }