Skip to content

Commit 5d83c32

Browse files
committed
Feature: add HTTP proxy support to webhook integrations
1 parent ac89371 commit 5d83c32

File tree

52 files changed

+9194
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+9194
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Add PRs to Combodo PRs Dashboard
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
8+
jobs:
9+
add-to-project:
10+
name: Add PR to Combodo Project
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check if author is a member of the organization
14+
id: check-membership
15+
run: |
16+
ORG="Combodo"
17+
AUTHOR=$(jq -r .pull_request.user.login "$GITHUB_EVENT_PATH")
18+
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}" \
19+
"https://api.github.com/orgs/$ORG/members/$AUTHOR")
20+
if [ "$RESPONSE" == "404" ]; then
21+
echo "project_url=https://github.com/orgs/Combodo/projects/5" >> $GITHUB_ENV
22+
echo "is_member=false" >> $GITHUB_ENV
23+
else
24+
echo "project_url=https://github.com/orgs/Combodo/projects/4" >> $GITHUB_ENV
25+
echo "is_member=true" >> $GITHUB_ENV
26+
27+
fi
28+
29+
- name: Add internal tag if member
30+
if: env.is_member == 'true'
31+
run: |
32+
curl -X POST -H "Authorization: token ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}" \
33+
-H "Accept: application/vnd.github.v3+json" \
34+
https://api.github.com/repos/Combodo/combodo-webhook-integration/issues/${{ github.event.pull_request.number }}/labels \
35+
-d '{"labels":["internal"]}'
36+
env:
37+
is_member: ${{ env.is_member }}
38+
39+
- name: Add PR to the appropriate project
40+
uses: actions/add-to-project@v1.0.2
41+
with:
42+
project-url: ${{ env.project_url }}
43+
github-token: ${{ secrets.PR_AUTOMATICALLY_ADD_TO_PROJECT }}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright (C) 2013-2024 Combodo SAS
4+
*
5+
* This file is part of iTop.
6+
*
7+
* iTop is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* iTop is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
*/
19+
20+
// Important: Unfortunately, for now AsyncTask classes CANNOT have a namespace, it will crash the OQL parser.
21+
22+
use Combodo\iTop\Core\WebRequest;
23+
use Combodo\iTop\Service\WebRequestSender;
24+
// If we ever move this class back to a namespace, mind putting the following uses back
25+
//use AsyncTask;
26+
//use AttributeString;
27+
//use AttributeLongText;
28+
//use MetaModel;
29+
30+
/**
31+
* Class SendWebRequest
32+
*
33+
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
34+
*/
35+
class SendWebRequest extends AsyncTask
36+
{
37+
/**
38+
* @inheritDoc
39+
* @throws \CoreException
40+
* @throws \Exception
41+
*/
42+
public static function Init()
43+
{
44+
$aParams = array
45+
(
46+
"category" => "core/cmdb",
47+
"key_type" => "autoincrement",
48+
"name_attcode" => "created",
49+
"state_attcode" => "",
50+
"reconc_keys" => array(),
51+
"db_table" => "priv_async_send_web_request",
52+
"db_key_field" => "id",
53+
"db_finalclass_field" => "",
54+
"display_template" => "",
55+
);
56+
MetaModel::Init_Params($aParams);
57+
MetaModel::Init_InheritAttributes();
58+
59+
MetaModel::Init_AddAttribute(new AttributeLongText("request", array("allowed_values"=>null, "sql"=>"request", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
60+
}
61+
62+
/**
63+
* Add the $oWebRequest to the queue to be send later (background task for example)
64+
*
65+
* @param \Combodo\iTop\Core\WebRequest $oWebRequest
66+
* @param \EventNotification|null $oLog
67+
*
68+
* @throws \ArchivedObjectException
69+
* @throws \CoreCannotSaveObjectException
70+
* @throws \CoreException
71+
* @throws \CoreUnexpectedValue
72+
* @throws \CoreWarning
73+
* @throws \MySQLException
74+
* @throws \OQLException
75+
*
76+
* @return void
77+
*/
78+
public static function AddToQueue(WebRequest $oWebRequest, $oLog = null)
79+
{
80+
$oNew = new static();
81+
if ($oLog)
82+
{
83+
$oNew->Set('event_id', $oLog->GetKey());
84+
}
85+
86+
$oNew->Set('request', serialize($oWebRequest));
87+
$oNew->DBInsert();
88+
}
89+
90+
/**
91+
* @inheritDoc
92+
*/
93+
public function DoProcess()
94+
{
95+
$aIssues = array();
96+
$oWebRequest = unserialize($this->Get('request'));
97+
98+
// Retrieve log event
99+
/** @var \AttributeExternalKey $oAttDef */
100+
$oAttDef = MetaModel::GetAttributeDef(get_class($this), 'event_id');
101+
$oLog = MetaModel::GetObject($oAttDef->GetTargetClass(), $this->Get('event_id'), false, true);
102+
103+
$oSenderService = WebRequestSender::GetInstance();
104+
$aResult = $oSenderService->Send($oWebRequest, $aIssues, $oLog, WebRequestSender::ENUM_SEND_MODE_SYNC);
105+
switch ($aResult['sender_status'])
106+
{
107+
case WebRequestSender::ENUM_SEND_STATE_OK:
108+
return 'Sent';
109+
110+
case WebRequestSender::ENUM_SEND_STATE_PENDING:
111+
return 'Whoops! Seems like a bug occurred, the request should be sent in synchronous mode';
112+
113+
case WebRequestSender::ENUM_SEND_STATE_ERROR:
114+
return 'Failed: '.implode(', ', $aIssues);
115+
}
116+
}
117+
}
5.33 KB
Loading
7.44 KB
Loading
6.42 KB
Loading
8.33 KB
Loading
8.91 KB
Loading
11.4 KB
Loading
9.8 KB
Loading
12.2 KB
Loading

0 commit comments

Comments
 (0)