Skip to content

Commit

Permalink
chore: autoformatted after changed eslint config in github#664
Browse files Browse the repository at this point in the history
Mostly, the changes in github#664 relaxes the eslint rules, but that PR also removes the space before the parentheses in function definitions.
The formatting was done with the vscode js/ts formatter `vscode.typescript-language-features`, and since this also does the same change it is now consistent across the whole codebase.

Other than removing the space-before-function-paren, some files with inconsistent indentation and/or trailing spaces has been updated.
  • Loading branch information
Gramatus committed Oct 5, 2024
1 parent 60f8fd3 commit d3510fd
Show file tree
Hide file tree
Showing 38 changed files with 623 additions and 624 deletions.
42 changes: 21 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let deploymentConfig
module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => {
let appName = 'safe-settings'
let appSlug = 'safe-settings'
async function syncAllSettings (nop, context, repo = context.repo(), ref) {
async function syncAllSettings(nop, context, repo = context.repo(), ref) {
try {
deploymentConfig = await loadYamlFileSystem()
robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`)
Expand Down Expand Up @@ -42,7 +42,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
}
}

async function syncSubOrgSettings (nop, context, suborg, repo = context.repo(), ref) {
async function syncSubOrgSettings(nop, context, suborg, repo = context.repo(), ref) {
try {
deploymentConfig = await loadYamlFileSystem()
robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`)
Expand All @@ -67,7 +67,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
}
}

async function syncSettings (nop, context, repo = context.repo(), ref) {
async function syncSettings(nop, context, repo = context.repo(), ref) {
try {
deploymentConfig = await loadYamlFileSystem()
robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`)
Expand All @@ -92,7 +92,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
}
}

async function renameSync (nop, context, repo = context.repo(), rename, ref) {
async function renameSync(nop, context, repo = context.repo(), rename, ref) {
try {
deploymentConfig = await loadYamlFileSystem()
robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`)
Expand All @@ -101,7 +101,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
const config = Object.assign({}, deploymentConfig, runtimeConfig)
const renameConfig = Object.assign({}, config, rename)
robot.log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`)
return Settings.sync(nop, context, repo, renameConfig, ref )
return Settings.sync(nop, context, repo, renameConfig, ref)
} catch (e) {
if (nop) {
let filename = env.SETTINGS_FILE_PATH
Expand All @@ -123,7 +123,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
*
* @return The parsed YAML file
*/
async function loadYamlFileSystem () {
async function loadYamlFileSystem() {
if (deploymentConfig === undefined) {
const deploymentConfigPath = env.DEPLOYMENT_CONFIG_FILE
if (fs.existsSync(deploymentConfigPath)) {
Expand All @@ -135,7 +135,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
return deploymentConfig
}

function getAllChangedSubOrgConfigs (payload) {
function getAllChangedSubOrgConfigs(payload) {
const settingPattern = new Glob(`${env.CONFIG_PATH}/suborgs/*.yml`)
// Changes will be an array of files that were added
const added = payload.commits.map(c => {
Expand All @@ -159,7 +159,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
return configs
}

function getAllChangedRepoConfigs (payload, owner) {
function getAllChangedRepoConfigs(payload, owner) {
const settingPattern = new Glob(`${env.CONFIG_PATH}/repos/*.yml`)
// Changes will be an array of files that were added
const added = payload.commits.map(c => {
Expand All @@ -182,7 +182,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
return configs
}

function getChangedRepoConfigName (glob, files, owner) {
function getChangedRepoConfigName(glob, files, owner) {
const modifiedFiles = files.filter(s => {
robot.log.debug(JSON.stringify(s))
return (s.search(glob) >= 0)
Expand All @@ -193,7 +193,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
})
}

function getChangedSubOrgConfigName (glob, files) {
function getChangedSubOrgConfigName(glob, files) {
const modifiedFiles = files.filter(s => {
robot.log.debug(JSON.stringify(s))
return (s.search(glob) >= 0)
Expand All @@ -205,7 +205,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
})
}

async function createCheckRun (context, pull_request, head_sha, head_branch) {
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 res = await context.octokit.checks.create({
Expand Down Expand Up @@ -234,7 +234,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
}


async function syncInstallation () {
async function syncInstallation() {
robot.log.trace('Fetching installations')
const github = await robot.auth()

Expand Down Expand Up @@ -395,7 +395,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
})

robot.on('repository.renamed', async context => {
if (env.BLOCK_REPO_RENAME_BY_HUMAN!== 'true') {
if (env.BLOCK_REPO_RENAME_BY_HUMAN !== 'true') {
robot.log.debug(`"env.BLOCK_REPO_RENAME_BY_HUMAN" is 'false' by default. Repo rename is not managed by Safe-settings. Continue with the default behavior.`)
return
}
Expand All @@ -414,7 +414,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
const newPath = `.github/repos/${payload.repository.name}.yml`
robot.log.debug(oldPath)
try {
const repofile = await context.octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
const repofile = await context.octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: payload.repository.owner.login,
repo: env.ADMIN_REPO,
path: oldPath,
Expand Down Expand Up @@ -443,7 +443,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
owner: payload.repository.owner.login,
repo: env.ADMIN_REPO,
path: newPath,
name: `${payload.repository.name}.yml`,
name: `${payload.repository.name}.yml`,
content: content,
message: `Repo Renamed and safe-settings renamed the file from ${payload.changes.repository.name.from} to ${payload.repository.name}`,
sha: repofile.data.sha,
Expand All @@ -455,21 +455,21 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
} else {
robot.log.error(error)
}
}
}

} catch (error) {
if (error.status === 404) {
//nop
} else {
} else {
robot.log.error(error)
}
}
}
return
} else {
robot.log.debug('Repository Edited by a Human')
// Create a repository config to reset the name back to the previous name
const rename = {repository: { name: payload.changes.repository.name.from, oldname: payload.repository.name}}
const repo = {repo: payload.changes.repository.name.from, owner: payload.repository.owner.login}
const rename = { repository: { name: payload.changes.repository.name.from, oldname: payload.repository.name } }
const repo = { repo: payload.changes.repository.name.from, owner: payload.repository.owner.login }
return renameSync(false, context, repo, rename)
}
})
Expand Down Expand Up @@ -663,7 +663,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
syncInstallation()
})
}

// Get info about the app
info()

Expand Down
4 changes: 2 additions & 2 deletions lib/commentmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = `* Run on: \` <%= new Date() %> \`
### Breakdown of changes
| Repo <% Object.keys(it.changes).forEach(plugin => { %> | <%= plugin %> settings <% }) %> |
| -- <% Object.keys(it.changes).forEach(plugin => { -%> | -- <% }) %>
|
|
<% Object.keys(it.reposProcessed).forEach( repo => { -%>
| <%= repo -%>
<%- Object.keys(it.changes).forEach(plugin => { -%>
Expand All @@ -22,7 +22,7 @@ module.exports = `* Run on: \` <%= new Date() %> \`
\`None\`
<% } else { %>
<% Object.keys(it.errors).forEach(repo => { %>
<%_= repo %>:
<%_= repo %>:
<% it.errors[repo].forEach(plugin => { %>
* <%= plugin.msg %>
<% }) %>
Expand Down
6 changes: 3 additions & 3 deletions lib/configManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const yaml = require('js-yaml')
const env = require('./env')

module.exports = class ConfigManager {
constructor (context, ref) {
constructor(context, ref) {
this.context = context
this.ref = ref
this.log = context.log
Expand All @@ -15,7 +15,7 @@ module.exports = class ConfigManager {
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async loadYaml (filePath) {
async loadYaml(filePath) {
try {
const repo = { owner: this.context.repo().owner, repo: env.ADMIN_REPO }
const params = Object.assign(repo, { path: filePath, ref: this.ref })
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports = class ConfigManager {
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async loadGlobalSettingsYaml () {
async loadGlobalSettingsYaml() {
const CONFIG_PATH = env.CONFIG_PATH
const filePath = path.posix.join(CONFIG_PATH, env.SETTINGS_FILE_PATH)
return this.loadYaml(filePath)
Expand Down
68 changes: 34 additions & 34 deletions lib/deploymentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@ const env = require('./env')
* The settings are loaded from the deployment-settings.yml file during initialization and stored as static properties.
*/
class DeploymentConfig {
//static config
static configvalidators = {}
static overridevalidators = {}
//static config
static configvalidators = {}
static overridevalidators = {}

static {
const deploymentConfigPath = process.env.DEPLOYMENT_CONFIG_FILE ? process.env.DEPLOYMENT_CONFIG_FILE : 'deployment-settings.yml'
if (fs.existsSync(deploymentConfigPath)) {
this.config = yaml.load(fs.readFileSync(deploymentConfigPath))
} else {
this.config = { restrictedRepos: ['admin', '.github', 'safe-settings'] }
}

const overridevalidators = this.config.overridevalidators
if (this.isIterable(overridevalidators)) {
for (const validator of overridevalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', 'overrideconfig', 'githubContext', validator.script)
this.overridevalidators[validator.plugin] = { canOverride: f, error: validator.error }
}
}
const configvalidators = this.config.configvalidators
if (this.isIterable(configvalidators)) {
for (const validator of configvalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', 'githubContext', validator.script)
this.configvalidators[validator.plugin] = { isValid: f, error: validator.error }
}
}
static {
const deploymentConfigPath = process.env.DEPLOYMENT_CONFIG_FILE ? process.env.DEPLOYMENT_CONFIG_FILE : 'deployment-settings.yml'
if (fs.existsSync(deploymentConfigPath)) {
this.config = yaml.load(fs.readFileSync(deploymentConfigPath))
} else {
this.config = { restrictedRepos: ['admin', '.github', 'safe-settings'] }
}

static isIterable (obj) {
// checks for null and undefined
if (obj == null) {
return false
}
return typeof obj[Symbol.iterator] === 'function'
const overridevalidators = this.config.overridevalidators
if (this.isIterable(overridevalidators)) {
for (const validator of overridevalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', 'overrideconfig', 'githubContext', validator.script)
this.overridevalidators[validator.plugin] = { canOverride: f, error: validator.error }
}
}
const configvalidators = this.config.configvalidators
if (this.isIterable(configvalidators)) {
for (const validator of configvalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', 'githubContext', validator.script)
this.configvalidators[validator.plugin] = { isValid: f, error: validator.error }
}
}
}

constructor (nop, context, repo, config, ref, suborg) {
static isIterable(obj) {
// checks for null and undefined
if (obj == null) {
return false
}
return typeof obj[Symbol.iterator] === 'function'
}

constructor(nop, context, repo, config, ref, suborg) {
}
}
DeploymentConfig.FILE_NAME = `${env.CONFIG_PATH}/settings.yml`

Expand Down
4 changes: 2 additions & 2 deletions lib/error.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = `Run on: \`<%= new Date().toISOString() %>\`
#### Breakdown of Errors
| Owner| Repo | Plugin | Error
| --- | --- | --- | ---
| Owner| Repo | Plugin | Error
| --- | --- | --- | ---
<% it.forEach( error => { -%>
<%= error.owner %> | <%= error.repo %> | <%= error.plugin %> | <%= error.msg %>
Expand Down
14 changes: 7 additions & 7 deletions lib/glob.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Glob {
constructor (glob) {
constructor(glob) {
this.glob = glob

// If not a glob pattern then just match the string.
Expand All @@ -11,7 +11,7 @@ class Glob {
this.regexp = new RegExp(`^${this.regexptText}$`, 'u')
}

globize (glob) {
globize(glob) {
return glob
.replace(/\\/g, '\\\\') // escape backslashes
.replace(/\//g, '\\/') // escape forward slashes
Expand All @@ -21,23 +21,23 @@ class Glob {
.replace(/\*/g, '([^\\/]*)') // match any character except /
}

toString () {
toString() {
return this.glob
}

[Symbol.search] (s) {
[Symbol.search](s) {
return s.search(this.regexp)
}

[Symbol.match] (s) {
[Symbol.match](s) {
return s.match(this.regexp)
}

[Symbol.replace] (s, replacement) {
[Symbol.replace](s, replacement) {
return s.replace(this.regexp, replacement)
}

[Symbol.replaceAll] (s, replacement) {
[Symbol.replaceAll](s, replacement) {
return s.replaceAll(this.regexp, replacement)
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/mergeArrayBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const merge = require('deepmerge')

function findMatchingIndex (properties, sourceItem, target) {
function findMatchingIndex(properties, sourceItem, target) {
const hasAnyProperty = item => properties.some(prop => Object.prototype.hasOwnProperty.call(item, prop))
if (hasAnyProperty(sourceItem)) {
return target
Expand All @@ -11,7 +11,7 @@ function findMatchingIndex (properties, sourceItem, target) {
}
}

function mergeBy (key, configvalidator, overridevalidator, properties, target, source, options, githubContext) {
function mergeBy(key, configvalidator, overridevalidator, properties, target, source, options, githubContext) {
const destination = target.slice()
source.forEach(sourceItem => {
const matchingIndex = findMatchingIndex(properties, sourceItem, target)
Expand Down
Loading

0 comments on commit d3510fd

Please sign in to comment.