Skip to content

Commit 41752cd

Browse files
authored
Webhook features and documentation (#1596)
Signed-off-by: tdruez <[email protected]>
1 parent 0d683a0 commit 41752cd

40 files changed

+1243
-269
lines changed

CHANGELOG.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
Changelog
22
=========
33

4+
v34.9.6 (unreleased)
5+
--------------------
6+
7+
- Refine and document the Webhook system
8+
https://github.com/aboutcode-org/scancode.io/issues/1587
9+
* Add UI to add/delete Webhooks from the project settings
10+
* Add a new `add-webhook` management command
11+
* Add a `add_webhook` REST API action
12+
* Add a new `SCANCODEIO_GLOBAL_WEBHOOK` setting
13+
* Add a new chapter dedicated to Webhooks management in the documentation
14+
* Add support for custom payload dedicated to Slack webhooks
15+
416
v34.9.5 (2025-02-19)
517
--------------------
618

@@ -15,6 +27,10 @@ v34.9.5 (2025-02-19)
1527
with other aboutcode submodules.
1628
https://github.com/aboutcode-org/scancode.io/issues/1423
1729

30+
- Add a ``add-webhook`` management command that allows to add webhook subscription on
31+
a project.
32+
https://github.com/aboutcode-org/scancode.io/issues/1587
33+
1834
- Add proper progress logging for the ``assemble`` section of the
1935
``scan_for_application_packages``.
2036
https://github.com/aboutcode-org/scancode.io/issues/1601

docs/application-settings.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,54 @@ The web server can be started in DEBUG mode with:
268268
269269
$ SCANCODEIO_LOG_LEVEL=DEBUG make run
270270
271+
.. _scancodeio_settings_site_url:
272+
273+
SCANCODEIO_SITE_URL
274+
^^^^^^^^^^^^^^^^^^^
275+
276+
The base URL of the ScanCode.io application instance.
277+
This setting is **required** to generate absolute URLs referencing objects within the
278+
application, such as in webhook notifications.
279+
280+
The value should be a fully qualified URL, including the scheme (e.g., ``https://``).
281+
282+
Example configuration in the ``.env`` file::
283+
284+
SCANCODEIO_SITE_URL=https://scancode.example.com/
285+
286+
Default: ``""`` (empty)
287+
288+
.. _scancodeio_settings_global_webhook:
289+
290+
SCANCODEIO_GLOBAL_WEBHOOK
291+
^^^^^^^^^^^^^^^^^^^^^^^^^
292+
293+
This setting defines a **global webhook** that will be automatically added as a
294+
``WebhookSubscription`` for each new project.
295+
296+
The webhook is configured as a dictionary and must include a ``target_url``.
297+
Additional options control when the webhook is triggered and what data is included
298+
in the payload.
299+
300+
Example configuration in the ``.env`` file::
301+
302+
SCANCODEIO_GLOBAL_WEBHOOK=target_url=https://webhook.url,trigger_on_each_run=False,include_summary=True,include_results=False
303+
304+
The available options are:
305+
306+
- ``target_url`` (**required**): The URL where the webhook payload will be sent.
307+
- ``trigger_on_each_run`` (**default**: ``False``): If ``True``, the webhook is triggered
308+
on every pipeline run.
309+
- ``include_summary`` (**default**: ``False``): If ``True``, a summary of the pipeline
310+
run results is included in the payload.
311+
- ``include_results`` (**default**: ``False``): If ``True``, detailed scan results
312+
are included in the payload.
313+
314+
If this setting is provided, ScanCode.io will create a webhook subscription
315+
**only for newly created projects that are not clones**.
316+
317+
Default: ``{}`` (no global webhook is set)
318+
271319
TIME_ZONE
272320
^^^^^^^^^
273321

docs/command-line-interface.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,47 @@ add the docker pipeline to your project::
344344
``--pipeline map_deploy_to_develop:Java,JavaScript``
345345

346346

347+
.. _cli_add_webhook:
348+
349+
`$ scanpipe add-webhook --project PROJECT TARGET_URL`
350+
-----------------------------------------------------
351+
352+
Adds a webhook subscription to a project.
353+
354+
Required arguments:
355+
356+
- ``target-url``
357+
The target URL to which the webhook should send POST requests.
358+
359+
Optional arguments:
360+
361+
- ``--trigger-on-each-run``
362+
Trigger the webhook after each individual pipeline run.
363+
364+
- ``--include-summary``
365+
Include summary data in the payload.
366+
367+
- ``--include-results``
368+
Include results data in the payload.
369+
370+
- ``--inactive``
371+
Create the webhook but set it as inactive.
372+
373+
Example usage:
374+
375+
1. Add an active webhook that triggers after each pipeline run::
376+
377+
$ scanpipe add-webhook my_project https://example.com/webhook --trigger-on-each-run
378+
379+
2. Add a webhook that includes summary and results data::
380+
381+
$ scanpipe add-webhook my_project https://example.com/webhook --include-summary --include-results
382+
383+
3. Add an inactive webhook::
384+
385+
$ scanpipe add-webhook my_project https://example.com/webhook --inactive
386+
387+
347388
`$ scanpipe execute --project PROJECT`
348389
--------------------------------------
349390

docs/faq.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ Also, A new GitHub action is available at
205205
`scancode-action repository <https://github.com/nexB/scancode-action>`_
206206
to run ScanCode.io pipelines from your GitHub Workflows.
207207

208+
How can I get notified about my project progression?
209+
-----------------------------------------------------
210+
211+
You can monitor your project's progress in multiple ways:
212+
213+
- **User Interface:** The project details page provides real-time updates on pipeline
214+
execution.
215+
- **REST API:** Use the API to programmatically check the status of your projects.
216+
- **CLI Monitoring:** The ``scanpipe list-projects`` command provides an overview of
217+
project states.
218+
- **Webhook Integration:** You can set up webhooks to receive updates in your preferred
219+
notification system. For more details, refer to the :ref:`webhooks` section.
220+
- **Slack notifications:** Get project updates directly in Slack by configuring an
221+
incoming webhook. See :ref:`webhooks_slack_notifications` for setup instructions.
222+
208223
.. _faq_tag_input_files:
209224

210225
How to tag input files?

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ you’ll find information on:
5050
command-line-interface
5151
rest-api
5252
automation
53+
webhooks
5354
application-settings
5455
distros-os-images
5556

docs/project-configuration.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ Default is ``None``, in which case all files will be scanned.
104104
set using the .env file, and the project setting ``scan_max_file_size`` takes
105105
precedence over the scancodeio setting ``SCANCODEIO_SCAN_MAX_FILE_SIZE``.
106106

107-
108107
ignored_patterns
109108
^^^^^^^^^^^^^^^^
110109

docs/rest-api.rst

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,81 @@ about the project, including the status of any pipeline run:
198198
"created_date": "2021-07-21T16:06:29.132795+02:00"
199199
}
200200
201+
.. _rest_api_webhooks:
202+
203+
Adding webhooks
204+
^^^^^^^^^^^^^^^
205+
206+
When creating a project, you can also **register webhook subscriptions** that will
207+
notify external services about pipeline execution events.
208+
209+
You can either provide:
210+
- A **single webhook URL** using the ``webhook_url`` field.
211+
- A **list of detailed webhook configurations** using the ``webhooks`` field.
212+
213+
Webhook fields:
214+
- ``webhook_url`` (string, optional): A single webhook URL to be notified.
215+
- ``webhooks`` (list, optional): A list of webhook configurations.
216+
- ``target_url`` (string, required): The URL to which the webhook will send a
217+
``POST`` request.
218+
- ``trigger_on_each_run`` (boolean, optional): If ``true``, the webhook will be
219+
triggered after each individual pipeline run. Default is ``false``.
220+
- ``include_summary`` (boolean, optional): If ``true``, the webhook payload
221+
will include the summary data of the pipeline execution. Default is ``false``.
222+
- ``include_results`` (boolean, optional): If ``true``, the webhook payload
223+
will include the full results data of the pipeline execution.
224+
Default is ``false``.
225+
- ``is_active`` (boolean, optional): If ``true``, the webhook is active and
226+
will be triggered when the specified conditions are met. Default is ``true``.
227+
228+
Using cURL to register a webhook:
229+
230+
.. code-block:: console
231+
232+
api_url="http://localhost/api/projects/"
233+
content_type="Content-Type: application/json"
234+
data='{
235+
"name": "project_name",
236+
"webhook_url": "https://example.com/webhook"
237+
}'
238+
239+
curl -X POST "$api_url" -H "$content_type" -d "$data"
240+
241+
.. code-block:: json
242+
243+
{
244+
"name": "project_name",
245+
"webhook_url": "https://example.com/webhook"
246+
}
247+
248+
Using cURL to register multiple webhooks:
249+
250+
.. code-block:: console
251+
252+
api_url="http://localhost/api/projects/"
253+
content_type="Content-Type: application/json"
254+
data='{
255+
"name": "project_name",
256+
"webhooks": [
257+
{
258+
"target_url": "https://example.com/webhook1",
259+
"trigger_on_each_run": true,
260+
"include_summary": false,
261+
"include_results": true,
262+
"is_active": true
263+
},
264+
{
265+
"target_url": "https://example.com/webhook2",
266+
"trigger_on_each_run": false,
267+
"include_summary": true,
268+
"include_results": false,
269+
"is_active": true
270+
}
271+
]
272+
}'
273+
274+
curl -X POST "$api_url" -H "$content_type" -d "$data"
275+
201276
Project details
202277
---------------
203278

@@ -278,6 +353,8 @@ Using cURL to upload a local file:
278353
"status": "Input(s) added."
279354
}
280355
356+
.. _rest_api_add_pipeline:
357+
281358
Add pipeline
282359
^^^^^^^^^^^^
283360

@@ -315,6 +392,58 @@ Using cURL:
315392
"status": "Pipeline added."
316393
}
317394
395+
.. _rest_api_add_webhook:
396+
397+
Add webhook
398+
^^^^^^^^^^^
399+
400+
This action adds a webhook subscription to the ``project``.
401+
A webhook allows external services to receive real-time notifications about project
402+
pipeline execution events.
403+
404+
``POST /api/projects/d4ed9405-5568-45ad-99f6-782a9b82d1d2/add_webhook/``
405+
406+
Data:
407+
- ``target_url`` (string, required): The URL to which the webhook will send
408+
a ``POST`` request when triggered.
409+
- ``trigger_on_each_run`` (boolean, optional): If ``true``, the webhook will be
410+
triggered after each individual pipeline run. Default is ``false``.
411+
- ``include_summary`` (boolean, optional): If ``true``, the webhook payload will
412+
include the summary data of the pipeline execution. Default is ``false``.
413+
- ``include_results`` (boolean, optional): If ``true``, the webhook payload will
414+
include the full results data of the pipeline execution. Default is ``false``.
415+
- ``is_active`` (boolean, optional): If ``true``, the webhook is active and will
416+
be triggered when the specified conditions are met. Default is ``true``.
417+
418+
Using cURL:
419+
420+
.. code-block:: console
421+
422+
api_url="http://localhost/api/projects/6461408c-726c-4b70-aa7a-c9cc9d1c9685/add_webhook/"
423+
content_type="Content-Type: application/json"
424+
data='{
425+
"target_url": "https://example.com/webhook",
426+
"trigger_on_each_run": true,
427+
"include_summary": true,
428+
"include_results": false,
429+
"is_active": true
430+
}'
431+
432+
curl -X POST "$api_url" -H "$content_type" -d "$data"
433+
434+
.. code-block:: json
435+
436+
{
437+
"status": "Webhook added."
438+
}
439+
440+
.. note::
441+
- Webhooks will only be triggered for active subscriptions.
442+
- If ``trigger_on_each_run`` is set to ``false``, the webhook will only trigger
443+
after all pipeline runs are completed.
444+
- The ``include_summary`` and ``include_results`` fields allow customization of
445+
the webhook payload.
446+
318447
Archive
319448
^^^^^^^
320449

docs/user-interface.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,34 @@ your specific requirements.
117117
Project Settings UI and click on the **Config file** link in the left section under
118118
**Download**.
119119

120+
.. _user_interface_manage_webhook:
121+
122+
Manage Webhook
123+
^^^^^^^^^^^^^^
124+
125+
The **Manage Webhook** section in the Project Settings view allows you to configure
126+
Webhook subscriptions for project pipeline execution events.
127+
128+
From the Settings page, you can:
129+
130+
- **Add a new webhook** by specifying a target URL that will receive event notifications.
131+
- **Edit an existing webhook** to update its target URL, event triggers, or payload settings.
132+
- **Delete a webhook** to stop receiving notifications for that project.
133+
134+
Each webhook is associated with a **WebhookSubscription** and includes the following
135+
configurable options:
136+
137+
- **Target URL**: The destination where the webhook payload will be sent when triggered.
138+
- **Trigger on Each Run**: Choose whether to send notifications after each pipeline run
139+
or only after all runs are completed.
140+
- **Include Summary**: Decide whether to include summary data in the webhook payload.
141+
- **Include Results**: Optionally include detailed scan results in the webhook payload.
142+
- **Active Status**: Enable or disable the webhook without deleting it.
143+
144+
.. note::
145+
Ensure the target URL is correctly configured to receive webhook requests and
146+
process them accordingly.
147+
120148
Archive a Project
121149
^^^^^^^^^^^^^^^^^
122150

0 commit comments

Comments
 (0)