I am in the process of creating an API that will accept and process POST requests from GitLab webhooks and in turn create "Tasks" for issues that were created in GitLab.
Example Steps:
- Create an issue in GitLab.
- GitLab makes a POST request to my API via the project's configured webhooks.
- My API validates the GitLab instance and secret before processing the POST request.
- The Controller identifies it as an issue that was created in GitLab.
- The Controller then makes a few POST requests to the GitLab API to create "Tasks".
I already have everything created and it executes as expected, however, it creates new issues rather than "tasks" that are associated with existing issues. This ends up in an infinite loop between the GitLab webhooks and my API making POST requests to GitLab.
I need to refactor step 5 above to create "Tasks" instead of "Issues". I have also seen "work items" somewhere but cannot seem to find relevant API documentation for it.
Here's the code I am using to try and create the "Tasks" that are associated with the issue that was created. $subtasks is an array with 4 subtasks listed, each with a title and description.
// Loop through the subtasks and create them.
foreach ( $subtasks as $subtask ) {
try {
// Create the subtask via the GitLab API.
Http::withToken($gitlabAccessToken)->post("https://gitlab.com/api/v4/projects/$projectId/issues", [
'title' => $subtask['title'],
'description' => $subtask['description'],
'parent_id' => $issueId
]);
} catch ( \Exception $e ) {
Log::error($e->getMessage());
break;
}
}
Does anyone have any advice or suggestions?
Here's a screenshot of what I want to create via the GitLab API if it is possible. Screenshot
Thank you.