@@ -26,8 +26,42 @@ import type {} from "@octokit/plugin-throttling/dist-types/types.d";
2626// To avoid that, we ensure to cap the message to 60k chars.
2727const MAX_CHARACTERS_PER_MESSAGE = 60000 ;
2828
29+ const setupOctokit = ( githubToken ) => {
30+ return new ( GitHub . plugin ( throttling ) ) (
31+ getOctokitOptions ( githubToken , {
32+ throttle : {
33+ onRateLimit : ( retryAfter , options : any , octokit , retryCount ) => {
34+ core . warning (
35+ `Request quota exhausted for request ${ options . method } ${ options . url } `
36+ ) ;
37+
38+ if ( retryCount <= 2 ) {
39+ core . info ( `Retrying after ${ retryAfter } seconds!` ) ;
40+ return true ;
41+ }
42+ } ,
43+ onSecondaryRateLimit : (
44+ retryAfter ,
45+ options : any ,
46+ octokit ,
47+ retryCount
48+ ) => {
49+ core . warning (
50+ `SecondaryRateLimit detected for request ${ options . method } ${ options . url } `
51+ ) ;
52+
53+ if ( retryCount <= 2 ) {
54+ core . info ( `Retrying after ${ retryAfter } seconds!` ) ;
55+ return true ;
56+ }
57+ } ,
58+ } ,
59+ } )
60+ ) ;
61+ } ;
62+
2963const createRelease = async (
30- octokit : ReturnType < typeof github . getOctokit > ,
64+ octokit : ReturnType < typeof GitHub > ,
3165 { pkg, tagName } : { pkg : Package ; tagName : string }
3266) => {
3367 try {
@@ -83,37 +117,7 @@ export async function runPublish({
83117 createGithubReleases,
84118 cwd = process . cwd ( ) ,
85119} : PublishOptions ) : Promise < PublishResult > {
86- const octokit = new ( GitHub . plugin ( throttling ) ) (
87- getOctokitOptions ( githubToken , {
88- throttle : {
89- onRateLimit : ( retryAfter , options : any , octokit , retryCount ) => {
90- core . warning (
91- `Request quota exhausted for request ${ options . method } ${ options . url } `
92- ) ;
93-
94- if ( retryCount <= 2 ) {
95- core . info ( `Retrying after ${ retryAfter } seconds!` ) ;
96- return true ;
97- }
98- } ,
99- onSecondaryRateLimit : (
100- retryAfter ,
101- options : any ,
102- octokit ,
103- retryCount
104- ) => {
105- core . warning (
106- `SecondaryRateLimit detected for request ${ options . method } ${ options . url } `
107- ) ;
108-
109- if ( retryCount <= 2 ) {
110- core . info ( `Retrying after ${ retryAfter } seconds!` ) ;
111- return true ;
112- }
113- } ,
114- } ,
115- } )
116- ) ;
120+ const octokit = setupOctokit ( githubToken ) ;
117121
118122 let [ publishCommand , ...publishArgs ] = script . split ( / \s + / ) ;
119123
@@ -302,10 +306,12 @@ export async function runVersion({
302306 hasPublishScript = false ,
303307 prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE ,
304308} : VersionOptions ) : Promise < RunVersionResult > {
309+ const octokit = setupOctokit ( githubToken ) ;
310+
305311 let repo = `${ github . context . repo . owner } /${ github . context . repo . repo } ` ;
306312 let branch = github . context . ref . replace ( "refs/heads/" , "" ) ;
307313 let versionBranch = `changeset-release/${ branch } ` ;
308- let octokit = github . getOctokit ( githubToken ) ;
314+
309315 let { preState } = await readChangesetState ( cwd ) ;
310316
311317 await gitUtils . switchToMaybeExistingBranch ( versionBranch ) ;
0 commit comments