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

Conversation

jeramysoucy
Copy link
Contributor

@jeramysoucy jeramysoucy commented Dec 27, 2023

Closes #27
Closes #29

Summary

This PR resolves the issue of undefined project links manifest version (see #27), as well as the issue where octokit pagination with API calls caused improper headers in low-level fetch in node >= 18 (see #29)

Details

Undefined Values

The project links were derived from the response of the deprecated v1 all projects API - each project body contained a browseUrl property. According to the API migration documentation it:

can be constructed using organization ID and project ID https://app.snyk.io/org/:orgId/project/:projectId

But this is inaccurate. The URL can be constructed from the organization name in lower-case and the project ID as such: https://app.snyk.io/org/[org name]/project/[projectId]

The manifest version used to be populated from the imageTag property return from the deprecated v1 all projects API. The API migration documentation claims that it:

Can be fetched from the latest project snapshot via v1 POST org/:orgId/project/:projectId/history

But I found that this did not work. Example for several projects:

*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: 20.10.0-slim
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: 20.10.0-slim
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: nonroot
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: undefined
*** PROJECT IMAGE TAG: undefined

Originally, I removed the manifest version from the output issue description, as it is not included in our other issue-generation automations. However, I found that I could still properly query for imageTag with the non-deprecated v1 single project API. As this API also returns the browseUrl property, it is not necessary to query for the organization name and manually construct the URL.

Fetch Header Issue

This PR fixes the fetch header issue by replacing the octokit API call within the octokit pagination call for querying issue labels with a raw request URL. This seems to resolve this issue and executes correctly in node 16, 18, and 20.

Additional

Lastly, error reporting around requests has been improved throughout the codebase. Previously, only low-level exceptions were being displayed if something went wrong, which did not include a path or reference back to which high-level operation caused the error. Error reports will now include a better description, along with a response status code and response details if available.


const baseV1Url = 'https://snyk.io/api/v1'
const baseRestUrl = 'https://api.snyk.io'
const baseRestUrl = 'https://api.snyk.io/rest'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to include the full base here and just remove the '/rest' in the one place where it is redundant.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeramysoucy I think this is now introducing this when used Error: Failed to paginate request for get https://api.snyk.io/rest/rest/orgs/, notice the double /rest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related issue: #30

@jeramysoucy jeramysoucy marked this pull request as ready for review December 27, 2023 19:35
@jeramysoucy jeramysoucy requested a review from a team December 27, 2023 19:36
@jeramysoucy jeramysoucy changed the title Fixes issue description and improves error reporting Fixes issue description and octokit pagination Dec 27, 2023
Copy link

@kc13greiner kc13greiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Changes LGTM!

++ descriptive errors!

@jeramysoucy jeramysoucy merged commit ad3e2b6 into elastic:main Dec 28, 2023
5 checks passed
@jeramysoucy jeramysoucy self-assigned this Dec 28, 2023
@watson watson mentioned this pull request Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants