Skip to content

Instantly share code, notes, and snippets.

@juandjara
Created August 12, 2017 12:25
Show Gist options
  • Save juandjara/ebd8c412c77fa20981548a9a62a4b68c to your computer and use it in GitHub Desktop.
Save juandjara/ebd8c412c77fa20981548a9a62a4b68c to your computer and use it in GitHub Desktop.
Delete last deploy from `now.js` for a given project so yo can replace it with a new one.
// this script requires a `.env` file with a `NOW_TOKEN` to work
// it also requires the npm packages `dotenv` and `axios`
require('dotenv').config()
const pkg = require('./package.json')
const axios = require('axios').create({
baseURL: "https://api.zeit.co/now",
headers: {
Authorization: `Bearer ${process.env.NOW_TOKEN}`
}
})
axios.get('/deployments')
.then(res => res.data)
.then(data => data.deployments.filter(d => d.name === pkg.name))
.then(botDeploys => botDeploys.slice(-1)[0])
.then(lastDeploy => axios.delete(`/deployments/${lastDeploy.uid}`))
.then(res => res.data)
.then(console.log)
.catch(err => console.error(err.response.data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment