1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/script/delete-unused-staging-apps.js
Jason Etcovitch 8d4f3e65fe Move test & script utils out of /lib (#17517)
* Remove an unused file

* Move authenticate-to-aws to scripts/utils

* Move crowdin-config to tests/utils

* Remove add-frontmatter-to-file

* Move find-unused-assets

* Move git-utils to script/utils

* Move lib/github to script/utils

* Revert "Remove an unused file"

This reverts commit cd93ad846a0354e957359f23124eb0724c9147cf.

* Move find-extraneous-translation-files to script/utils

* We already have tests/helpers

* Rename script/utils => helpers for consistency

* Forgot a path

* Fix path to crowdin-config

Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com>
2021-01-29 10:30:51 -05:00

58 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
// [start-readme]
//
// This script finds and lists all the Heroku staging apps and deletes any leftover apps that have closed PRs
//
// [end-readme]
require('dotenv').config()
const assert = require('assert')
assert(process.env.HEROKU_API_TOKEN)
const { chain } = require('lodash')
const chalk = require('chalk')
const Heroku = require('heroku-client')
const github = require('./helpers/github')()
const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN })
const owner = 'github'
const repo = 'docs-internal'
const stagingAppNamePrefix = 'docs-internal-pr-'
main()
async function main () {
const stagingApps = chain(await heroku.get('/apps'))
.filter(app => app.name.startsWith(stagingAppNamePrefix))
.map(app => {
app.pullRequestNumber = Number(app.name.match(/\d+$/)[0])
return app
})
.orderBy('name')
.value()
console.log('staging apps:', stagingApps.length)
for (const app of stagingApps) {
try {
const { data: pr } = await github.pulls.get({
owner,
repo,
pull_number: app.pullRequestNumber
})
if (pr.state === 'open') {
console.log(chalk.green(app.name))
} else if (pr.state === 'closed') {
console.log(chalk.red(app.name), '(PR was closed; deleting app now)')
await heroku.delete(`/apps/${app.name}`)
} else {
console.log(chalk.red(app.name), `(${pr.state})`)
}
} catch (err) {
console.log('no PR found', chalk.red(app.name))
console.log(err)
}
}
}