Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/plugins/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 2 additions & 0 deletions lib/plugins/diffable.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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)`)
}
}

Expand Down
10 changes: 8 additions & 2 deletions lib/plugins/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,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))
Expand All @@ -91,10 +91,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')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/plugins/autolinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions test/unit/lib/plugins/branches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -183,7 +197,6 @@ describe('Branches', () => {
)

return plugin.sync().then(() => {

expect(github.rest.repos.updateBranchProtection).toHaveBeenCalledWith(expect.objectContaining({
owner: 'bkeepers',
repo: 'test',
Expand Down Expand Up @@ -305,7 +318,6 @@ describe('Branches', () => {
)

return plugin.sync().then(() => {

expect(github.rest.repos.updateBranchProtection).toHaveBeenCalledWith(expect.objectContaining({
owner: 'bkeepers',
repo: 'test',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/plugins/collaborators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/plugins/custom_properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('CustomProperties', () => {
}
}

log = { debug: jest.fn(), error: console.error }
log = { debug: jest.fn(), info: jest.fn(), error: console.error }
})

describe('Custom Properties plugin', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/plugins/environments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 () => {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/lib/plugins/labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion test/unit/lib/plugins/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Repository', () => {
const log = jest.fn()
log.debug = jest.fn()
log.error = jest.fn()
log.info = jest.fn()

function configure (config) {
const nop = false
Expand All @@ -43,6 +44,7 @@ describe('Repository', () => {
description: 'Hello World!',
mediaType: { previews: ['nebula-preview'] }
})
expect(log.info).toHaveBeenCalledWith(expect.stringContaining('Applying repository settings changes to bkeepers/test'))
})
})

Expand All @@ -60,7 +62,7 @@ describe('Repository', () => {
})
})

it.only('syncs topics', () => {
it('syncs topics', () => {
const plugin = configure({
topics: ['foo', 'bar']
})
Expand All @@ -74,6 +76,7 @@ describe('Repository', () => {
previews: ['mercy']
}
})
expect(log.info).toHaveBeenCalledWith(expect.stringContaining('Applying topic changes to bkeepers/test'))
})
})
})
Expand Down
1 change: 1 addition & 0 deletions test/unit/lib/plugins/rulesets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/plugins/teams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Teams', () => {
const org = 'bkeepers'

function configure (config) {
const log = { debug: jest.fn(), error: console.error }
const log = { debug: jest.fn(), info: jest.fn(), error: console.error }
const errors = []
return new Teams(undefined, github, { owner: 'bkeepers', repo: 'test' }, config, log, errors)
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/plugins/variables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down