From 04621913a7339339f29a1f845abfd4296abffc5c Mon Sep 17 00:00:00 2001 From: Martin Migasiewicz <616250+martinm82@users.noreply.github.com> Date: Wed, 15 Feb 2023 14:06:14 +0100 Subject: [PATCH 1/7] chore(logs): improve log messages --- index.js | 156 ++++++++++++++++++++++---------------- lib/configManager.js | 12 +-- lib/mergeDeep.js | 2 +- lib/plugins/branches.js | 10 +-- lib/plugins/diffable.js | 2 +- lib/plugins/repository.js | 36 ++++----- lib/plugins/validator.js | 8 +- lib/settings.js | 20 ++--- lib/validator.js | 8 +- 9 files changed, 138 insertions(+), 116 deletions(-) diff --git a/index.js b/index.js index dc1f82bc..1abc86a0 100644 --- a/index.js +++ b/index.js @@ -10,13 +10,14 @@ const env = require('./lib/env') let deploymentConfig module.exports = (robot, _, Settings = require('./lib/settings')) => { async function syncAllSettings (nop, context, repo = context.repo(), ref) { + const log = robot.log.child({ context: 'index', repository: repo.repo }) try { deploymentConfig = await loadYamlFileSystem() - robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) + log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) const configManager = new ConfigManager(context, ref) const runtimeConfig = await configManager.loadGlobalSettingsYaml() const config = Object.assign({}, deploymentConfig, runtimeConfig) - robot.log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) + log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) if (ref) { return Settings.syncAll(nop, context, repo, config, ref) } else { @@ -30,7 +31,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { deploymentConfig = {} } const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') - robot.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) + log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) Settings.handleError(nop, context, repo, deploymentConfig, ref, nopcommand) } else { throw e @@ -39,13 +40,14 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { } async function syncSubOrgSettings (nop, context, suborg, repo = context.repo(), ref) { + const log = robot.log.child({ context: 'index', suborg, repository: repo.repo }) try { deploymentConfig = await loadYamlFileSystem() - robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) + log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) const configManager = new ConfigManager(context, ref) const runtimeConfig = await configManager.loadGlobalSettingsYaml() const config = Object.assign({}, deploymentConfig, runtimeConfig) - robot.log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) + log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) return Settings.syncSubOrgs(nop, context, suborg, repo, config, ref) } catch (e) { if (nop) { @@ -55,7 +57,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { deploymentConfig = {} } const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') - robot.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) + log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) Settings.handleError(nop, context, repo, deploymentConfig, ref, nopcommand) } else { throw e @@ -64,13 +66,14 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { } async function syncSettings (nop, context, repo = context.repo(), ref) { + const log = robot.log.child({ context: 'index', repository: repo.repo }) try { deploymentConfig = await loadYamlFileSystem() - robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) + log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) const configManager = new ConfigManager(context, ref) const runtimeConfig = await configManager.loadGlobalSettingsYaml() const config = Object.assign({}, deploymentConfig, runtimeConfig) - robot.log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) + log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) return Settings.sync(nop, context, repo, config, ref) } catch (e) { if (nop) { @@ -80,7 +83,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { deploymentConfig = {} } const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') - robot.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) + log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) Settings.handleError(nop, context, repo, deploymentConfig, ref, nopcommand) } else { throw e @@ -108,23 +111,25 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { function getAllChangedSubOrgConfigs (payload) { const settingPattern = new Glob('.github/suborgs/*.yml') + const log = robot.log.child({ context: 'index' }) + // Changes will be an array of files that were added const added = payload.commits.map(c => { return (c.added.filter(s => { - robot.log.debug(JSON.stringify(s)) + log.debug(JSON.stringify(s)) return (s.search(settingPattern) >= 0) })) }).flat(2) const modified = payload.commits.map(c => { return (c.modified.filter(s => { - robot.log.debug(JSON.stringify(s)) + log.debug(JSON.stringify(s)) return (s.search(settingPattern) >= 0) })) }).flat(2) const changes = added.concat(modified) const configs = changes.map(file => { const matches = file.match(settingPattern) - robot.log.debug(`${JSON.stringify(file)} \n ${matches[1]}`) + log.debug(`${JSON.stringify(file)} \n ${matches[1]}`) return { name: matches[1] + '.yml', path: file } }) return configs @@ -132,30 +137,33 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { function getAllChangedRepoConfigs (payload, owner) { const settingPattern = new Glob('.github/repos/*.yml') + const log = robot.log.child({ context: 'index' }) + // Changes will be an array of files that were added const added = payload.commits.map(c => { return (c.added.filter(s => { - robot.log.debug(JSON.stringify(s)) + log.debug(JSON.stringify(s)) return (s.search(settingPattern) >= 0) })) }).flat(2) const modified = payload.commits.map(c => { return (c.modified.filter(s => { - robot.log.debug(JSON.stringify(s)) + log.debug(JSON.stringify(s)) return (s.search(settingPattern) >= 0) })) }).flat(2) const changes = added.concat(modified) const configs = changes.map(file => { - robot.log.debug(`${JSON.stringify(file)}`) + log.debug(`${JSON.stringify(file)}`) return { repo: file.match(settingPattern)[1], owner } }) return configs } function getChangedRepoConfigName (glob, files, owner) { + const log = robot.log.child({ context: 'index' }) const modifiedFiles = files.filter(s => { - robot.log.debug(JSON.stringify(s)) + log.debug(JSON.stringify(s)) return (s.search(glob) >= 0) }) @@ -165,31 +173,34 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { } function getChangedSubOrgConfigName (glob, files) { + const log = robot.log.child({ context: 'index' }) const modifiedFiles = files.filter(s => { - robot.log.debug(JSON.stringify(s)) + log.debug(JSON.stringify(s)) return (s.search(glob) >= 0) }) return modifiedFiles.map(modifiedFile => { - robot.log.debug(`${JSON.stringify(modifiedFile)}`) + log.debug(`${JSON.stringify(modifiedFile)}`) return { name: modifiedFile.match(glob)[1] + '.yml', path: modifiedFile } }) } async function createCheckRun (context, pull_request, head_sha, head_branch) { const { payload } = context - robot.log.debug(`Check suite was requested! for ${context.repo()} ${pull_request.number} ${head_sha} ${head_branch}`) + const log = robot.log.child({ context: 'index' }) + log.debug(`Check suite was requested! for ${context.repo()} ${pull_request.number} ${head_sha} ${head_branch}`) const res = await context.octokit.checks.create({ owner: payload.repository.owner.login, repo: payload.repository.name, name: 'Safe-setting validator', head_sha }) - robot.log.debug(JSON.stringify(res, null)) + log.debug(JSON.stringify(res, null)) } async function syncInstallation () { - robot.log.trace('Fetching installations') + const log = robot.log.child({ context: 'index' }) + log.trace('Fetching installations') const github = await robot.auth() const installations = await github.paginate( @@ -198,7 +209,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { if (installations.length > 0) { const installation = installations[0] - robot.log.trace(`${JSON.stringify(installation)}`) + log.trace(`${JSON.stringify(installation)}`) const github = await robot.auth(installation.id) const context = { payload: { @@ -216,6 +227,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { robot.on('push', async context => { const { payload } = context const { repository } = payload + const log = robot.log.child({ context: 'index', event: 'push', repository: repository.name }) const adminRepo = repository.name === env.ADMIN_REPO if (!adminRepo) { @@ -224,7 +236,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { const defaultBranch = payload.ref === 'refs/heads/' + repository.default_branch if (!defaultBranch) { - robot.log.debug('Not working on the default branch, returning...') + log.debug('Not working on the default branch, returning...') return } @@ -233,7 +245,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { commit.modified.includes(Settings.FILE_NAME) }) if (settingsModified) { - robot.log.debug(`Changes in '${Settings.FILE_NAME}' detected, doing a full synch...`) + log.debug(`Changes in '${Settings.FILE_NAME}' detected, doing a full synch...`) return syncAllSettings(false, context) } @@ -251,18 +263,19 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { })) } - robot.log.debug(`No changes in '${Settings.FILE_NAME}' detected, returning...`) + log.debug(`No changes in '${Settings.FILE_NAME}' detected, returning...`) }) robot.on('branch_protection_rule', async context => { const { payload } = context - const { sender } = payload - robot.log.debug('Branch Protection edited by ', JSON.stringify(sender)) + const { sender, repository } = payload + const log = robot.log.child({ context: 'index', event: 'branch_protection_rule', repository: repository.name }) + if (sender.type === 'Bot') { - robot.log.debug('Branch Protection edited by Bot') + log.debug(`Branch Protection edited by a Bot (${sender.login}), returning...`) return } - robot.log.debug('Branch Protection edited by a Human') + log.debug(`Branch Protection edited by a Human (${sender.login})`) return syncSettings(false, context) }) @@ -274,30 +287,31 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { ] robot.on(member_change_events, async context => { const { payload } = context - const { sender } = payload - robot.log.debug('Repository member edited by ', JSON.stringify(sender)) + const { sender, repository } = payload + const log = robot.log.child({ context: 'index', event: 'member_change_events', repository: repository.name }) if (sender.type === 'Bot') { - robot.log.debug('Repository member edited by Bot') + log.debug(`Repository member edited by a Bot (${sender.login}), returning...`) return } - robot.log.debug('Repository member edited by a Human') + log.debug(`Repository member edited by a Human (${sender.login})`) return syncSettings(false, context) }) robot.on('repository.edited', async context => { const { payload } = context const { changes, repository, sender } = payload - robot.log.debug('repository.edited payload from ', JSON.stringify(sender)) + const log = robot.log.child({ context: 'index', event: 'repository.edited', repository: repository.name }) + if (sender.type === 'Bot') { - robot.log.debug('Repository Edited by a Bot') + log.debug(`Repository edited by a Bot (${sender.login}), returning...`) return } - robot.log.debug('Repository Edited by a Human') + log.debug(`Repository edited by a Human (${sender.login}`) if (!Object.prototype.hasOwnProperty.call(changes, 'default_branch')) { - robot.log.debug('Repository configuration was edited but the default branch was not affected, returning...') + log.debug('Repository configuration was edited but the default branch was not affected, returning...') return } - robot.log.debug(`Default branch changed from '${changes.default_branch.from}' to '${repository.default_branch}'`) + log.debug(`Default branch changed from '${changes.default_branch.from}' to '${repository.default_branch}'`) return syncSettings(false, context) }) @@ -305,18 +319,20 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { const { payload } = context const { repository } = payload const adminRepo = repository.name === env.ADMIN_REPO - robot.log.debug(`Is Admin repo event ${adminRepo}`) + const log = robot.log.child({ context: 'index', event: 'check_suite.requested', repository: repository.name }) + + log.debug(`Is Admin repo event ${adminRepo}`) if (!adminRepo) { - robot.log.debug('Not working on the Admin repo, returning...') + log.debug('Not working on the Admin repo, returning...') return } const defaultBranch = payload.check_suite.head_branch === repository.default_branch if (defaultBranch) { - robot.log.debug(' Working on the default branch, returning...') + log.debug(' Working on the default branch, returning...') return } if (!payload.check_suite.pull_requests[0]) { - robot.log.debug('Not working on a PR, returning...') + log.debug('Not working on a PR, returning...') return } const pull_request = payload.check_suite.pull_requests[0] @@ -324,18 +340,20 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { }) robot.on('pull_request.opened', async context => { - robot.log.debug('Pull_request opened !') const { payload } = context const { repository } = payload const adminRepo = repository.name === env.ADMIN_REPO - robot.log.debug(`Is Admin repo event ${adminRepo}`) + const log = robot.log.child({ context: 'index', event: 'pull_request.opened', repository: repository.name }) + + log.debug('Pull_request opened!') + log.debug(`Is Admin repo event ${adminRepo}`) if (!adminRepo) { - robot.log.debug('Not working on the Admin repo, returning...') + log.debug('Not working on the Admin repo, returning...') return } const defaultBranch = payload.pull_request.head_branch === repository.default_branch if (defaultBranch) { - robot.log.debug(' Working on the default branch, returning...') + log.debug('Working on the default branch, returning...') return } const pull_request = payload.pull_request @@ -343,58 +361,59 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { }) robot.on('pull_request.reopened', async context => { - robot.log.debug('Pull_request REopened !') const { payload } = context const { repository } = payload const pull_request = payload.pull_request const adminRepo = repository.name === env.ADMIN_REPO + const log = robot.log.child({ context: 'index', event: 'pull_request.reopened', repository: repository.name }) - robot.log.debug(`Is Admin repo event ${adminRepo}`) + log.debug('Pull request reopened!') + log.debug(`Is Admin repo event ${adminRepo}`) if (!adminRepo) { - robot.log.debug('Not working on the Admin repo, returning...') + log.debug('Not working on the Admin repo, returning...') return } const defaultBranch = payload.pull_request.head_branch === repository.default_branch if (defaultBranch) { - robot.log.debug(' Working on the default branch, returning...') + log.debug(' Working on the default branch, returning...') return } return createCheckRun(context, pull_request, payload.pull_request.head.sha, payload.pull_request.head.ref) }) robot.on(['check_suite.rerequested'], async context => { - robot.log.debug('Check suite was rerequested!') - return createCheckRun(context) - }) - - robot.on(['check_suite.rerequested'], async context => { - robot.log.debug('Check suite was rerequested!') + const { payload } = context + const { repository } = payload + const log = robot.log.child({ context: 'index', event: 'check_suite.rerequested', repository: repository.name }) + log.debug('Check suite was rerequested!') return createCheckRun(context) }) robot.on(['check_run.created'], async context => { - robot.log.debug('Check run was created!') const { payload } = context const { repository } = payload const { check_run } = payload const { check_suite } = check_run const pull_request = check_suite.pull_requests[0] const source = payload.check_run.name === 'Safe-setting validator' + const log = robot.log.child({ context: 'index', event: 'check_run.created', repository: repository.name }) + + log.debug('Check run was created!') if (!source) { - robot.log.debug(' Not triggered by Safe-settings...') + log.debug('Not triggered by Safe-settings...') return } const adminRepo = repository.name === env.ADMIN_REPO - robot.log.debug(`Is Admin repo event ${adminRepo}`) + log.debug(`Is Admin repo event ${adminRepo}`) if (!adminRepo) { - robot.log.debug('Not working on the Admin repo, returning...') + log.debug('Not working on the Admin repo, returning...') return } if (!pull_request) { - robot.log.debug('Not working on a PR, returning...') + log.debug('Not working on a PR, returning...') return } @@ -406,7 +425,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { started_at: new Date().toISOString(), output: { title: 'Starting NOP', summary: 'initiating...' } } - robot.log.debug(`Updating check run ${JSON.stringify(params)}`) + log.debug(`Updating check run ${JSON.stringify(params)}`) await context.octokit.checks.update(params) // guarding against null value from upstream libary that is @@ -422,7 +441,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { const settingsModified = files.includes(Settings.FILE_NAME) if (settingsModified) { - robot.log.debug(`Changes in '${Settings.FILE_NAME}' detected, doing a full synch...`) + log.debug(`Changes in '${Settings.FILE_NAME}' detected, doing a full synch...`) return syncAllSettings(true, context, context.repo(), pull_request.head.ref) } @@ -450,14 +469,16 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { conclusion: 'success', output: { title: 'No Safe-settings changes detected', summary: 'No changes detected' } } - robot.log.debug(`Completing check run ${JSON.stringify(params)}`) + log.debug(`Completing check run ${JSON.stringify(params)}`) await context.octokit.checks.update(params) }) robot.on('repository.created', async context => { const { payload } = context - const { sender } = payload - robot.log.debug('repository.created payload from ', JSON.stringify(sender)) + const { sender, repository } = payload + const log = robot.log.child({ context: 'index', event: 'repository.created', repository: repository.name }) + + log.debug('repository.created payload from ', JSON.stringify(sender)) return syncSettings(false, context) }) @@ -474,7 +495,8 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { # * * * * * * */ cron.schedule(process.env.CRON, () => { - robot.log.debug('running a task every minute') + const log = robot.log.child({ event: 'cron' }) + log.debug(`running a scheduled task (${process.env.CRON})`) syncInstallation() }) } diff --git a/lib/configManager.js b/lib/configManager.js index 58f5bb43..985bdd48 100644 --- a/lib/configManager.js +++ b/lib/configManager.js @@ -6,15 +6,15 @@ module.exports = class ConfigManager { constructor (context, ref) { this.context = context this.ref = ref - this.log = context.log + this.log = context.log.child({ context: 'ConfigManager' }) } /** -* Loads a file from GitHub -* -* @param params Params to fetch the file with -* @return The parsed YAML file -*/ + * Loads a file from GitHub + * + * @param params Params to fetch the file with + * @return The parsed YAML file + */ async loadYaml (filePath) { try { const repo = { owner: this.context.repo().owner, repo: env.ADMIN_REPO } diff --git a/lib/mergeDeep.js b/lib/mergeDeep.js index b942f5f1..f5e760be 100644 --- a/lib/mergeDeep.js +++ b/lib/mergeDeep.js @@ -2,7 +2,7 @@ const mergeBy = require('./mergeArrayBy') const NAME_FIELDS = ['name', 'username'] class MergeDeep { constructor (log, ignorableFields, configvalidators = {}, overridevalidators = {}) { - this.log = log + this.log = log.child({ context: 'MergeDeep' }) this.ignorableFields = ignorableFields this.configvalidators = configvalidators this.overridevalidators = overridevalidators diff --git a/lib/plugins/branches.js b/lib/plugins/branches.js index 2b98ac90..e524f82b 100644 --- a/lib/plugins/branches.js +++ b/lib/plugins/branches.js @@ -8,7 +8,7 @@ module.exports = class Branches { this.github = github this.repo = repo this.branches = settings - this.log = log + this.log = log.child({ context: 'Branches', repository: this.repo.repo }) this.nop = nop } @@ -24,7 +24,7 @@ module.exports = class Branches { let p = Object.assign(this.repo, { branch: branch.name }) if (branch.name === 'default') { p = Object.assign(this.repo, { branch: currentRepo.data.default_branch }) - this.log(`Deleting default branch protection for branch ${currentRepo.data.default_branch}`) + this.log.debug(`Deleting default branch protection for branch ${currentRepo.data.default_branch}`) } // Hack to handle closures and keep params from changing const params = Object.assign({}, p) @@ -41,7 +41,7 @@ module.exports = class Branches { let p = Object.assign(this.repo, { branch: branch.name }) if (branch.name === 'default') { p = Object.assign(this.repo, { branch: currentRepo.data.default_branch }) - // this.log(`Setting default branch protection for branch ${currentRepo.data.default_branch}`) + // this.log.debug(`Setting default branch protection for branch ${currentRepo.data.default_branch}`) } // Hack to handle closures and keep params from changing const params = Object.assign({}, p) @@ -72,7 +72,7 @@ module.exports = class Branches { return Promise.resolve(resArray) } this.log.debug(`Adding branch protection ${JSON.stringify(params)}`) - return this.github.repos.updateBranchProtection(params).then(res => this.log(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.log.error(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) + return this.github.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.log.error(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) }).catch((e) => { if (e.status === 404) { Object.assign(params, branch.protection, { headers: previewHeaders }) @@ -81,7 +81,7 @@ module.exports = class Branches { return Promise.resolve(resArray) } this.log.debug(`Adding branch protection ${JSON.stringify(params)}`) - return this.github.repos.updateBranchProtection(params).then(res => this.log(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.log.error(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) + return this.github.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.log.error(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) } else { this.log.error(e) // return diff --git a/lib/plugins/diffable.js b/lib/plugins/diffable.js index 4d7f6549..9535e23f 100644 --- a/lib/plugins/diffable.js +++ b/lib/plugins/diffable.js @@ -27,7 +27,7 @@ module.exports = class Diffable { this.github = github this.repo = repo this.entries = entries - this.log = log + this.log = log.child({ context: this.constructor.name, repository: this.repo.repo }) this.nop = nop } diff --git a/lib/plugins/repository.js b/lib/plugins/repository.js index 9883b490..e9d5dd44 100644 --- a/lib/plugins/repository.js +++ b/lib/plugins/repository.js @@ -50,7 +50,7 @@ module.exports = class Repository { this.topics = this.settings.topics this.security = this.settings.security this.repo = repo - this.log = log + this.log = log.child({ context: 'Repository', repository: this.repo.repo }) this.nop = nop this.force_create = this.settings.force_create this.template = this.settings.template @@ -82,10 +82,10 @@ module.exports = class Repository { this.log.debug(`Result of comparing topics for changes source ${JSON.stringify(resp.data.topics)} target ${JSON.stringify(this.topics)} = ${topicResults}`) if (this.nop && changes.hasChanges) { - resArray.push(new NopCommand('Repository', this.repo, null, `Repo settings changes: ${results}`)) + resArray.push(new NopCommand('Repository', this.repo, null, `[${this.settings.name}] Repo settings changes: ${results}`)) } if (this.nop && topicChanges.hasChanges) { - resArray.push(new NopCommand('Repository', this.repo, null, `Repo topics changes ${topicResults}`)) + resArray.push(new NopCommand('Repository', this.repo, null, `[${this.settings.name}] Repo topics changes ${topicResults}`)) } const promises = [] if (changes.hasChanges) { @@ -93,7 +93,7 @@ module.exports = class Repository { if (this.settings.default_branch && (resp.data.default_branch !== this.settings.default_branch)) { this.log.debug('There is a rename of the default branch') if (this.nop) { - resArray.push(new NopCommand('Repository', this.repo, this.github.repos.renameBranch.endpoint(resp.data.default_branch, this.settings.default_branch), `Repo rename default branch to ${this.settings.default_branch}`)) + resArray.push(new NopCommand('Repository', this.repo, this.github.repos.renameBranch.endpoint(resp.data.default_branch, this.settings.default_branch), `[${this.settings.name}] Repo rename default branch to ${this.settings.default_branch}`)) } else { promises.push(this.renameBranch(resp.data.default_branch, this.settings.default_branch)) } @@ -114,7 +114,7 @@ module.exports = class Repository { } else { this.log.debug(`There are no changes for repo ${JSON.stringify(this.repo)}.`) if (this.nop) { - resArray.push(new NopCommand('Repository', this.repo, null, `There are no changes for repo ${JSON.stringify(this.repo)}.`)) + resArray.push(new NopCommand('Repository', this.repo, null, `[${this.settings.name}] There are no changes for repo ${JSON.stringify(this.repo)}.`)) } } if (this.nop) { @@ -126,7 +126,7 @@ module.exports = class Repository { if (e.status === 404) { if (this.force_create) { if (this.template) { - this.log(`Creating repo using template ${this.template}`) + this.log.debug(`Creating repo using template ${this.template}`) const options = { template_owner: this.repo.owner, template_repo: this.template, owner: this.repo.owner, name: this.repo.repo, private: (this.settings.private ? this.settings.private : true), description: this.settings.description ? this.settings.description : '' } if (this.nop) { @@ -139,7 +139,7 @@ module.exports = class Repository { // https://docs.github.com/en/rest/repos/repos#create-an-organization-repository uses org instead of owner like // the API to create a repo with a template this.settings.org = this.settings.owner - this.log('Creating repo with settings ', this.settings) + this.log.debug('Creating repo with settings ', this.settings) if (this.nop) { this.log.debug(`Creating Repo ${JSON.stringify(this.github.repos.createInOrg.endpoint(this.settings))} `) return Promise.resolve([ @@ -162,19 +162,19 @@ module.exports = class Repository { } renameBranch (oldname, newname) { - const parms = { + const params = { owner: this.settings.owner, repo: this.settings.repo, branch: oldname, new_name: newname } - this.log.debug(`Rename default branch repo with settings ${JSON.stringify(parms)}`) + this.log.debug(`Rename default branch repo with settings ${JSON.stringify(params)}`) if (this.nop) { return Promise.resolve([ - new NopCommand(this.constructor.name, this.repo, this.github.repos.renameBranch.endpoint(parms), 'Rename Branch') + new NopCommand(this.constructor.name, this.repo, this.github.repos.renameBranch.endpoint(params), 'Rename Branch') ]) } - return this.github.repos.renameBranch(parms) + return this.github.repos.renameBranch(params) } updaterepo (resArray) { @@ -199,14 +199,14 @@ module.exports = class Repository { if (this.topics) { if (repoData.data?.topics.length !== this.topics.length || !repoData.data?.topics.every(t => this.topics.includes(t))) { - this.log(`Updating repo with topics ${this.topics.join(',')}`) + this.log.debug(`Updating repo with topics ${this.topics.join(',')}`) if (this.nop) { resArray.push((new NopCommand(this.constructor.name, this.repo, this.github.repos.replaceAllTopics.endpoint(parms), 'Update Topics'))) return Promise.resolve(resArray) } return this.github.repos.replaceAllTopics(parms) } else { - this.log(`no need to update topics for ${repoData.data.name}`) + this.log.debug(`no need to update topics for ${repoData.data.name}`) if (this.nop) { resArray.push((new NopCommand(this.constructor.name, this.repo, null, `no need to update topics for ${repoData.data.name}`))) return Promise.resolve(resArray) @@ -218,9 +218,9 @@ module.exports = class Repository { // Added support for Code Security and Analysis updateSecurity (repoData, resArray) { if (this.security?.enableVulnerabilityAlerts === true || this.security?.enableVulnerabilityAlerts === false) { - this.log(`Found repo with security settings ${JSON.stringify(this.security)}`) + this.log.debug(`Found repo with security settings ${JSON.stringify(this.security)}`) if (this.security.enableVulnerabilityAlerts === true) { - this.log(`Enabling Dependabot alerts for owner: ${repoData.owner.login} and repo ${repoData.name}`) + this.log.debug(`Enabling Dependabot alerts for owner: ${repoData.owner.login} and repo ${repoData.name}`) if (this.nop) { resArray.push((new NopCommand(this.constructor.name, this.repo, this.github.repos.enableVulnerabilityAlerts.endpoint({ owner: repoData.owner.login, @@ -234,7 +234,7 @@ module.exports = class Repository { }) } else { - this.log(`Disabling Dependabot alerts for for owner: ${repoData.owner.login} and repo ${repoData.name}`) + this.log.debug(`Disabling Dependabot alerts for for owner: ${repoData.owner.login} and repo ${repoData.name}`) if (this.nop) { resArray.push((new NopCommand(this.constructor.name, this.github.repos.disableVulnerabilityAlerts.endpoint({ owner: repoData.owner.login, @@ -249,7 +249,7 @@ module.exports = class Repository { } } else { - this.log(`no need to update security for ${repoData.name}`) + this.log.debug(`no need to update security for ${repoData.name}`) if (this.nop) { resArray.push((new NopCommand(this.constructor.name, this.repo, null, `no need to update security for ${repoData.name}`))) return Promise.resolve(resArray) @@ -289,4 +289,4 @@ module.exports = class Repository { } } } -} \ No newline at end of file +} diff --git a/lib/plugins/validator.js b/lib/plugins/validator.js index ee16c281..e97896c2 100644 --- a/lib/plugins/validator.js +++ b/lib/plugins/validator.js @@ -6,7 +6,7 @@ module.exports = class Validator { // this.regex = /[a-zA-Z0-9_-]+_\w[a-zA-Z0-9_-]+.*/gm this.regex = new RegExp(this.pattern, 'gm') this.repo = repo - this.log = log + this.log = log.child({ context: 'Validator', repository: this.repo.repo }) this.nop = nop } @@ -20,7 +20,7 @@ module.exports = class Validator { } }).then(res => { if (this.repo.repo.search(this.regex) >= 0) { - this.log(`Repo ${this.repo.repo} Passed Validation for pattern ${this.pattern}`) + this.log.debug(`Repo ${this.repo.repo} Passed Validation for pattern ${this.pattern}`) if (this.nop) { return Promise.resolve([ new NopCommand(this.constructor.name, this.repo, null, `Passed Validation for pattern ${this.pattern}`) @@ -38,7 +38,7 @@ module.exports = class Validator { }) } } else { - this.log(`Repo ${this.repo.repo} Failed Validation for pattern ${this.pattern}`) + this.log.warn(`Repo ${this.repo.repo} Failed Validation for pattern ${this.pattern}`) if (this.nop) { return Promise.resolve([ new NopCommand(this.constructor.name, this.repo, null, `Failed Validation for pattern ${this.pattern}`) @@ -59,7 +59,7 @@ module.exports = class Validator { }) .catch(() => {}) } catch (error) { - this.log(`Error in Validation checking ${error}`) + this.log.error(`Error in Validation checking ${error}`) } } } diff --git a/lib/settings.js b/lib/settings.js index 86b5e1dd..1c28e5ab 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -51,7 +51,7 @@ class Settings { if (suborg) { this.subOrgConfigMap = [suborg] } - this.log = context.log + this.log = context.log.child({ context: 'Settings', repository: this.repo.repo }) this.results = [] this.configvalidators = {} this.overridevalidators = {} @@ -198,7 +198,7 @@ ${this.results.reduce((x, y) => { // If suborg config has been updated then only restrict to the repos for that suborg if (this.subOrgConfigMap && !subOrgConfig) { - this.log.debug(`Skipping... SubOrg config changed but this repo is not part of it. ${JSON.stringify(repo)} suborg config ${JSON.stringify(this.subOrgConfigMap)}`) + this.log.info(`Skipping... SubOrg config changed but this repo is not part of it. ${JSON.stringify(repo)} suborg config ${JSON.stringify(this.subOrgConfigMap)}`) return } @@ -286,10 +286,10 @@ ${this.results.reduce((x, y) => { if (Array.isArray(baseConfig) && Array.isArray(config)) { for (const baseEntry of baseConfig) { const newEntry = config.find(e => e.name === baseEntry.name) - this.validate(section, baseEntry, newEntry) + this.validate(repoName, section, baseEntry, newEntry) } } else { - this.validate(section, baseConfig, config) + this.validate(repoName, section, baseConfig, config) } if (section !== 'repositories' && section !== 'repository') { // Ignore any config that is not a plugin @@ -303,7 +303,7 @@ ${this.results.reduce((x, y) => { return childPlugins } - validate (section, baseConfig, overrideConfig) { + validate (repoName, section, baseConfig, overrideConfig) { const configValidator = this.configvalidators[section] if (configValidator) { this.log.debug(`Calling configvalidator for key ${section} `) @@ -328,7 +328,7 @@ ${this.results.reduce((x, y) => { if (Array.isArray(restrictedRepos)) { // For backward compatibility support the old format if (restrictedRepos.includes(repoName)) { - this.log.debug(`Skipping retricted repo ${repoName}`) + this.log.info(`Skipping retricted repo ${repoName}`) return true } else { this.log.debug(`${repoName} not in restricted repos ${restrictedRepos}`) @@ -339,12 +339,12 @@ ${this.results.reduce((x, y) => { this.log.debug(`Allowing ${repoName} in restrictedRepos.include [${restrictedRepos.include}]`) return false } else { - this.log.debug(`Skipping repo ${repoName} not in restrictedRepos.include`) + this.log.info(`Skipping repo ${repoName} not in restrictedRepos.include`) return true } } else if (Array.isArray(restrictedRepos.exclude)) { if (this.includesRepo(repoName, restrictedRepos.exclude)) { - this.log.debug(`Skipping excluded repo ${repoName} in restrictedRepos.exclude`) + this.log.info(`Skipping excluded repo ${repoName} in restrictedRepos.exclude`) return true } else { this.log.debug(`Allowing ${repoName} not in restrictedRepos.exclude [${restrictedRepos.exclude}]`) @@ -453,8 +453,8 @@ ${this.results.reduce((x, y) => { // read the repo contents using tree this.log.debug(`repos directory info ${JSON.stringify(repoDirInfo)}`) - //const endpoint = `/repos/${this.repo.owner}/${repo.repo}/git/trees/${repoDirInfo.sha}` - //this.log.debug(`endpoint: ${endpoint}`) + // const endpoint = `/repos/${this.repo.owner}/${repo.repo}/git/trees/${repoDirInfo.sha}` + // this.log.debug(`endpoint: ${endpoint}`) const treeParams = Object.assign(repo, { tree_sha: repoDirInfo.sha, recursive: 0 }) const response = await this.github.git.getTree(treeParams).catch(e => { this.log.debug(`Error getting settings ${JSON.stringify(this.github.git.getTree.endpoint(treeParams))} ${e}`) diff --git a/lib/validator.js b/lib/validator.js index 6d61e040..d675a7ff 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -5,7 +5,7 @@ module.exports = class Validator { // this.regex = /[a-zA-Z0-9_-]+_\w[a-zA-Z0-9_-]+.*/gm this.regex = new RegExp(this.pattern, 'gm') this.repo = repo - this.log = log + this.log = log.child({ context: 'Validator', repository: this.repo.repo }) } sync () { @@ -18,7 +18,7 @@ module.exports = class Validator { } }).then(res => { if (this.repo.repo.search(this.regex) >= 0) { - this.log(`Repo ${this.repo.repo} Passed Validation for pattern ${this.pattern}`) + this.log.debug(`Repo ${this.repo.repo} Passed Validation for pattern ${this.pattern}`) if (res.data.names.find(x => x === 'validation-error')) { res.data.names = res.data.names.filter(x => x !== 'validation-error') return this.github.repos.replaceAllTopics({ @@ -31,7 +31,7 @@ module.exports = class Validator { }) } } else { - this.log(`Repo ${this.repo.repo} Failed Validation for pattern ${this.pattern}`) + this.log.error(`Repo ${this.repo.repo} Failed Validation for pattern ${this.pattern}`) if (!res.data.names.find(x => x === 'validation-error')) { res.data.names.push('validation-error') return this.github.repos.replaceAllTopics({ @@ -46,7 +46,7 @@ module.exports = class Validator { } }) } catch (error) { - this.log(`Error in Validation checking ${error}`) + this.log.error(`Error in Validation checking ${error}`) } } } From d478bdadbe39cb5289e44ff62275f42b0822561c Mon Sep 17 00:00:00 2001 From: Martin Migasiewicz <616250+martinm82@users.noreply.github.com> Date: Wed, 26 Apr 2023 07:50:50 +0200 Subject: [PATCH 2/7] fixup! chore(logs): improve log messages --- lib/plugins/branches.js | 2 +- lib/plugins/diffable.js | 2 +- lib/plugins/repository.js | 4 ++-- lib/validator.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/plugins/branches.js b/lib/plugins/branches.js index e524f82b..1c02ad7b 100644 --- a/lib/plugins/branches.js +++ b/lib/plugins/branches.js @@ -8,7 +8,7 @@ module.exports = class Branches { this.github = github this.repo = repo this.branches = settings - this.log = log.child({ context: 'Branches', repository: this.repo.repo }) + this.log = log.child({ plugin: 'Branches', repository: this.repo.repo }) this.nop = nop } diff --git a/lib/plugins/diffable.js b/lib/plugins/diffable.js index 9535e23f..8550bb4a 100644 --- a/lib/plugins/diffable.js +++ b/lib/plugins/diffable.js @@ -27,7 +27,7 @@ module.exports = class Diffable { this.github = github this.repo = repo this.entries = entries - this.log = log.child({ context: this.constructor.name, repository: this.repo.repo }) + this.log = log.child({ plugin: this.constructor.name, repository: this.repo.repo }) this.nop = nop } diff --git a/lib/plugins/repository.js b/lib/plugins/repository.js index e9d5dd44..40312945 100644 --- a/lib/plugins/repository.js +++ b/lib/plugins/repository.js @@ -50,7 +50,7 @@ module.exports = class Repository { this.topics = this.settings.topics this.security = this.settings.security this.repo = repo - this.log = log.child({ context: 'Repository', repository: this.repo.repo }) + this.log = log.child({ plugin: 'Repository', repository: this.repo.repo }) this.nop = nop this.force_create = this.settings.force_create this.template = this.settings.template @@ -254,7 +254,7 @@ module.exports = class Repository { resArray.push((new NopCommand(this.constructor.name, this.repo, null, `no need to update security for ${repoData.name}`))) return Promise.resolve(resArray) } - } + } } updateAutomatedSecurityFixes(repoData, resArray) { diff --git a/lib/validator.js b/lib/validator.js index d675a7ff..98b51281 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -5,7 +5,7 @@ module.exports = class Validator { // this.regex = /[a-zA-Z0-9_-]+_\w[a-zA-Z0-9_-]+.*/gm this.regex = new RegExp(this.pattern, 'gm') this.repo = repo - this.log = log.child({ context: 'Validator', repository: this.repo.repo }) + this.log = log.child({ plugin: 'Validator', repository: this.repo.repo }) } sync () { From 397144578740df5c7a0b856ebce3e4b8fb60d297 Mon Sep 17 00:00:00 2001 From: Martin Migasiewicz <616250+martinm82@users.noreply.github.com> Date: Wed, 26 Apr 2023 08:01:39 +0200 Subject: [PATCH 3/7] fixup! chore(logs): improve log messages --- lib/plugin.js | 5 +++++ lib/plugins/branches.js | 2 +- lib/plugins/diffable.js | 5 +++-- lib/plugins/repository.js | 2 +- lib/plugins/validator.js | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 lib/plugin.js diff --git a/lib/plugin.js b/lib/plugin.js new file mode 100644 index 00000000..f83d8779 --- /dev/null +++ b/lib/plugin.js @@ -0,0 +1,5 @@ +module.exports = class Plugin { + constructor (log, repo_name) { + this.log = log.child({ component: 'plugin', plugin: this.constructor.name, repository: repo_name }) + } +} diff --git a/lib/plugins/branches.js b/lib/plugins/branches.js index 1c02ad7b..e7066f73 100644 --- a/lib/plugins/branches.js +++ b/lib/plugins/branches.js @@ -8,8 +8,8 @@ module.exports = class Branches { this.github = github this.repo = repo this.branches = settings - this.log = log.child({ plugin: 'Branches', repository: this.repo.repo }) this.nop = nop + super(log, this.repo.repo) } sync () { diff --git a/lib/plugins/diffable.js b/lib/plugins/diffable.js index 8550bb4a..dc3e82f0 100644 --- a/lib/plugins/diffable.js +++ b/lib/plugins/diffable.js @@ -19,16 +19,17 @@ // remove(existing) { // } // } +const Plugin = require('../plugin') const MergeDeep = require('../mergeDeep') const NopCommand = require('../nopcommand') const ignorableFields = ['id', 'node_id', 'default', 'url'] -module.exports = class Diffable { +module.exports = class Diffable extends Plugin { constructor (nop, github, repo, entries, log) { this.github = github this.repo = repo this.entries = entries - this.log = log.child({ plugin: this.constructor.name, repository: this.repo.repo }) this.nop = nop + super(log, this.repo.repo) } filterEntries () { diff --git a/lib/plugins/repository.js b/lib/plugins/repository.js index 40312945..f589c700 100644 --- a/lib/plugins/repository.js +++ b/lib/plugins/repository.js @@ -50,13 +50,13 @@ module.exports = class Repository { this.topics = this.settings.topics this.security = this.settings.security this.repo = repo - this.log = log.child({ plugin: 'Repository', repository: this.repo.repo }) this.nop = nop this.force_create = this.settings.force_create this.template = this.settings.template delete this.settings.topics delete this.settings.force delete this.settings.template + super(log, this.repo.repo) } sync () { diff --git a/lib/plugins/validator.js b/lib/plugins/validator.js index e97896c2..1cfbda29 100644 --- a/lib/plugins/validator.js +++ b/lib/plugins/validator.js @@ -6,8 +6,8 @@ module.exports = class Validator { // this.regex = /[a-zA-Z0-9_-]+_\w[a-zA-Z0-9_-]+.*/gm this.regex = new RegExp(this.pattern, 'gm') this.repo = repo - this.log = log.child({ context: 'Validator', repository: this.repo.repo }) this.nop = nop + super(log, this.repo.repo) } sync () { From cf82d4e5156f6a6fb7d9610d783afff481f30ba3 Mon Sep 17 00:00:00 2001 From: Martin Migasiewicz <616250+martinm82@users.noreply.github.com> Date: Wed, 26 Apr 2023 08:04:29 +0200 Subject: [PATCH 4/7] fixup! chore(logs): improve log messages --- lib/plugin.js | 2 ++ lib/plugins/branches.js | 3 ++- lib/plugins/repository.js | 3 ++- lib/plugins/validator.js | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index f83d8779..62aeec0c 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,3 +1,5 @@ +// Base class for all plugins + module.exports = class Plugin { constructor (log, repo_name) { this.log = log.child({ component: 'plugin', plugin: this.constructor.name, repository: repo_name }) diff --git a/lib/plugins/branches.js b/lib/plugins/branches.js index e7066f73..21292204 100644 --- a/lib/plugins/branches.js +++ b/lib/plugins/branches.js @@ -1,9 +1,10 @@ +const Plugin = require('../plugin') const NopCommand = require('../nopcommand') const MergeDeep = require('../mergeDeep') const ignorableFields = [] const previewHeaders = { accept: 'application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json' } -module.exports = class Branches { +module.exports = class Branches extends Plugin { constructor (nop, github, repo, settings, log) { this.github = github this.repo = repo diff --git a/lib/plugins/repository.js b/lib/plugins/repository.js index f589c700..2fe7357b 100644 --- a/lib/plugins/repository.js +++ b/lib/plugins/repository.js @@ -1,5 +1,6 @@ // const { restEndpointMethods } = require('@octokit/plugin-rest-endpoint-methods') // const EndPoints = require('@octokit/plugin-rest-endpoint-methods') +const Plugin = require('../plugin') const NopCommand = require('../nopcommand') const MergeDeep = require('../mergeDeep') const ignorableFields = [ @@ -42,7 +43,7 @@ const ignorableFields = [ 'repo' ] -module.exports = class Repository { +module.exports = class Repository extends Plugin { constructor (nop, github, repo, settings, installationId, log) { this.installationId = installationId this.github = github diff --git a/lib/plugins/validator.js b/lib/plugins/validator.js index 1cfbda29..8c63d3e8 100644 --- a/lib/plugins/validator.js +++ b/lib/plugins/validator.js @@ -1,5 +1,6 @@ +const Plugin = require('../plugin') const NopCommand = require('../nopcommand') -module.exports = class Validator { +module.exports = class Validator extends Plugin { constructor (nop, github, repo, settings, log) { this.github = github this.pattern = settings.pattern From 09c8ab76fccd4252e9b9e1979bc1779577204235 Mon Sep 17 00:00:00 2001 From: Martin Migasiewicz <616250+martinm82@users.noreply.github.com> Date: Mon, 24 Apr 2023 10:38:53 +0200 Subject: [PATCH 5/7] chore: log when doing repo or suborg sync --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 1abc86a0..6fc3c14c 100644 --- a/index.js +++ b/index.js @@ -252,6 +252,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { const repoChanges = getAllChangedRepoConfigs(payload, context.repo().owner) if (repoChanges.length > 0) { return Promise.all(repoChanges.map(repo => { + log.debug(`Changes in '${repo}' detected, doing a repo sync...`) return syncSettings(false, context, repo) })) } @@ -259,6 +260,7 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => { const changes = getAllChangedSubOrgConfigs(payload) if (changes.length) { return Promise.all(changes.map(suborg => { + log.debug(`Changes in '${suborg}' detected, doing a suborg sync...`) return syncSubOrgSettings(false, context, suborg) })) } From 871ebbc57f01e050d806f074f0ce38c66c157f4a Mon Sep 17 00:00:00 2001 From: Martin Migasiewicz <616250+martinm82@users.noreply.github.com> Date: Wed, 26 Apr 2023 08:11:54 +0200 Subject: [PATCH 6/7] chore: fix eslint errors --- lib/plugin.js | 4 ++-- lib/plugins/branches.js | 2 +- lib/plugins/diffable.js | 2 +- lib/plugins/repository.js | 2 +- lib/plugins/validator.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index 62aeec0c..fb1e5d4f 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,7 +1,7 @@ // Base class for all plugins module.exports = class Plugin { - constructor (log, repo_name) { - this.log = log.child({ component: 'plugin', plugin: this.constructor.name, repository: repo_name }) + constructor (log, repoName) { + this.log = log.child({ component: 'plugin', plugin: this.constructor.name, repository: repoName }) } } diff --git a/lib/plugins/branches.js b/lib/plugins/branches.js index 21292204..76a750f1 100644 --- a/lib/plugins/branches.js +++ b/lib/plugins/branches.js @@ -6,11 +6,11 @@ const previewHeaders = { accept: 'application/vnd.github.hellcat-preview+json,ap module.exports = class Branches extends Plugin { constructor (nop, github, repo, settings, log) { + super(log, repo.repo) this.github = github this.repo = repo this.branches = settings this.nop = nop - super(log, this.repo.repo) } sync () { diff --git a/lib/plugins/diffable.js b/lib/plugins/diffable.js index dc3e82f0..28a83a09 100644 --- a/lib/plugins/diffable.js +++ b/lib/plugins/diffable.js @@ -25,11 +25,11 @@ const NopCommand = require('../nopcommand') const ignorableFields = ['id', 'node_id', 'default', 'url'] module.exports = class Diffable extends Plugin { constructor (nop, github, repo, entries, log) { + super(log, repo.repo) this.github = github this.repo = repo this.entries = entries this.nop = nop - super(log, this.repo.repo) } filterEntries () { diff --git a/lib/plugins/repository.js b/lib/plugins/repository.js index 2fe7357b..203fb2da 100644 --- a/lib/plugins/repository.js +++ b/lib/plugins/repository.js @@ -45,6 +45,7 @@ const ignorableFields = [ module.exports = class Repository extends Plugin { constructor (nop, github, repo, settings, installationId, log) { + super(log, repo.repo) this.installationId = installationId this.github = github this.settings = Object.assign({ mediaType: { previews: ['nebula-preview'] } }, settings, repo) @@ -57,7 +58,6 @@ module.exports = class Repository extends Plugin { delete this.settings.topics delete this.settings.force delete this.settings.template - super(log, this.repo.repo) } sync () { diff --git a/lib/plugins/validator.js b/lib/plugins/validator.js index 8c63d3e8..d84a01a6 100644 --- a/lib/plugins/validator.js +++ b/lib/plugins/validator.js @@ -2,13 +2,13 @@ const Plugin = require('../plugin') const NopCommand = require('../nopcommand') module.exports = class Validator extends Plugin { constructor (nop, github, repo, settings, log) { + super(log, repo.repo) this.github = github this.pattern = settings.pattern // this.regex = /[a-zA-Z0-9_-]+_\w[a-zA-Z0-9_-]+.*/gm this.regex = new RegExp(this.pattern, 'gm') this.repo = repo this.nop = nop - super(log, this.repo.repo) } sync () { From b4c6d47fb9f6d63259c9384c83e8ac7503f62028 Mon Sep 17 00:00:00 2001 From: Martin Migasiewicz <616250+martinm82@users.noreply.github.com> Date: Wed, 26 Apr 2023 08:34:03 +0200 Subject: [PATCH 7/7] fixup! fixup! chore(logs): improve log messages --- lib/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin.js b/lib/plugin.js index fb1e5d4f..cfa645cf 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -2,6 +2,6 @@ module.exports = class Plugin { constructor (log, repoName) { - this.log = log.child({ component: 'plugin', plugin: this.constructor.name, repository: repoName }) + this.log = log.child({ plugin: this.constructor.name, repository: repoName }) } }