-
Notifications
You must be signed in to change notification settings - Fork 199
Updates CLI to use '@octokit/rest' instead of 'github'. #154
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
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7ef3fcb
Update 'github' dependency to '@octokit/rest'.
bicknellr 47b073a
Merge remote-tracking branch 'origin/master' into octokit
bicknellr 0d090ca
Throw if the response status is not '200 OK'.
bicknellr 09a0871
Merge remote-tracking branch 'origin/master' into octokit
bicknellr 7526dfd
Merge remote-tracking branch 'origin/master' into octokit
bicknellr bfdd059
Update tests with new response format. Add a test for non-'200 OK' re…
bicknellr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ import * as semver from 'semver'; | |
|
|
||
| import request = require('request'); | ||
| import rimraf = require('rimraf'); | ||
| import GitHubApi = require('github'); | ||
| import Octokit = require('@octokit/rest'); | ||
|
|
||
| const gunzip = require('gunzip-maybe'); | ||
| const tar = require('tar-fs'); | ||
|
|
@@ -52,14 +52,14 @@ export interface GithubOpts { | |
| owner: string; | ||
| repo: string; | ||
| githubToken?: string; | ||
| githubApi?: GitHubApi; | ||
| githubApi?: Octokit; | ||
| requestApi?: request | ||
| .RequestAPI<request.Request, request.CoreOptions, request.RequiredUriUrl>; | ||
| } | ||
|
|
||
| export class Github { | ||
| private _token: string|null; | ||
| private _github: GitHubApi; | ||
| private _github: Octokit; | ||
| private _request: request | ||
| .RequestAPI<request.Request, request.CoreOptions, request.RequiredUriUrl>; | ||
| private _owner: string; | ||
|
|
@@ -77,9 +77,7 @@ export class Github { | |
| this._token = opts.githubToken || Github.tokenFromFile('token'); | ||
| this._owner = opts.owner; | ||
| this._repo = opts.repo; | ||
| this._github = opts.githubApi || new GitHubApi({ | ||
| protocol: 'https', | ||
| }); | ||
| this._github = opts.githubApi || new Octokit(); | ||
| if (this._token != null) { | ||
| this._github.authenticate({ | ||
| type: 'oauth', | ||
|
|
@@ -156,21 +154,22 @@ export class Github { | |
| * Get all Github releases and match their tag names against the given semver | ||
| * range. Return the release with the latest possible match. | ||
| */ | ||
| async getSemverRelease(semverRange: string): Promise<GitHubApi.Release> { | ||
| async getSemverRelease(semverRange: string): Promise<any> { | ||
| // Note that we only see the 100 most recent releases. If we ever release | ||
| // enough versions that this becomes a concern, we'll need to improve this | ||
| // call to request multiple pages of results. | ||
| const releases: GitHubApi.Release[] = await this._github.repos.getReleases({ | ||
| const response: Octokit.AnyResponse = await this._github.repos.getReleases({ | ||
| owner: this._owner, | ||
| repo: this._repo, | ||
| per_page: 100, | ||
| }); | ||
| const releases = response.data; | ||
| const validReleaseVersions = | ||
| releases.filter((r) => semver.valid(r.tag_name)).map((r) => r.tag_name); | ||
| releases.filter((r: any) => semver.valid(r.tag_name)).map((r: any) => r.tag_name); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, it seems like their |
||
| const maxSatisfyingReleaseVersion = | ||
| semver.maxSatisfying(validReleaseVersions, semverRange); | ||
| const maxSatisfyingRelease = | ||
| releases.find((r) => r.tag_name === maxSatisfyingReleaseVersion); | ||
| releases.find((r: any) => r.tag_name === maxSatisfyingReleaseVersion); | ||
| if (!maxSatisfyingRelease) { | ||
| throw new Error(`${this._owner}/${this._repo} has no releases matching ${ | ||
| semverRange}.`); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Switching from types to
anyis a pretty big regression. I'd rather not update the library if that's the primary change.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.
What would you say to manually adding types here, casting the
AnyResponseto a custom type wheredatais something that we've defined as notany?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.
If there's an expectation that the newer version of the library is better then I'm on board
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 think this is blocked on https://github.com/octokit/rest.js/pull/732