-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
70 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Content in this folder is intended to be automatically sourced and used by builds on Netlify. | ||
|
||
The functions folder exists to host custom functions hosted by Netlify. Currently, the ones present are automatically | ||
triggered when one of Netlify's events match the name of the function file. | ||
See: https://docs.netlify.com/functions/trigger-on-events/ for more information. The purpose of these triggered events | ||
is to have a more accurate metric of when a build is actually complete, compared to Gatsby plugins' native setup. |
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,7 @@ | ||
import { callPostBuildWebhook } from '../../plugins/gatsby-source-snooty-preview/utils/post-build'; | ||
import { constructResPayload } from '../utils'; | ||
|
||
export async function handler(event, _context) { | ||
const resPayload = constructResPayload(event); | ||
await callPostBuildWebhook(resPayload, 'failed'); | ||
} |
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,7 @@ | ||
import { callPostBuildWebhook } from '../../plugins/gatsby-source-snooty-preview/utils/post-build'; | ||
import { constructResPayload } from '../utils'; | ||
|
||
export async function handler(event, _context) { | ||
const resPayload = constructResPayload(event); | ||
await callPostBuildWebhook(resPayload, 'completed'); | ||
} |
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,3 @@ | ||
[functions."deploy-*"] | ||
# build-hook.txt is a temporary file created at build time for Netlify builds | ||
included_files = ['build-hook.txt', 'plugins/gatsby-source-snooty-preview/utils/post-build.js', 'netlify/utils.js'] |
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,30 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
/** | ||
* Parses build hook data from the expected temporary location | ||
* @returns {object | undefined} | ||
*/ | ||
const parseBuildHookData = () => { | ||
// This file does not currently exist, but should be created on Netlify builds as part of `npm run build:netlify`. | ||
// The INCOMING_HOOK_BODY env var is not automatically passed along to functions, so we use a txt file to save it | ||
const relativeFilePath = '../build-hook.txt'; | ||
const buildHookDataString = fs.readFileSync(path.resolve(__dirname, relativeFilePath), 'utf-8'); | ||
if (!buildHookDataString) { | ||
console.log('No build hook data found.'); | ||
return; | ||
} | ||
return JSON.parse(buildHookDataString); | ||
}; | ||
|
||
export const constructResPayload = (event) => { | ||
const buildHookData = parseBuildHookData(); | ||
const parsedEventBody = JSON.parse(event.body); | ||
// This is Netlify's default post-deployment payload. We include it with our custom data in case | ||
// we want to process any information | ||
const netlifyPayload = parsedEventBody.payload; | ||
return { | ||
netlifyPayload, | ||
...buildHookData, | ||
}; | ||
}; |
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
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