-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Allow body for Webhooks #9309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow body for Webhooks #9309
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9309 +/- ##
===========================================
+ Coverage 35.07% 54.71% +19.64%
===========================================
Files 1308 135 -1173
Lines 14465 4386 -10079
Branches 1439 890 -549
===========================================
- Hits 5074 2400 -2674
+ Misses 8481 1564 -6917
+ Partials 910 422 -488
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
|
Never mind, I've located the problem. Will try to have this PR ready shortly. |
|
Hey @dblythy any news on this? |
All functional at this stage I’ve just gotta write some tests for the feature. Should be a wk or so |
|
@dblythy Do you want some assistance? I can try and jump in? |
That would be good if you wouldn’t mind. I’ll share my fork with you. |
waiting for strapi/strapi#9309 to create strapi -> github actions webhook
|
I really NEED this feature to trigger GitHub Actions workflows on a non-default branch! |
|
Hi @dblythy thank you for starting this PR. This feature will evolve in the upcoming features for sure. We have a lot of ideas around the webhooks. That being said this isn't a top high priority just yet :/ From what I can see in your PR you are adding some key values to the body statically. Something that we could allow to fit your usecase without creating conflicts with what we plan for the feature could be a programmatic way to extend the body rather than configuring things in the UI. What do you think ? |
|
@alexandrebodin Currently not being able to modify the content of the body is causing errors when trying to use webhooks with GitHub actions. We're required to pass data via the body such as: I can confirm that it also won't accept query parameters associated with the url and passing other variables in the header doesn't help the situation. The documentation for this can be found here https://docs.github.com/en/actions/reference/events-that-trigger-workflows I've found a working workaround here: https://www.npmjs.com/package/strapi-plugin-github-actions Though this is no ideal as we lose all of the 'automation' functionality such as being able to trigger workflows for publish, unpublish etc. We don't have a choice to move away from github actions, is it possible someone can look into this again? |
|
@LiamDotPro Thank you for the detailed response. As said in my comment would a programmatic API to extend the webhook format would work for you ? Some random example that comes to mind
webhooks: {
fromatRequest(req, info) {
if (info.webhook.url.includes('github.com')) {
return {
body: {
event_type: 'some_type',
...req.body
},
qs: {} // custom query string,
headers: {} // custom headers
}
}
}
}Would that work for you ? |
|
@alexalexandrebodin Yeah that looks spot on 👍🏻 |
|
We don't have this on the todo for a while but if someone wants to work on a PR for that it should be a pretty straight forward PR to work on :) |
|
@alexandrebodin I'll try and take a stab at it sometime this evening or weekend. |
|
@dblythy @iamcryptoki I just released this plugin which takes a different approach, it may be helpful to you. |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/webhook-doesnt-take-a-body/15425/2 |
@alexandrebodin what do you think about using event-hub directly? For example, I'm using the following code to trigger Github Actions when content is published: //src/index.ts
bootstrap({ strapi }: { strapi: Strapi }) {
const octokit = new Octokit({ auth: `TOKEN` });
const listener = strapi.eventHub.on("entry.publish", async () => {
try {
await octokit.request(
"POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
{
owner: "OWNER",
repo: "REPO",
workflow_id: "ID",
ref: "branch",
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
}
);
} catch (error) {
//add error handling
}
});
},Is that a valid workaround? |
|
What happened to this PR? I really need it to trigger rebuilds in DigitalOcean. |
|
TL;DR: Our solution is not ideal but you can use Strapi as a proxy server and pass body using a custom endpoint until setting request body is allowed by Strapi. Check out our step-by-step tutorial demonstrating a clean and practical integration approach. Full guide available here: https://uninterrupted.tech/blog/passing-body-data-in-strapi-webhooks-triggering-git-hub-workflows-example/ |
What does it do?
This PR adds options for body to webhooks.
However, i'm struggling to work out how to resolve this API error on creating the webhook:
I'm new to this project so any pointers would be appreciated.
I'm also not a react developer so code might need work.
Why is it needed?
I need this so I can build via GitHub actions.
Related issue(s)/PR(s)
Closes #7567
TODO: