Skip to content

Commit 9dde073

Browse files
authored
CRAVEX Generic workflow integration #345 (#381)
Signed-off-by: tdruez <[email protected]>
1 parent a1a7fa6 commit 9dde073

File tree

9 files changed

+525
-2
lines changed

9 files changed

+525
-2
lines changed

docs/faq.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ How can I download SBOM for my products?
1515
the product details view in the web UI or from dedicated endpoint URLs of the REST API.
1616

1717
Refer to :ref:`how_to_3` for more details.
18+
19+
How can I integrate DejaCode with my tools or applications?
20+
-----------------------------------------------------------
21+
22+
DejaCode supports three main integration approaches:
23+
24+
- **Platform-specific integrations** for GitHub, GitLab, Jira, SourceHut, and Forgejo
25+
(:ref:`platform_specific_integrations`)
26+
- The **REST API** for programmatic access to data and operations
27+
(:ref:`rest_api_integration`)
28+
- **Webhooks** for receiving real-time event notifications
29+
(:ref:`webhook_integration`)
30+
31+
The last two options — REST API and webhooks — enable **generic integration** with
32+
virtually any application or service, giving you full flexibility to connect
33+
DejaCode to your existing tools and workflows.

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ Welcome to the very start of your DejaCode journey!
4848
:maxdepth: 1
4949
:caption: Integrations
5050

51+
integrations-introduction
5152
integrations-forgejo
5253
integrations-github
5354
integrations-gitlab
5455
integrations-jira
5556
integrations-sourcehut
57+
integrations-rest-api
58+
integrations-webhook
5659

5760
.. toctree::
5861
:maxdepth: 1

docs/integrations-introduction.rst

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
.. _integrations_introduction:
2+
3+
Integrations overview
4+
=====================
5+
6+
DejaCode offers several ways to connect with other tools and services, enabling
7+
**automation**, **synchronization**, and **streamlined workflows**. Depending on your
8+
needs, you can choose from :ref:`platform_specific_integrations`, the
9+
:ref:`rest_api_integration`, or the :ref:`webhook_integration`.
10+
11+
.. _platform_specific_integrations:
12+
13+
Platform-specific integrations
14+
------------------------------
15+
16+
DejaCode provides built-in support for the following platforms:
17+
18+
- :ref:`integrations_github`
19+
- :ref:`integrations_gitlab`
20+
- :ref:`integrations_jira`
21+
- :ref:`integrations_sourcehut`
22+
- :ref:`integrations_forgejo`
23+
24+
These integrations are designed to work **seamlessly** with each platform's features.
25+
They typically allow **requests**, **comments**, and **status changes** in DejaCode to
26+
be linked or synchronized with corresponding items in the external platform, such as
27+
**issues** or **tickets**.
28+
29+
Platform-specific integrations are the best choice when:
30+
31+
- Your team already uses **one of the supported platforms**
32+
- You want **minimal setup**, with features mapped directly between systems
33+
- You prefer a **native, optimized experience** rather than building custom logic
34+
35+
.. _rest_api_integration:
36+
37+
REST API
38+
--------
39+
40+
The :ref:`integrations_rest_api` provides **full programmatic access** to most features
41+
of the platform. This makes it possible to integrate DejaCode with **any script,
42+
application, or automation system**, regardless of the programming language or
43+
framework.
44+
45+
With the REST API, you can:
46+
47+
- **Create, update, and retrieve** requests and related objects
48+
- **Automate** administrative tasks
49+
- Pull data into **reporting** or **analytics tools**
50+
- Build **custom user interfaces** on top of DejaCode data
51+
52+
This approach offers **maximum flexibility**, but requires you to write the logic for
53+
**handling events**, **processing data**, and **authenticating** with the API.
54+
55+
.. _webhook_integration:
56+
57+
Webhook integration
58+
-------------------
59+
60+
:ref:`integrations_webhook` allow DejaCode to **push** information to an **external
61+
system** the moment specific events occur, instead of requiring you to **poll** the
62+
API.
63+
64+
When a configured event happens (such as a **request** being created or updated),
65+
DejaCode sends an HTTP ``POST`` request with a **JSON payload** to your **target URL**.
66+
You can then process this payload to **trigger automation**, **update another system**,
67+
or **log the change**.
68+
69+
Webhooks can be configured for a **variety of events**, and the payload can be
70+
extended with **custom fields** and **headers**. They are especially powerful when
71+
combined with the REST API — **webhooks deliver the trigger**, and **API calls perform
72+
follow-up actions**.
73+
74+
Generic integrations
75+
--------------------
76+
77+
While platform-specific integrations focus on **GitHub**, **GitLab**, **Jira**,
78+
**SourceHut**, and **Forgejo**, both the :ref:`rest_api_integration` and
79+
:ref:`webhook_integration` provide the tools to connect DejaCode to **virtually any
80+
application or service**.
81+
82+
Examples include:
83+
84+
- Pushing updates to a **Slack** channel or **Microsoft Teams**
85+
- Updating **internal dashboards**
86+
- Triggering **security scans** or **CI/CD jobs**
87+
- Synchronizing data with **proprietary in-house systems**
88+
89+
Choosing the right approach
90+
---------------------------
91+
92+
- Use a :ref:`platform_specific_integrations` integration if your workflow centers on
93+
**one of the supported platforms** and you want the **easiest setup**.
94+
- Use the :ref:`rest_api_integration` for **full control** and **flexibility** over
95+
how DejaCode interacts with other systems.
96+
- Use :ref:`webhook_integration` to receive **real-time notifications** and act
97+
immediately on events.
98+
- Combine :ref:`webhook_integration` with the :ref:`rest_api_integration` for
99+
**event-driven automation** that can **react** and then **fetch or update** related
100+
data as needed.

docs/integrations-rest-api.rst

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
.. _integrations_rest_api:
2+
3+
REST API Integration
4+
====================
5+
6+
DejaCode offers a REST API to allow integration with external applications in a
7+
generic way. You can use it to fetch, create, and update DejaCode Requests
8+
from your own scripts or applications.
9+
10+
The full REST API documentation is also available in the DejaCode web UI under
11+
**Tools > API Documentation**.
12+
13+
This guide focuses specifically on interacting with **DejaCode Requests**.
14+
15+
.. note::
16+
17+
Example HTTP requests assume the DejaCode URL is ``https://localhost``.
18+
Replace with your actual instance URL.
19+
20+
Prerequisites
21+
-------------
22+
23+
- A **DejaCode API Key**, available from your **Profile** settings page.
24+
25+
Authentication
26+
--------------
27+
28+
Include your **API Key** in the "Authorization" HTTP header for every request.
29+
The key must be prefixed by the string literal ``Token`` followed by a space:
30+
31+
Authorization: Token abcdef123456
32+
33+
.. warning::
34+
Treat your API key like a password — keep it secret and secure.
35+
36+
Example using cURL::
37+
38+
curl -X GET \
39+
https://localhost/api/v2/requests/ \
40+
-H "Authorization: Token abcdef123456"
41+
42+
Example using Python::
43+
44+
import requests
45+
46+
api_url = "https://localhost/api/v2/requests/"
47+
headers = {"Authorization": "Token abcdef123456"}
48+
params = {"page": "2"}
49+
response = requests.get(api_url, headers=headers, params=params)
50+
print(response.json())
51+
52+
Request List
53+
------------
54+
55+
**Endpoint:** ``GET /api/v2/requests/``
56+
57+
This endpoint lists all requests. Responses include pagination fields ``next``
58+
and ``previous`` to navigate through pages.
59+
60+
You can sort the list using ``?ordering=FIELD``. Prefix a field with ``-`` to
61+
reverse the sort order (descending). Available fields:
62+
63+
- ``title``
64+
- ``request_template``
65+
- ``status``
66+
- ``priority``
67+
- ``assignee``
68+
- ``requester``
69+
- ``created_date``
70+
- ``last_modified_date``
71+
72+
Filtering is supported using ``FIELD=VALUE`` syntax. Available filters include:
73+
74+
- ``request_template``
75+
- ``status``
76+
- ``requester``
77+
- ``assignee``
78+
- ``priority``
79+
- ``content_type``
80+
- ``last_modified_date``
81+
82+
Example: Get closed requests sorted by last modification date::
83+
84+
api_url = "https://localhost/api/v2/requests/"
85+
headers = {"Authorization": "Token abcdef123456"}
86+
params = {"status": "closed", "ordering": "last_modified_date"}
87+
response = requests.get(api_url, headers=headers, params=params)
88+
print(response.json())
89+
90+
Request Details
91+
---------------
92+
93+
**Endpoint:** ``GET /api/v2/requests/{uuid}/``
94+
95+
Returns all available information for a specific request. Replace ``{uuid}``
96+
with the UUID of the request you want to retrieve.
97+
98+
Example JSON response snippet::
99+
100+
{
101+
"uuid": "adf1835e-4b58-42d0-b1f4-c57791167d19",
102+
"title": "Issue title",
103+
"request_template": "https://localhost/api/v2/request_templates/5b106292-d8b6-459c-abda-e6a87527a0db/",
104+
"status": "open",
105+
"assignee": "username",
106+
"notes": "",
107+
"serialized_data": {"Notes": "This version has a known vulnerability."},
108+
"created_date": "2025-08-12T17:41:47.424373+04:00",
109+
"last_modified_date": "2025-08-12T17:42:29.031833+04:00",
110+
"comments": [
111+
{
112+
"uuid": "8ee73eb2-353a-4e84-8536-fe4e25a1abf6",
113+
"username": "username",
114+
"text": "Comment content.",
115+
"created_date": "2025-08-14T09:17:55.397285+04:00"
116+
}
117+
]
118+
}
119+
120+
Create a Request
121+
----------------
122+
123+
**Endpoint:** ``POST /api/v2/requests/``
124+
125+
Required fields:
126+
127+
- **title** (string): A short, descriptive title of the request.
128+
- **request_template** (string): URI of the template to use.
129+
130+
Optional fields:
131+
132+
- **status** (string): ``open``, ``closed``, or ``draft``. Default is ``open``.
133+
- **assignee** (string): Username of the person assigned.
134+
- **priority** (string|null): Priority level.
135+
- **product_context** (string|null): URI of a product context.
136+
- **notes** (string): Notes related to the request.
137+
- **serialized_data** (string): Additional structured data.
138+
- **is_private** (boolean): True if only visible to requester/reviewers.
139+
- **content_object** (string|null): URI of associated content object.
140+
- **cc_emails** (array of strings): List of emails to notify.
141+
142+
.. note::
143+
144+
The structure of **serialized_data** depends on the "Request Template" used
145+
for the request. To help construct valid **serialized_data**, consult the
146+
``form_data_layout`` field available in the Request Template list at
147+
``https://localhost/api/v2/request_templates/``.
148+
149+
Example of minimal JSON payload::
150+
151+
{
152+
"title": "New vulnerability found",
153+
"request_template": "Address Vulnerabilities in Product Packages"
154+
}
155+
156+
Example using cURL::
157+
158+
api_url="https://localhost/api/v2/requests/"
159+
headers="Authorization: Token abcdef123456"
160+
data='{
161+
"title": "New vulnerability found",
162+
"request_template": "Address Vulnerabilities in Product Packages"
163+
}'
164+
165+
curl -X POST "$api_url" -H "$headers" -d "$data"
166+
167+
Example using Python::
168+
169+
import requests
170+
api_url = "https://localhost/api/v2/requests/"
171+
headers = {
172+
"Authorization": "Token abcdef123456",
173+
"Content-Type": "application/json"
174+
}
175+
data = {
176+
"title": "New vulnerability found",
177+
"request_template": "Address Vulnerabilities in Product Packages",
178+
"assignee": "username"
179+
}
180+
response = requests.post(api_url, headers=headers, json=data)
181+
print(response.json())
182+
183+
Update a Request
184+
----------------
185+
186+
**Endpoint:** ``PUT /api/v2/requests/{uuid}/``
187+
188+
Performs a full update. All fields of the request must be provided.
189+
190+
Partial Update
191+
--------------
192+
193+
**Endpoint:** ``PATCH /api/v2/requests/{uuid}/``
194+
195+
Allows updating only specific fields. For example, to close a request::
196+
197+
import requests
198+
api_url = "https://localhost/api/v2/requests/{uuid}/"
199+
headers = {
200+
"Authorization": "Token abcdef123456",
201+
"Content-Type": "application/json"
202+
}
203+
data = {"status": "closed"}
204+
response = requests.patch(api_url, headers=headers, json=data)
205+
print(response.json())
206+
207+
Add comment
208+
-----------
209+
210+
``POST /api/v2/requests/{uuid}/add_comment/``
211+
212+
This endpoint allows you to attach a new comment to an existing request.
213+
A successful call will store the comment and return a confirmation message.
214+
215+
**Payload example**:
216+
217+
.. code-block:: json
218+
219+
{
220+
"text": "Comment content"
221+
}
222+
223+
**Notes**:
224+
- The ``uuid`` in the URL must correspond to the target request.
225+
- The ``text`` field is required and should contain the full comment content.
226+
- Comments are attributed to the authenticated user making the request.
227+
- A successful request returns HTTP 201 with a status message.
228+
- Invalid or missing fields will return HTTP 400 along with error details.

0 commit comments

Comments
 (0)