Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Update awaiting build as a helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
rihardsgravis committed Sep 18, 2020
1 parent b3be9f2 commit ec5b21c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const axios = require("axios")
const sleep = (seconds) =>
new Promise((resolve) => setTimeout(resolve, seconds * 1000))

const awaitBuild = (data) => {
const awaitBuild = core.getInput("await-build")

if (awaitBuild && data.deployments[0].state !== "READY") {
throw Error("Deployment not yet ready")
}
}

const headers = {
headers: {
Authorization: `Bearer ${core.getInput("token")}`,
Expand All @@ -20,11 +28,7 @@ async function getProdUrl(sha) {
throw new Error("Commit sha for prod url didn't match")
}

const awaitBuild = core.getInput("await-build")

if (awaitBuild && data.deployments[0].state !== "READY") {
throw Error("Deployment not yet ready")
}
awaitBuild(data)

return data.url
}
Expand All @@ -34,11 +38,7 @@ async function getBranchUrl(sha) {
const url = `https://api.vercel.com/v5/now/deployments?${teamId ? `teamId=${teamId}&` : ""}meta-githubCommitSha=${sha}`
const { data } = await axios.get(url, headers)

const awaitBuild = core.getInput("await-build")

if(awaitBuild && data.deployments[0].state !== "READY"){
throw Error("Deployment not yet ready")
}
awaitBuild(data)

// If the deployment isn't in the response, this will throw an error and
// cause a retry.
Expand Down

0 comments on commit ec5b21c

Please sign in to comment.