Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Add PRs to Combodo PRs Dashboard

on:
pull_request_target:
types:
- opened

jobs:
add-to-project:
name: Add PR to Combodo Project
runs-on: ubuntu-latest
steps:
- name: Check if author is a member of the organization
id: check-membership
run: |
ORG="Combodo"
AUTHOR=$(jq -r .pull_request.user.login "$GITHUB_EVENT_PATH")
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}" \
"https://api.github.com/orgs/$ORG/members/$AUTHOR")
if [ "$RESPONSE" == "404" ]; then
echo "project_url=https://github.com/orgs/Combodo/projects/5" >> $GITHUB_ENV
echo "is_member=false" >> $GITHUB_ENV
else
echo "project_url=https://github.com/orgs/Combodo/projects/4" >> $GITHUB_ENV
echo "is_member=true" >> $GITHUB_ENV

fi

- name: Add internal tag if member
if: env.is_member == 'true'
run: |
curl -X POST -H "Authorization: token ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/Combodo/combodo-webhook-integration/issues/${{ github.event.pull_request.number }}/labels \
-d '{"labels":["internal"]}'
env:
is_member: ${{ env.is_member }}

- name: Add PR to the appropriate project
uses: actions/add-to-project@v1.0.2
with:
project-url: ${{ env.project_url }}
github-token: ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}
117 changes: 117 additions & 0 deletions datamodels/2.x/combodo-webhook-integration/SendWebRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/

// Important: Unfortunately, for now AsyncTask classes CANNOT have a namespace, it will crash the OQL parser.

use Combodo\iTop\Core\WebRequest;
use Combodo\iTop\Service\WebRequestSender;
// If we ever move this class back to a namespace, mind putting the following uses back
//use AsyncTask;
//use AttributeString;
//use AttributeLongText;
//use MetaModel;

/**
* Class SendWebRequest
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
*/
class SendWebRequest extends AsyncTask
{
/**
* @inheritDoc
* @throws \CoreException
* @throws \Exception
*/
public static function Init()
{
$aParams = array
(
"category" => "core/cmdb",
"key_type" => "autoincrement",
"name_attcode" => "created",
"state_attcode" => "",
"reconc_keys" => array(),
"db_table" => "priv_async_send_web_request",
"db_key_field" => "id",
"db_finalclass_field" => "",
"display_template" => "",
);
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();

MetaModel::Init_AddAttribute(new AttributeLongText("request", array("allowed_values"=>null, "sql"=>"request", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
}

/**
* Add the $oWebRequest to the queue to be send later (background task for example)
*
* @param \Combodo\iTop\Core\WebRequest $oWebRequest
* @param \EventNotification|null $oLog
*
* @throws \ArchivedObjectException
* @throws \CoreCannotSaveObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \CoreWarning
* @throws \MySQLException
* @throws \OQLException
*
* @return void
*/
public static function AddToQueue(WebRequest $oWebRequest, $oLog = null)
{
$oNew = new static();
if ($oLog)
{
$oNew->Set('event_id', $oLog->GetKey());
}

$oNew->Set('request', serialize($oWebRequest));
$oNew->DBInsert();
}

/**
* @inheritDoc
*/
public function DoProcess()
{
$aIssues = array();
$oWebRequest = unserialize($this->Get('request'));

// Retrieve log event
/** @var \AttributeExternalKey $oAttDef */
$oAttDef = MetaModel::GetAttributeDef(get_class($this), 'event_id');
$oLog = MetaModel::GetObject($oAttDef->GetTargetClass(), $this->Get('event_id'), false, true);

$oSenderService = WebRequestSender::GetInstance();
$aResult = $oSenderService->Send($oWebRequest, $aIssues, $oLog, WebRequestSender::ENUM_SEND_MODE_SYNC);
switch ($aResult['sender_status'])
{
case WebRequestSender::ENUM_SEND_STATE_OK:
return 'Sent';

case WebRequestSender::ENUM_SEND_STATE_PENDING:
return 'Whoops! Seems like a bug occurred, the request should be sent in synchronous mode';

case WebRequestSender::ENUM_SEND_STATE_ERROR:
return 'Failed: '.implode(', ', $aIssues);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions datamodels/2.x/combodo-webhook-integration/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"license": "AGPL-3.0-only",
"autoload": {
"psr-4": {
"Combodo\\iTop\\": "src/"
}
},
"require": {
"composer-runtime-api": "^2.0"
}
}
20 changes: 20 additions & 0 deletions datamodels/2.x/combodo-webhook-integration/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<Set>
<RemoteApplicationType alias="RemoteApplicationType" id="1">
<name>iTop</name>
</RemoteApplicationType>
<RemoteApplicationType alias="RemoteApplicationType" id="2">
<name>Slack</name>
</RemoteApplicationType>
<RemoteApplicationType alias="RemoteApplicationType" id="3">
<name>Rocket.Chat</name>
</RemoteApplicationType>
<RemoteApplicationType alias="RemoteApplicationType" id="4">
<name>Google Chat</name>
</RemoteApplicationType>
<RemoteApplicationType alias="RemoteApplicationType" id="5">
<name>Microsoft Teams</name>
</RemoteApplicationType>
<RemoteApplicationType alias="RemoteApplicationType" id="6">
<name>Other / Generic</name>
</RemoteApplicationType>
</Set>
Loading