Skip to content
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

Fixes issue description and octokit pagination #28

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Uses v1 single project API to retrieve browseUrl and imageTag. Remove…
…s previous queryOrganization funtion.
  • Loading branch information
jeramysoucy committed Dec 27, 2023
commit c250e2868253bcbdf79829670bd3b0459c5b7f04
4 changes: 2 additions & 2 deletions lib/github/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module.exports = async (issues) => {
const headerText = 'This issue has been created automatically by [snyk-github-issue-creator](https://github.com/elastic/snyk-github-issue-creator).\r\n\r\nSnyk project(s):'
const projectText = projects
.map(
({ name, browseUrl }) =>
`\r\n * [\`${name}\`](${browseUrl})`
({ name, browseUrl, imageTag }) =>
`\r\n * [\`${name}\`](${browseUrl}) (manifest version ${imageTag})`
)
.join('')
const sectionText = Object.keys(sevMap)
Expand Down
49 changes: 24 additions & 25 deletions lib/snyk.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,47 @@ module.exports = class Snyk {
).orgs
}

async queryOrgInfo (organizationId) {
async queryProjectDetails (organizationId, projectId) {
try {
const response = await request({
return await request({
method: 'get',
url: `${baseRestUrl}/orgs/${organizationId}?version=2023-11-27`,
url: `${baseV1Url}/org/${organizationId}/project/${projectId}`, // project snapshot via v1 POST org/:orgId/project/:projectId/history
headers: this._headers,
json: true
})

if (response.data === undefined || response.data.attributes === undefined || response.data.attributes.name === undefined) {
throw new Error('expected response to include data.attributes.name')
}

return response.data
} catch (err) {
throw new Error(dressError(err, `Failed to query snyk organization with id ${organizationId}`))
throw new Error(dressError(err, `Failed to query snyk project details. Organization ID: ${organizationId}, Project ID: ${projectId}`))
}
}

async projects (orgId, selectedProjects = []) {
const organizationId = orgId || this._orgId

const organization = await this.queryOrgInfo(organizationId)

const responseData = await paginateRestResponseData(
`${baseRestUrl}/orgs/${organizationId}/projects?version=2023-11-27&meta.latest_issue_counts=true&limit=20`,
this._headers
)

return responseData.map((project) => {
const { critical, high, medium, low } = project.meta.latest_issue_counts
const issueCountTotal = critical + high + medium + low

return {
id: project.id,
name: project.attributes.name,
isMonitored:
project.attributes.status === 'active',
issueCountTotal,
browseUrl: `https://app.snyk.io/org/${organization.attributes.name.toLowerCase()}/project/${project.id}`
}
}).filter(({ id, isMonitored }) => {
const projects = await Promise.all(
responseData.map(async (project) => {
const { critical, high, medium, low } = project.meta.latest_issue_counts
const issueCountTotal = critical + high + medium + low

const projectDetails = await this.queryProjectDetails(organizationId, project.id)

return {
id: project.id,
name: project.attributes.name,
isMonitored:
project.attributes.status === 'active',
issueCountTotal,
browseUrl: projectDetails.browseUrl,
imageTag: projectDetails.imageTag
}
})
)

return projects.filter(({ id, isMonitored }) => {
if (selectedProjects.includes(id)) {
return true
}
Expand Down
Loading