@@ -26,8 +26,42 @@ import type {} from "@octokit/plugin-throttling/dist-types/types.d";
26
26
// To avoid that, we ensure to cap the message to 60k chars.
27
27
const MAX_CHARACTERS_PER_MESSAGE = 60000 ;
28
28
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
+
29
63
const createRelease = async (
30
- octokit : ReturnType < typeof github . getOctokit > ,
64
+ octokit : ReturnType < typeof GitHub > ,
31
65
{ pkg, tagName } : { pkg : Package ; tagName : string }
32
66
) => {
33
67
try {
@@ -83,37 +117,7 @@ export async function runPublish({
83
117
createGithubReleases,
84
118
cwd = process . cwd ( ) ,
85
119
} : 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 ) ;
117
121
118
122
let [ publishCommand , ...publishArgs ] = script . split ( / \s + / ) ;
119
123
@@ -302,10 +306,12 @@ export async function runVersion({
302
306
hasPublishScript = false ,
303
307
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE ,
304
308
} : VersionOptions ) : Promise < RunVersionResult > {
309
+ const octokit = setupOctokit ( githubToken ) ;
310
+
305
311
let repo = `${ github . context . repo . owner } /${ github . context . repo . repo } ` ;
306
312
let branch = github . context . ref . replace ( "refs/heads/" , "" ) ;
307
313
let versionBranch = `changeset-release/${ branch } ` ;
308
- let octokit = github . getOctokit ( githubToken ) ;
314
+
309
315
let { preState } = await readChangesetState ( cwd ) ;
310
316
311
317
await gitUtils . switchToMaybeExistingBranch ( versionBranch ) ;
0 commit comments