@@ -47,7 +47,6 @@ async function main() {
47
47
}
48
48
49
49
const prInfoMatch = / ^ (?: g h a - | g h d - ) ? (?< repo > d o c s (?: - i n t e r n a l ) ? ) - (?< pullNumber > \d + ) - - .* $ /
50
- const legacyPrInfoMatch = / ^ h e l p - d o c s - p r - (?< pullNumber > \d + ) $ /
51
50
52
51
let exceededLimit = false
53
52
let matchingCount = 0
@@ -62,16 +61,8 @@ async function main() {
62
61
const { data : environments } = response
63
62
64
63
const envsPlusPullIds = environments . map ( ( env ) => {
65
- let match = prInfoMatch . exec ( env . name )
66
- let { repo : repoName , pullNumber } = ( match || { } ) . groups || { }
67
-
68
- if ( ! match ) {
69
- match = legacyPrInfoMatch . exec ( env . name )
70
- if ( match ) {
71
- repoName = repo
72
- pullNumber = ( ( match || { } ) . groups || { } ) . pullNumber
73
- }
74
- }
64
+ const match = prInfoMatch . exec ( env . name )
65
+ const { repo : repoName , pullNumber } = ( match || { } ) . groups || { }
75
66
76
67
return {
77
68
env,
@@ -184,39 +175,45 @@ async function main() {
184
175
185
176
async function deleteEnvironment ( envName ) {
186
177
try {
187
- // Get the latest deployment environment to signal its deactivation
188
- const { data : deployments } = await octokit . repos . listDeployments ( {
178
+ let deploymentCount = 0
179
+
180
+ // Get all of the Deployments to signal this environment's complete deactivation
181
+ for await ( const response of octokit . paginate . iterator ( octokit . repos . listDeployments , {
189
182
owner,
190
183
repo,
191
184
192
185
// In the GitHub API, there can only be one active deployment per environment.
193
186
// For our many staging apps, we must use the unique appName as the environment.
194
187
environment : envName ,
195
- } )
196
-
197
- // Deactivate ALL of the deployments
198
- for ( const deployment of deployments ) {
199
- // Deactivate this Deployment with an 'inactive' DeploymentStatus
200
- await octokit . repos . createDeploymentStatus ( {
201
- owner,
202
- repo,
203
- deployment_id : deployment . id ,
204
- state : 'inactive' ,
205
- description : 'The app was undeployed' ,
206
- // The 'ant-man' preview is required for `state` values of 'inactive', as well as
207
- // the use of the `log_url`, `environment_url`, and `auto_inactive` parameters.
208
- // The 'flash' preview is required for `state` values of 'in_progress' and 'queued'.
209
- mediaType : {
210
- previews : [ 'ant-man' , 'flash' ] ,
211
- } ,
212
- } )
213
-
214
- // Delete this Deployment
215
- await octokit . repos . deleteDeployment ( {
216
- owner,
217
- repo,
218
- deployment_id : deployment . id ,
219
- } )
188
+ } ) ) {
189
+ const { data : deployments } = response
190
+
191
+ // Deactivate ALL of the deployments
192
+ for ( const deployment of deployments ) {
193
+ // Deactivate this Deployment with an 'inactive' DeploymentStatus
194
+ await octokit . repos . createDeploymentStatus ( {
195
+ owner,
196
+ repo,
197
+ deployment_id : deployment . id ,
198
+ state : 'inactive' ,
199
+ description : 'The app was undeployed' ,
200
+ // The 'ant-man' preview is required for `state` values of 'inactive', as well as
201
+ // the use of the `log_url`, `environment_url`, and `auto_inactive` parameters.
202
+ // The 'flash' preview is required for `state` values of 'in_progress' and 'queued'.
203
+ mediaType : {
204
+ previews : [ 'ant-man' , 'flash' ] ,
205
+ } ,
206
+ } )
207
+
208
+ // Delete this Deployment
209
+ await octokit . repos . deleteDeployment ( {
210
+ owner,
211
+ repo,
212
+ deployment_id : deployment . id ,
213
+ } )
214
+
215
+ deploymentCount ++
216
+ }
220
217
}
221
218
222
219
// Delete this Environment
@@ -232,7 +229,12 @@ async function main() {
232
229
}
233
230
}
234
231
235
- console . log ( '✅' , chalk . green ( `Removed stale deployment environment "${ envName } "` ) )
232
+ console . log (
233
+ '✅' ,
234
+ chalk . green (
235
+ `Removed stale deployment environment "${ envName } " (${ deploymentCount } deployments)`
236
+ )
237
+ )
236
238
} catch ( error ) {
237
239
console . log (
238
240
'❌' ,
0 commit comments