Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions lib/configManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ module.exports = class ConfigManager {
const params = Object.assign(repo, { path: filePath, ref: this.ref })
const response = await this.context.octokit.repos.getContent(params).catch(e => {
this.log.error(`Error getting settings ${e}`)
return null
})

if (!response) {
return null
}

// Ignore in case path is a folder
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory
if (Array.isArray(response.data)) {
Expand Down
32 changes: 16 additions & 16 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const env = require('./env')
const CONFIG_PATH = env.CONFIG_PATH
const eta = new Eta({ views: path.join(__dirname) })
const SCOPE = { ORG: 'org', REPO: 'repo' } // Determine if the setting is a org setting or repo setting
const yaml = require('js-yaml');
const yaml = require('js-yaml')

class Settings {
static fileCache = {};
static fileCache = {}

static async syncAll (nop, context, repo, config, ref) {
const settings = new Settings(nop, context, repo, config, ref)
Expand Down Expand Up @@ -170,10 +170,10 @@ class Settings {

// remove duplicate rows in this.results
this.results = this.results.filter((thing, index, self) => {
return index === self.findIndex((t) => {
return t.type === thing.type && t.repo === thing.repo && t.plugin === thing.plugin
})
return index === self.findIndex((t) => {
return t.type === thing.type && t.repo === thing.repo && t.plugin === thing.plugin
})
})

let error = false
// Different logic
Expand Down Expand Up @@ -203,15 +203,15 @@ class Settings {
if (!stats.errors[res.repo]) {
stats.errors[res.repo] = []
}
stats.errors[res.repo].push(res.action)
stats.errors[res.repo].push(res.action ?? { msg: 'Unknown error' })
} else if (!(res.action?.additions === null && res.action?.deletions === null && res.action?.modifications === null)) {
if (!stats.changes[res.plugin]) {
stats.changes[res.plugin] = {}
}
if (!stats.changes[res.plugin][res.repo]) {
stats.changes[res.plugin][res.repo] = []
}
stats.changes[res.plugin][res.repo].push(`${res.action}`)
stats.changes[res.plugin][res.repo].push(res.action ?? { msg: 'No action details' })
}
}
})
Expand Down Expand Up @@ -242,16 +242,18 @@ ${this.results.reduce((x, y) => {
if (!y) {
return x
}
// Skip results that don't have an action property or have undefined action
if (!y.action) {
return x
}

if (y.type === 'ERROR') {
error = true
return `${x}
<tr><td> ❗ ${y.action.msg} </td><td> ${y.plugin} </td><td> ${prettify(y.repo)} </td><td> ${prettify(y.action.additions)} </td><td> ${prettify(y.action.deletions)} </td><td> ${prettify(y.action.modifications)} </td><tr>`
} else if (y.action.additions === null && y.action.deletions === null && y.action.modifications === null) {
return `${x}`
return x
} else {
if (y.action === undefined) {
return `${x}`
}
return `${x}
<tr><td> ✋ </td><td> ${y.plugin} </td><td> ${prettify(y.repo)} </td><td> ${prettify(y.action.additions)} </td><td> ${prettify(y.action.deletions)} </td><td> ${prettify(y.action.modifications)} </td><tr>`
}
Expand Down Expand Up @@ -300,7 +302,7 @@ ${this.results.reduce((x, y) => {
}
}

async updateRepos(repo) {
async updateRepos (repo) {
this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs()
// Keeping this as is instead of doing an object assign as that would cause `Cannot read properties of undefined (reading 'startsWith')` error
// Copilot code review would recoommend using object assign but that would cause the error
Expand Down Expand Up @@ -368,7 +370,6 @@ ${this.results.reduce((x, y) => {
}
}


async updateAll () {
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
Expand Down Expand Up @@ -791,14 +792,14 @@ ${this.results.reduce((x, y) => {
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async loadYaml(filePath) {
async loadYaml (filePath) {
try {
const repo = { owner: this.repo.owner, repo: env.ADMIN_REPO }
const params = Object.assign(repo, {
path: filePath,
ref: this.ref
})
const namespacedFilepath = `${this.repo.owner}/${filePath}`;
const namespacedFilepath = `${this.repo.owner}/${filePath}`

// If the filepath already exists in the fileCache, add the etag to the params
// to check if the file has changed
Expand Down Expand Up @@ -898,7 +899,6 @@ ${this.results.reduce((x, y) => {
}
}


async getSubOrgRepositories (subOrgProperties) {
const organizationName = this.repo.owner
try {
Expand Down