From af7fdc544766c1beeb212137135a19624a129d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjeramysoucy=E2=80=9D?= Date: Wed, 27 Dec 2023 10:28:31 -0500 Subject: [PATCH] Fixes style --- lib/github/index.js | 10 ++++------ lib/github/labels.js | 8 +++----- lib/snyk.js | 16 +++++++--------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/github/index.js b/lib/github/index.js index 095bc5d..5a39efd 100644 --- a/lib/github/index.js +++ b/lib/github/index.js @@ -21,7 +21,7 @@ module.exports = { }, // retrieve issue IDs already created in GitHub - async existingIssues() { + async existingIssues () { try { return await octokit.paginate( `GET /search/issues?q=repo%3A${conf.ghOwner}/${conf.ghRepo}+is%3Aissue+label%3Asnyk`, @@ -31,8 +31,7 @@ module.exports = { existingIssue.number ]) ) - } - catch (err) { + } catch (err) { throw new Error(`Failed to paginate octakit request for existing issues in repository ${conf.ghRepo}, error: ${err.message}`, { cause: err }) } }, @@ -41,9 +40,8 @@ module.exports = { if (conf.dryRun) return try { return await this.client.issues.create(options) - } - catch (err) { - throw new Error(`Failed to ${options.issue_number?'update':'create'} issue: ${options.issue_number?options.issue_number:options.title}, error: ${err.message}`, { cause: err }) + } catch (err) { + throw new Error(`Failed to ${options.issue_number ? 'update' : 'create'} issue: ${options.issue_number ? options.issue_number : options.title}, error: ${err.message}`, { cause: err }) } }, diff --git a/lib/github/labels.js b/lib/github/labels.js index 3d0bf1e..c73564d 100644 --- a/lib/github/labels.js +++ b/lib/github/labels.js @@ -61,8 +61,7 @@ const ensureLabelsAreCreated = async (octokit, client, ghOwner, ghRepo, issues) }), (response) => response.data ) - } - catch (err) { + } catch (err) { throw new Error(`Failed to paginate octakit request for labels in repository ${ghRepo}, error: ${err.message}`, { cause: err }) } @@ -75,7 +74,7 @@ const ensureLabelsAreCreated = async (octokit, client, ghOwner, ghRepo, issues) await Promise.all( labelsToCreate.map((name) => { try { - client.issues + return client.issues .createLabel({ owner: ghOwner, repo: ghRepo, @@ -84,8 +83,7 @@ const ensureLabelsAreCreated = async (octokit, client, ghOwner, ghRepo, issues) .then(() => { console.log(`Created GitHub label: "${name}"`) }) - } - catch (err) { + } catch (err) { throw new Error(`Failed to create GitHub label '${name}', error: ${err.message}`, { cause: err }) } }) diff --git a/lib/snyk.js b/lib/snyk.js index 26fcd58..991467c 100644 --- a/lib/snyk.js +++ b/lib/snyk.js @@ -29,7 +29,7 @@ module.exports = class Snyk { ).orgs } - async queryOrgInfo(organizationId) { + async queryOrgInfo (organizationId) { try { const response = await request({ method: 'get', @@ -39,12 +39,11 @@ module.exports = class Snyk { }) if (response.data === undefined || response.data.attributes === undefined || response.data.attributes.name === undefined) { - throw new Error (`expected response to include data.attributes.name`) + throw new Error('expected response to include data.attributes.name') } return response.data - } - catch (err) { + } catch (err) { throw new Error(`Failed to query snyk organization with id ${organizationId}, error: ${err.message}`, { cause: err }) } } @@ -69,7 +68,7 @@ module.exports = class Snyk { isMonitored: project.attributes.status === 'active', issueCountTotal, - browseUrl: `https://app.snyk.io/org/${organization.attributes.name.toLowerCase()}/project/${project.id}`, + browseUrl: `https://app.snyk.io/org/${organization.attributes.name.toLowerCase()}/project/${project.id}` } }).filter(({ id, isMonitored }) => { if (selectedProjects.includes(id)) { @@ -122,7 +121,7 @@ function getSeverities (minimumSeverity) { return ['critical', 'high', 'medium', 'low'] } -async function paginateRestResponseData(url, headers, method = 'get') { +async function paginateRestResponseData (url, headers, method = 'get') { try { const reponseData = [] do { @@ -133,13 +132,12 @@ async function paginateRestResponseData(url, headers, method = 'get') { json: true }) reponseData.push(...response.data) - if (response.links.next) url = baseRestUrl + response.links.next / trimStart('/rest') + if (response.links.next) url = baseRestUrl + response.links.next.trimStart('/rest') else url = undefined } while (url) return reponseData - } - catch (err) { + } catch (err) { throw new Error(`Failed to paginate request for ${method} ${url}, error: ${err.message}`, { cause: err }) } }