Overview
I investigated how to send notifications to GitHub when a Google Spreadsheet is updated using Google Apps Script. I also looked into how to send notifications from Strapi and Contentful to GitHub, so I am recording this as a reference.
Google Apps Script
By preparing a script like the following, I was able to send spreadsheet update notifications to GitHub.
const token = "ghp_xxx"
const owner = "yyy"
const repo = "zzz"
const event_type = "aaa"
function postSheetChange() {
const headers = {
"Accept": "application/vnd.github+json",
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
}
var payload = JSON.stringify({
event_type
});
var requestOptions = {
method: 'POST',
headers,
payload,
};
UrlFetchApp.fetch(`https://api.github.com/repos/${owner}/${repo}/dispatches`, requestOptions)
}
The following article was helpful for setting up triggers.
https://businesschatmaster.com/slack/spreadsheet-change-notification
Note that since notifications are sent to GitHub every time the Google Spreadsheet is updated, it is advisable to set up concurrency in GitHub Actions as shown below.
Alternatively, you could configure the trigger to fire only when specific cells (columns) are updated.
name: Build Test
concurrency:
cancel-in-progress: true
on:
repository_dispatch:
types:
- update_content
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
...
Strapi
With Strapi webhooks, the body cannot be customized, so it appears that a proxy server like the following is needed.
https://github.com/badsyntax/strapi-webhook-actions-proxy
Contentful
Using webhooks with Contentful was straightforward. The following article was helpful.
https://qiita.com/akitkat/items/3adcbafc4eeabaa6470b
Summary
I hope this serves as a helpful reference for using webhooks with headless CMS platforms.