-
Notifications
You must be signed in to change notification settings - Fork 6
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 'ensureLabelsAreCreated' by paginating API results #26
Fixes 'ensureLabelsAreCreated' by paginating API results #26
Conversation
… api with new rest api.
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@elastic/snyk-github-issue-creator", | |||
"version": "2.1.1", | |||
"version": "2.1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@watson Is there anything else I need to do to support rolling out a new version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version number should be updated independently of the changes in a PR. So just revert any changes to this file in this PR. To prepare and publish a new version, do the following after this PR is merged:
# ensure you have the latest main checked out locally
git pull upstream main
# bump the patch version in package.json and create version commit + tag
npm version patch
# ensure the patch commit is pushed upstream
git push upstream main
# ensure the version tag is pushed upstream
git push upstream --tags
# publish the new version to npm
npm publish
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@elastic/snyk-github-issue-creator", | |||
"version": "2.1.1", | |||
"version": "2.1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version number should be updated independently of the changes in a PR. So just revert any changes to this file in this PR. To prepare and publish a new version, do the following after this PR is merged:
# ensure you have the latest main checked out locally
git pull upstream main
# bump the patch version in package.json and create version commit + tag
npm version patch
# ensure the patch commit is pushed upstream
git push upstream main
# ensure the version tag is pushed upstream
git push upstream --tags
# publish the new version to npm
npm publish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't reviewed the code changes - just the package.json updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just found a single unused variable after the refactoring. Other than that it looks good 👍
lib/github/labels.js
Outdated
const response = await octokit.paginate( | ||
await client.issues.listLabelsForRepo({ | ||
owner: ghOwner, | ||
repo: ghRepo, | ||
per_page: 100 | ||
}) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this way of passing the response as an argument to octokit.paginate
in their docs 🤔 https://octokit.github.io/rest.js/v20#pagination
But I assume you tested it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works! However, I have updated the code to be more explicit in this case.
const responseData = await octokit.paginate(
await client.issues.listLabelsForRepo({
owner: ghOwner,
repo: ghRepo,
per_page: 100
}),
(response) => response.data
)
lib/snyk.js
Outdated
const baseUrl = 'https://snyk.io/api/v1' | ||
const baseRestUrl = 'https://api.snyk.io' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, the old const
isn't used anymore? Why not simply change its value to the new host?
const baseUrl = 'https://snyk.io/api/v1' | |
const baseRestUrl = 'https://api.snyk.io' | |
const baseUrl = 'https://api.snyk.io' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all v1 APIs are deprecated. It's still used in the issues
and orgs
functions. I will rename the const though, since we have 2 base paths now.
We have > 100 labels in the security repo, and we were not paginating the call to retrieve them. Previously, this was working because the labels we wanted to apply to an issue (typically
Kibana
,snyk
, andtriage_needed
) were within the first 100 results, but as new labels were created, some of the labels are now in the second page of results (specifically "triage_needed"). This causedensureLabelsAreCreated
to throw when attempting to create an existing label.This PR adds pagination of the
listLabelsForRepo
API call.Additionally, this PR replaces the deprecated snyk List all projects v1 API with the newer REST API. The v1 API EOL is December 22, 2023. See the official statement for more information.