Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
127 changes: 101 additions & 26 deletions packages/cli/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"author": "The Polymer Project Authors",
"license": "BSD-3-Clause",
"dependencies": {
"@octokit/rest": "^15.2.6",
"@types/chalk": "^0.4.31",
"@types/del": "^3.0.0",
"@types/findup-sync": "^0.3.29",
Expand Down Expand Up @@ -53,7 +54,6 @@
"command-line-usage": "^3.0.1",
"del": "^3.0.0",
"findup-sync": "^0.4.2",
"github": "^7.2.1",
"globby": "^8.0.1",
"gunzip-maybe": "^1.3.1",
"inquirer": "^1.0.2",
Expand Down
19 changes: 9 additions & 10 deletions packages/cli/src/github/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand All @@ -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',
Expand Down Expand Up @@ -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> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Switching from types to any is a pretty big regression. I'd rather not update the library if that's the primary change.

Copy link
Copy Markdown
Member Author

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 AnyResponse to a custom type where data is something that we've defined as not any?

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

// 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);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unfortunately, it seems like their index.d.ts no longer has types for responses.

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}.`);
Expand Down