Skip to content

Commit

Permalink
chore: upgrade octokit dependencies
Browse files Browse the repository at this point in the history
The main goal here is to upgrade `@octokit/plugin-throttling` to `5`, so that the secondary rate limit wait time is increased, wich hopefully fixes intuit#2458. This required other dependencies to be upgraded. The `resolutions` for `@octokit/plugin-rest-endpoint-methods` is necessary, because without it it pulls in `10.0.0` of `@octokit/types` which isn't compatible with the other libraries.
  • Loading branch information
restfulhead committed May 2, 2024
1 parent 335fadb commit 903f5a9
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 399 deletions.
14 changes: 9 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
"dependencies": {
"@auto-it/bot-list": "link:../../packages/bot-list",
"@endemolshinegroup/cosmiconfig-typescript-loader": "^3.0.2",
"@octokit/core": "^3.5.1",
"@octokit/plugin-enterprise-compatibility": "1.3.0",
"@octokit/plugin-retry": "^3.0.9",
"@octokit/plugin-throttling": "^3.6.2",
"@octokit/rest": "^18.12.0",
"@octokit/core": "^4.0.0",
"@octokit/plugin-enterprise-compatibility": "^2.0.5",
"@octokit/plugin-retry": "^4.1.6",
"@octokit/plugin-throttling": "^5.2.3",
"@octokit/plugin-rest-endpoint-methods": "~7.1.3",
"@octokit/rest": "^19.0.13",
"await-to-js": "^3.0.0",
"chalk": "^4.0.0",
"cosmiconfig": "7.0.0",
Expand Down Expand Up @@ -99,5 +100,8 @@
"@types/tinycolor2": "^1.4.1",
"@types/url-join": "^4.0.0",
"graphql": "^15.0.0"
},
"resolutions": {
"@octokit/plugin-rest-endpoint-methods": "7.1.3"
}
}
58 changes: 31 additions & 27 deletions packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export default class Git {
request: { agent: this.options.agent },
throttle: {
/** Add a wait once rate limit is hit */
onRateLimit: (retryAfter: number, opts: ThrottleOpts) => {
onRateLimit: (retryAfter: number, options: unknown) => {
const opts = options as ThrottleOpts;
this.logger.log.warn(
`Request quota exhausted for request ${opts.method} ${opts.url}`
);
Expand All @@ -153,7 +154,8 @@ export default class Git {
}
},
/** wait after abuse */
onAbuseLimit: (retryAfter: number, opts: ThrottleOpts) => {
onAbuseLimit: (retryAfter: number, options: unknown) => {
const opts = options as ThrottleOpts;
this.logger.log.error(
`Went over abuse rate limit ${opts.method} ${
opts.url
Expand Down Expand Up @@ -204,7 +206,8 @@ export default class Git {
this.logger.verbose.info("Got latest release:\n", latestRelease);

return latestRelease.tag_name;
} catch (e) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
if (e.status === 404) {
this.logger.verbose.info(
"Couldn't find latest release on GitHub, using first commit."
Expand Down Expand Up @@ -278,14 +281,14 @@ export default class Git {
this.logger.verbose.info("Found labels on PR:\n", labels.data);

return labels.data.map((l) => l.name);
} catch (e) {
throw new GitAPIError("listLabelsOnIssue", args, e);
} catch (e: unknown) {
throw new GitAPIError("listLabelsOnIssue", args, e as Error);
}
}

/** Get all the information about a PR or issue */
@memoize()
async getPr(prNumber: number) {
async getPr(prNumber: number): Promise<RestEndpointMethodTypes["issues"]["get"]["response"]> {
this.logger.verbose.info(`Getting info for PR: ${prNumber}`);

const args: RestEndpointMethodTypes["issues"]["get"]["parameters"] = {
Expand All @@ -300,14 +303,14 @@ export default class Git {
const info = await this.github.issues.get(args);
this.logger.veryVerbose.info('Got response for "issues.get":\n', info);
return info;
} catch (e) {
throw new GitAPIError("getPr", args, e);
} catch (e: unknown) {
throw new GitAPIError("getPr", args, e as Error);
}
}

/** Get information about specific commit */
@memoize()
async getCommit(sha: string) {
async getCommit(sha: string): Promise<RestEndpointMethodTypes["repos"]["getCommit"]["response"]> {
this.logger.verbose.info(`Getting info for commit: ${sha}`);

try {
Expand All @@ -321,8 +324,8 @@ export default class Git {
info
);
return info;
} catch (e) {
throw new GitAPIError("getCommit", [], e);
} catch (e: unknown) {
throw new GitAPIError("getCommit", [], e as Error);
}
}

Expand All @@ -338,20 +341,20 @@ export default class Git {
};

try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const labels = await this.github.paginate(
this.github.issues.listLabelsForRepo,
args
);

this.logger.veryVerbose.info(
'Got response for "getProjectLabels":\n',
labels
);
this.logger.verbose.info("Found labels on project:\n", labels);

return labels.map((l) => l.name);
} catch (e) {
throw new GitAPIError("getProjectLabels", args, e);
} catch (e: unknown) {
throw new GitAPIError("getProjectLabels", args, e as Error);
}
}

Expand Down Expand Up @@ -402,7 +405,8 @@ export default class Git {

return all;
}, []);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.log(error);
const tag = error.match(/ambiguous argument '(\S+)\.\.\S+'/);

Expand Down Expand Up @@ -493,7 +497,7 @@ export default class Git {

/** Get all the information about a PR or issue */
@memoize()
async getPullRequest(pr: number) {
async getPullRequest(pr: number): Promise<RestEndpointMethodTypes["pulls"]["get"]["response"]> {
this.logger.verbose.info(`Getting Pull Request: ${pr}`);

const args: RestEndpointMethodTypes["pulls"]["get"]["parameters"] = {
Expand Down Expand Up @@ -548,7 +552,7 @@ export default class Git {
}

/** Create a status (or checkmark) on a commit */
async createStatus(prInfo: IPRInfo) {
async createStatus(prInfo: IPRInfo): Promise<RestEndpointMethodTypes["repos"]["createCommitStatus"]["response"]> {
const args = {
...prInfo,
owner: this.options.owner,
Expand All @@ -568,7 +572,7 @@ export default class Git {
}

/** Add a label to the project */
async createLabel(label: ILabelDefinition) {
async createLabel(label: ILabelDefinition): Promise<RestEndpointMethodTypes["issues"]["createLabel"]["response"]> {
this.logger.verbose.info(
`Creating "${label.releaseType || "general"}" label :\n${label.name}`
);
Expand All @@ -591,7 +595,7 @@ export default class Git {
}

/** Update a label on the project */
async updateLabel(label: ILabelDefinition) {
async updateLabel(label: ILabelDefinition): Promise<RestEndpointMethodTypes["issues"]["updateLabel"]["response"]> {
this.logger.verbose.info(
`Updating "${label.releaseType || "generic"}" label :\n${label.name}`
);
Expand All @@ -615,7 +619,7 @@ export default class Git {
}

/** Add a label to and issue or pull request */
async addLabelToPr(pr: number, label: string) {
async addLabelToPr(pr: number, label: string): Promise<RestEndpointMethodTypes["issues"]["addLabels"]["response"]> {
this.logger.verbose.info(`Creating "${label}" label to PR ${pr}`);

const result = await this.github.issues.addLabels({
Expand All @@ -632,7 +636,7 @@ export default class Git {
}

/** Add a label to and issue or pull request */
async removeLabel(pr: number, label: string) {
async removeLabel(pr: number, label: string): Promise<RestEndpointMethodTypes["issues"]["removeLabel"]["response"]> {
this.logger.verbose.info(`Removing "${label}" from #${pr}`);

const result = await this.github.issues.removeLabel({
Expand All @@ -649,7 +653,7 @@ export default class Git {
}

/** Lock an issue */
async lockIssue(issue: number) {
async lockIssue(issue: number): Promise<RestEndpointMethodTypes["issues"]["lock"]["response"]> {
this.logger.verbose.info(`Locking #${issue} issue...`);

const result = await this.github.issues.lock({
Expand Down Expand Up @@ -763,7 +767,7 @@ export default class Git {
}

/** Create a comment on an issue or pull request */
async createComment(message: string, pr: number, context = "default") {
async createComment(message: string, pr: number, context = "default"): Promise<RestEndpointMethodTypes["issues"]["createComment"]["response"]> {
const commentIdentifier = makeCommentIdentifier(context);

this.logger.verbose.info("Using comment identifier:", commentIdentifier);
Expand All @@ -786,7 +790,7 @@ export default class Git {
}

/** Edit a comment on an issue or pull request */
async editComment(message: string, pr: number, context = "default") {
async editComment(message: string, pr: number, context = "default"): Promise<RestEndpointMethodTypes["issues"]["updateComment"]["response"] | RestEndpointMethodTypes["issues"]["createComment"]["response"]> {
const commentIdentifier = makeCommentIdentifier(context);

this.logger.verbose.info("Using comment identifier:", commentIdentifier);
Expand All @@ -810,7 +814,7 @@ export default class Git {
}

/** Create a comment on a pull request body */
async addToPrBody(message: string, pr: number, context = "default") {
async addToPrBody(message: string, pr: number, context = "default"): Promise<RestEndpointMethodTypes["issues"]["update"]["response"]> {
const id = makePrBodyIdentifier(context);

this.logger.verbose.info("Using PR body identifier:", id);
Expand Down Expand Up @@ -858,7 +862,7 @@ export default class Git {
prerelease = false,
fallbackCommit?: string,
latestRelease = false
) {
): Promise<RestEndpointMethodTypes["repos"]["createRelease"]["response"]> {
this.logger.verbose.info("Creating release on GitHub for tag:", tag);

const result = await this.github.repos.createRelease({
Expand All @@ -869,7 +873,7 @@ export default class Git {
name: tag,
body: releaseNotes,
prerelease,
make_latest: `${latestRelease}`,
make_latest: `${latestRelease}` as 'true' | 'false',
});

this.logger.veryVerbose.info("Got response from createRelease\n", result);
Expand Down
Loading

0 comments on commit 903f5a9

Please sign in to comment.