Skip to content

Fix remaining linting errors and enable linting on CI #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main-enterprise
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm install
- run: npm run lint:es
- run: npm run lint:js
- run: npm run lint:lockfile
- run: npm run test:unit:ci
strategy:
matrix:
Expand Down
4 changes: 2 additions & 2 deletions lib/mergeDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class MergeDeep {
// So any property in the target that is not in the source is not treated as a deletion
for (const key in source) {
// Skip prototype pollution vectors
if (key === "__proto__" || key === "constructor") {
continue;
if (key === '__proto__' || key === 'constructor') {
continue
}
// Logic specific for Github
// API response includes urls for resources, or other ignorable fields; we can ignore them
Expand Down
95 changes: 44 additions & 51 deletions lib/plugins/archive.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,79 @@
const NopCommand = require('../nopcommand');
const NopCommand = require('../nopcommand')

function returnValue(shouldContinue, nop) {
return { shouldContinue, nopCommands: nop };
function returnValue (shouldContinue, nop) {
return { shouldContinue, nopCommands: nop }
}

module.exports = class Archive {
constructor(nop, github, repo, settings, log) {
this.github = github;
this.repo = repo;
this.settings = settings;
this.log = log;
this.nop = nop;
constructor (nop, github, repo, settings, log) {
this.github = github
this.repo = repo
this.settings = settings
this.log = log
this.nop = nop
}

// Returns true if plugin application should continue, false otherwise
async sync() {
async sync () {
// Fetch repository details using REST API
const { data: repoDetails } = await this.github.repos.get({
owner: this.repo.owner,
repo: this.repo.repo
});
owner: this.repo.owner,
repo: this.repo.repo
})
if (typeof this.settings?.archived !== 'undefined') {
this.log.debug(`Checking if ${this.repo.owner}/${this.repo.repo} is archived`);
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is ${repoDetails.archived ? 'archived' : 'not archived'}`);
this.log.debug(`Checking if ${this.repo.owner}/${this.repo.repo} is archived`)

this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is ${repoDetails.archived ? 'archived' : 'not archived'}`)

if (repoDetails.archived) {
if (this.settings.archived) {
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} already archived, inform other plugins should not run.`);
return returnValue(false);
}
else {
this.log.debug(`Unarchiving ${this.repo.owner}/${this.repo.repo}`);
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} already archived, inform other plugins should not run.`)
return returnValue(false)
} else {
this.log.debug(`Unarchiving ${this.repo.owner}/${this.repo.repo}`)
if (this.nop) {
return returnValue(true, [new NopCommand(this.constructor.name, this.repo, this.github.repos.update.endpoint(this.settings), 'will unarchive')]);
}
else {
return returnValue(true, [new NopCommand(this.constructor.name, this.repo, this.github.repos.update.endpoint(this.settings), 'will unarchive')])
} else {
// Unarchive the repository using REST API
const updateResponse = await this.github.repos.update({
owner: this.repo.owner,
repo: this.repo.repo,
archived: false
});
this.log.debug(`Unarchive result ${JSON.stringify(updateResponse)}`);
})
this.log.debug(`Unarchive result ${JSON.stringify(updateResponse)}`)

return returnValue(true);
return returnValue(true)
}
}
}
else {
} else {
if (this.settings.archived) {
this.log.debug(`Archiving ${this.repo.owner}/${this.repo.repo}`);
this.log.debug(`Archiving ${this.repo.owner}/${this.repo.repo}`)
if (this.nop) {
return returnValue(false, [new NopCommand(this.constructor.name, this.repo, this.github.repos.update.endpoint(this.settings), 'will archive')]);
}
else {
return returnValue(false, [new NopCommand(this.constructor.name, this.repo, this.github.repos.update.endpoint(this.settings), 'will archive')])
} else {
// Archive the repository using REST API
const updateResponse = await this.github.repos.update({
owner: this.repo.owner,
repo: this.repo.repo,
archived: true
});
this.log.debug(`Archive result ${JSON.stringify(updateResponse)}`);
})
this.log.debug(`Archive result ${JSON.stringify(updateResponse)}`)

return returnValue(false);
return returnValue(false)
}
}
else {
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is not archived, ignoring.`);
return returnValue(true);
} else {
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is not archived, ignoring.`)
return returnValue(true)
}
}
}
else {
if (repoDetails.archived) {
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is archived, ignoring.`);
return returnValue(false);
}
else {
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is not archived, proceed as usual.`);
return returnValue(true);
}
} else {
if (repoDetails.archived) {
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is archived, ignoring.`)
return returnValue(false)
} else {
this.log.debug(`Repo ${this.repo.owner}/${this.repo.repo} is not archived, proceed as usual.`)
return returnValue(true)
}
}
}
};
}
8 changes: 4 additions & 4 deletions lib/plugins/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const Overrides = require('./overrides')
const ignorableFields = []
const previewHeaders = { accept: 'application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json' }
const overrides = {
'contexts': {
'action': 'reset',
'type': 'array'
},
contexts: {
action: 'reset',
type: 'array'
}
}

module.exports = class Branches extends ErrorStash {
Expand Down
8 changes: 4 additions & 4 deletions lib/plugins/diffable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module.exports = class Diffable extends ErrorStash {
// this.log.debug(` entries ${JSON.stringify(filteredEntries)}`)
filteredEntries = filteredEntries.filter(attrs => {
if (Array.isArray(attrs.exclude)) {
const excludeGlobs = attrs.exclude.map(exc => new Glob(exc));
const excludeGlobsMatch = excludeGlobs.some(glob => !!this.repo.repo.match(glob));
const excludeGlobs = attrs.exclude.map(exc => new Glob(exc))
const excludeGlobsMatch = excludeGlobs.some(glob => !!this.repo.repo.match(glob))

if (!attrs.exclude.includes(this.repo.repo) && !excludeGlobsMatch) {
// this.log.debug(`returning not excluded entry = ${JSON.stringify(attrs)} for repo ${this.repo.repo}`)
Expand All @@ -57,8 +57,8 @@ module.exports = class Diffable extends ErrorStash {
})
filteredEntries = filteredEntries.filter(attrs => {
if (Array.isArray(attrs.include)) {
const includeGlobs = attrs.include.map(inc => new Glob(inc));
const includeGlobsMatch = includeGlobs.some(glob => !!this.repo.repo.match(glob));
const includeGlobs = attrs.include.map(inc => new Glob(inc))
const includeGlobsMatch = includeGlobs.some(glob => !!this.repo.repo.match(glob))

if (attrs.include.includes(this.repo.repo) || includeGlobsMatch) {
// this.log.debug(`returning included entry = ${JSON.stringify(attrs)} for repo ${this.repo.repo}`)
Expand Down
88 changes: 44 additions & 44 deletions lib/plugins/environments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const Diffable = require('./diffable')
const MergeDeep = require('../mergeDeep')
const NopCommand = require('../nopcommand')

module.exports = class Environments extends Diffable {
Expand All @@ -19,13 +18,13 @@ module.exports = class Environments extends Diffable {
}
}

async nopifyRequest(url, options, description) {
async nopifyRequest (url, options, description) {
if (!this.nop) {
await this.github.request(url, options);
await this.github.request(url, options)
} else {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, url, description)
])
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, url, description)
])
}
}

Expand Down Expand Up @@ -147,7 +146,7 @@ module.exports = class Environments extends Diffable {
custom_branch_policies: !!attrs.deployment_branch_policy.custom_branch_policies
}
}
await this.nopifyRequest(`PUT /repos/:org/:repo/environments/:environment_name`, options, 'Update environment settings');
await this.nopifyRequest('PUT /repos/:org/:repo/environments/:environment_name', options, 'Update environment settings')
}

if (deploymentBranchPolicy && attrs.deployment_branch_policy && attrs.deployment_branch_policy.custom_branch_policies) {
Expand All @@ -157,14 +156,14 @@ module.exports = class Environments extends Diffable {
await this.nopifyRequest('DELETE /repos/:org/:repo/environments/:environment_name/deployment-branch-policies/:branch_policy_id', {
...baseRequestOptions,
branch_policy_id: policy.id
}, 'Delete deployment branch policy')
}, 'Delete deployment branch policy')
}

for (const policy of attrs.deployment_branch_policy.custom_branch_policies) {
await this.nopifyRequest(
'POST /repos/:org/:repo/environments/:environment_name/deployment-branch-policies',{
...baseRequestOptions,
name: policy
'POST /repos/:org/:repo/environments/:environment_name/deployment-branch-policies', {
...baseRequestOptions,
name: policy
}, 'Create deployment branch policy')
}
}
Expand All @@ -179,18 +178,18 @@ module.exports = class Environments extends Diffable {
if (existingVariable.value !== variable.value) {
await this.nopifyRequest(
'PATCH /repos/:org/:repo/environments/:environment_name/variables/:variable_name', {
...baseRequestOptions,
variable_name: variable.name,
value: variable.value
...baseRequestOptions,
variable_name: variable.name,
value: variable.value
}, 'Update environment variable'
)
)
}
} else {
await this.nopifyRequest(
'POST /repos/:org/:repo/environments/:environment_name/variables', {
...baseRequestOptions,
name: variable.name,
value: variable.value
...baseRequestOptions,
name: variable.name,
value: variable.value
}, 'Create environment variable'
)
}
Expand All @@ -199,8 +198,8 @@ module.exports = class Environments extends Diffable {
for (const variable of existingVariables) {
await this.nopifyRequest(
'DELETE /repos/:org/:repo/environments/:environment_name/variables/:variable_name', {
...baseRequestOptions,
variable_name: variable.name
...baseRequestOptions,
variable_name: variable.name
}, 'Delete environment variable'
)
}
Expand All @@ -215,19 +214,18 @@ module.exports = class Environments extends Diffable {
if (!existingRule) {
await this.nopifyRequest(
'POST /repos/:org/:repo/environments/:environment_name/deployment_protection_rules', {
...baseRequestOptions,
integration_id: rule.app_id
...baseRequestOptions,
integration_id: rule.app_id
}, 'Create deployment protection rule'
)
)
}
}
for (const rule of existingRules) {
await this.nopifyRequest('DELETE /repos/:org/:repo/environments/:environment_name/deployment_protection_rules/:rule_id', {
...baseRequestOptions,
rule_id: rule.id
}, "Delete deployment protection rule")
}, 'Delete deployment protection rule')
}

}
}

Expand All @@ -237,48 +235,50 @@ module.exports = class Environments extends Diffable {
repo: this.repo.repo,
environment_name: attrs.name
}

await this.nopifyRequest(
'PUT /repos/:org/:repo/environments/:environment_name', {
...baseRequestOptions,
wait_timer: attrs.wait_timer,
prevent_self_review: attrs.prevent_self_review,
reviewers: attrs.reviewers,
deployment_branch_policy: attrs.deployment_branch_policy == null ? null : {
...baseRequestOptions,
wait_timer: attrs.wait_timer,
prevent_self_review: attrs.prevent_self_review,
reviewers: attrs.reviewers,
deployment_branch_policy: attrs.deployment_branch_policy == null
? null
: {
protected_branches: !!attrs.deployment_branch_policy.protected_branches,
custom_branch_policies: !!attrs.deployment_branch_policy.custom_branch_policies
}
}
}, 'Update environment settings')

if (attrs.deployment_branch_policy && attrs.deployment_branch_policy.custom_branch_policies) {
for (const policy of attrs.deployment_branch_policy.custom_branch_policies) {
await this.nopifyRequest(
'POST /repos/:org/:repo/environments/:environment_name/deployment-branch-policies', {
...baseRequestOptions,
name: policy.name
...baseRequestOptions,
name: policy.name
}, 'Create deployment branch policy'
)
}
}

if (attrs.variables) {
for(const variable of attrs.variables) {
for (const variable of attrs.variables) {
await this.nopifyRequest(
'POST /repos/:org/:repo/environments/:environment_name/variables', {
...baseRequestOptions,
name: variable.name,
value: variable.value
}, 'Create environment variable'
)
}
)
}
}

if (attrs.deployment_protection_rules) {
for (const rule of attrs.deployment_protection_rules) {
await this.nopifyRequest(
'POST /repos/:org/:repo/environments/:environment_name/deployment_protection_rules', {
...baseRequestOptions,
integration_id: rule.app_id
...baseRequestOptions,
integration_id: rule.app_id
}, 'Create deployment protection rule'
)
}
Expand All @@ -293,16 +293,16 @@ module.exports = class Environments extends Diffable {
}

await this.nopifyRequest(
'DELETE /repos/:org/:repo/environments/:environment_name', {
...baseRequestOptions
}, 'Delete environment'
'DELETE /repos/:org/:repo/environments/:environment_name', {
...baseRequestOptions
}, 'Delete environment'
)
}
}

sync () {
const resArray = []
if (this.entries) {
let filteredEntries = this.filterEntries()
const filteredEntries = this.filterEntries()
return this.find().then(existingRecords => {
// Remove any null or undefined values from the diffables (usually comes from repo override)
for (const entry of filteredEntries) {
Expand Down
Loading