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

Commit

Permalink
fix: programmatically setting the status of the drone builds (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
planctus committed Dec 23, 2019
1 parent f921cda commit d40a55e
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions scripts/set-netlify-deployment-status.js
Expand Up @@ -10,6 +10,7 @@ const run = async () => {
DRONE_COMMIT_SHA,
DRONE_COMMIT_BRANCH,
DRONE_BUILD_LINK,
DRONE_BUILD_STATUS,
} = process.env;

if (!GH_TOKEN) {
Expand All @@ -18,14 +19,14 @@ const run = async () => {
return;
}

if (!DRONE_REPO || !DRONE_COMMIT_SHA) {
if (!DRONE_REPO || !DRONE_COMMIT_SHA || !DRONE_BUILD_STATUS) {
console.info(
'Current script depends on Drone CI 0.8 environment variables.'
);
console.info(
'Please see https://0-8-0.docs.drone.io/environment-reference'
);
console.log('Required: DRONE_REPO, DRONE_COMMIT_SHA');
console.log('Required: DRONE_REPO, DRONE_COMMIT_SHA, DRONE_BUILD_STATUS');
return;
}

Expand All @@ -46,12 +47,19 @@ const run = async () => {
context: 'drone/netlify',
};
} else {
payload = {
payloadNetlify = {
state: 'success',
target_url: deploymentResult.deploy_url,
description: 'Preview ready!',
context: 'drone/netlify',
};

payloadDrone = {
state: DRONE_BUILD_STATUS,
target_url: DRONE_BUILD_LINK,
description: 'Build completed!',
context: 'continuous-integration/drone/push',
};
}
} catch (error) {
payload = {
Expand All @@ -73,9 +81,28 @@ const run = async () => {
'Content-Type': 'application/json',
Authorization: `Bearer ${GH_TOKEN}`,
},
body: JSON.stringify(payload),
body: JSON.stringify(payloadNetlify),
}
);

console.log('Status check for the netlify preview successfully updated!');

if (payloadDrone) {
await fetch(
`https://api.github.com/repos/${DRONE_REPO}/statuses/${DRONE_COMMIT_SHA}`,
{
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-Charset': 'utf-8',
'Content-Type': 'application/json',
Authorization: `Bearer ${GH_TOKEN}`,
},
body: JSON.stringify(payloadDrone),
}
);
console.log('Status check for the drone build successfully updated with status:' + DRONE_BUILD_STATUS);
}
};

try {
Expand Down

0 comments on commit d40a55e

Please sign in to comment.