This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
feat: build trigger handler function #47
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
66b8b77
chore: add sample ENV
notrab f2957b0
feat: add es6-promise polyfill
notrab 1dddb15
feat: create build handler webhook
notrab 3701fff
feat: cancel any requests without a req body
notrab 850e4cc
update logo
notrab 843e4d9
fix: remove unncessary code
notrab d4b30b4
feat: update logo
notrab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require('dotenv').config(); | ||
|
||
require('es6-promise').polyfill(); | ||
require('isomorphic-fetch'); | ||
|
||
const BUILD_HOOK = process.env.BUILD_HOOK; | ||
const BUILD_STAGE_TRIGGER = process.env.STAGE_TRIGGER; | ||
|
||
const BUILD_TRIGGERS = [ | ||
'createProduct', | ||
'updateProduct', | ||
'deleteProduct', | ||
'createCategory', | ||
'updateCategory', | ||
'deleteCategory', | ||
'createCollection', | ||
'updateCollection', | ||
'deleteCollection', | ||
]; | ||
|
||
exports.handler = async event => { | ||
if (!event.body) | ||
return { | ||
statusCode: 405, | ||
message: 'You must provide a payload.', | ||
}; | ||
|
||
const { | ||
stageName, | ||
info: { fieldName }, | ||
} = JSON.parse(event.body); | ||
|
||
if (!req.body) | ||
return { | ||
statusCode: 422, | ||
body: JSON.stringify({ | ||
message: 'No action required.', | ||
}), | ||
}; | ||
|
||
try { | ||
if ( | ||
stageName === BUILD_STAGE_TRIGGER && | ||
BUILD_TRIGGERS.includes(fieldName) | ||
) { | ||
await fetch(BUILD_HOOK, { | ||
method: 'post', | ||
}); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
message: 'Build successfully triggered.', | ||
}), | ||
}; | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
message: 'No build required.', | ||
}), | ||
}; | ||
} catch (err) { | ||
console.log(err); | ||
|
||
return { | ||
statusCode: 500, | ||
body: JSON.stringify(err), | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is
req.body
defined? Left over copy/pasta?