Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

delete-unused-staging-apps.js 1.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  1. #!/usr/bin/env node
  2. // [start-readme]
  3. //
  4. // This script finds and lists all the Heroku staging apps and deletes any leftover apps that have closed PRs
  5. //
  6. // [end-readme]
  7. require('dotenv').config()
  8. const assert = require('assert')
  9. assert(process.env.HEROKU_API_TOKEN)
  10. const { chain } = require('lodash')
  11. const chalk = require('chalk')
  12. const Heroku = require('heroku-client')
  13. const github = require('./helpers/github')()
  14. const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN })
  15. const owner = 'github'
  16. const repo = 'docs-internal'
  17. const stagingAppNamePrefix = 'docs-internal-pr-'
  18. main()
  19. async function main () {
  20. const stagingApps = chain(await heroku.get('/apps'))
  21. .filter(app => app.name.startsWith(stagingAppNamePrefix))
  22. .map(app => {
  23. app.pullRequestNumber = Number(app.name.match(/\d+$/)[0])
  24. return app
  25. })
  26. .orderBy('name')
  27. .value()
  28. console.log('staging apps:', stagingApps.length)
  29. for (const app of stagingApps) {
  30. try {
  31. const { data: pr } = await github.pulls.get({
  32. owner,
  33. repo,
  34. pull_number: app.pullRequestNumber
  35. })
  36. if (pr.state === 'open') {
  37. console.log(chalk.green(app.name))
  38. } else if (pr.state === 'closed') {
  39. console.log(chalk.red(app.name), '(PR was closed; deleting app now)')
  40. await heroku.delete(`/apps/${app.name}`)
  41. } else {
  42. console.log(chalk.red(app.name), `(${pr.state})`)
  43. }
  44. } catch (err) {
  45. console.log('no PR found', chalk.red(app.name))
  46. console.log(err)
  47. }
  48. }
  49. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...