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

Commit

Permalink
fix: immediately send response
Browse files Browse the repository at this point in the history
  • Loading branch information
feerglas committed Jul 30, 2021
1 parent a7b0261 commit b29dad3
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const isValidSemanticCommit = (commit) => {
});
};

const triggerTravisJob = (commit, response) => {
const triggerTravisJob = (commit) => {

console.log('FIGMA-LISTENER: -->> Will trigger travis job for icons');
const travisUrl = 'https://api.travis-ci.com/repo/lyne-design-system%2Flyne-icons/requests';
Expand All @@ -58,17 +58,14 @@ const triggerTravisJob = (commit, response) => {
travisUrl
})
.then(() => {
// Figma needs status code 200 as answer
response.sendStatus(200);
console.log('FIGMA-LISTENER: -->> Successfully triggered Travis Job');
})
.catch(() => {
console.log('FIGMA-LISTENER: -->> Error in Triggering Travis');
response.sendStatus(400);
});
} else {
console.log('FIGMA-LISTENER: -->> Is not a valid commit:');
console.log(commit);
response.sendStatus(400);
}
})
.catch((error) => {
Expand All @@ -85,7 +82,6 @@ const triggerTravisJob = (commit, response) => {

let pendingTimeout = false;
let pendingCommitMessage = '';
let pendingResponse = false;
const pendingDuration = 15 * 1000;

const triggerTravisJobDelayed = (commit, response) => {
Expand All @@ -94,19 +90,15 @@ const triggerTravisJobDelayed = (commit, response) => {
clearTimeout(pendingTimeout);
}

if (pendingResponse) {
pendingResponse.sendStatus(200);
}

pendingResponse = response;
response.sendStatus(200);

if (commit.length > 0) {
pendingCommitMessage = commit;
}

pendingTimeout = setTimeout(() => {
console.log(`FIGMA-LISTENER: -->> Webhook from Figma received. Waiting for ${pendingDuration} to see if another request comes in.`);
triggerTravisJob(pendingCommitMessage, pendingResponse);
triggerTravisJob(pendingCommitMessage);

pendingTimeout = false;
pendingCommitMessage = '';
Expand Down

0 comments on commit b29dad3

Please sign in to comment.