/** * Provide auto merge */ public function actionDefault() { $payload = $this->httpRequest->getRawBody(); if (!$payload) { Debugger::log('No payload data', Debugger::ERROR); $this->terminate(); } $data = json_decode($payload, true); if (!$data) { Debugger::log('json_decode error', Debugger::ERROR); $this->terminate(); } if ($data['object_kind'] != 'note') { Debugger::log('Only notes object kind processing now. *' . $data['object_kind'] . '* given', Debugger::ERROR); $this->terminate(); } $projectId = isset($data['merge_request']['source_project_id']) ? $data['merge_request']['source_project_id'] : false; $mergeRequestId = isset($data['merge_request']['id']) ? $data['merge_request']['id'] : false; if (!$projectId || !$mergeRequestId) { Debugger::log('projectId or mergeRequestId missing', Debugger::ERROR); $this->terminate(); } $project = $this->projectRepository->findByGitlabId($projectId); if (!$project) { Debugger::log('Project ' . $projectId . ' is not allowed to auto merge', Debugger::ERROR); $this->terminate(); } $mr = $this->gitlabClient->api('mr')->show($projectId, $mergeRequestId); $mergeRequest = $this->mergeRequestBuilder->create($mr, $data); if ($mergeRequest->canBeAutoMerged($project->positive_votes)) { $this->gitlabClient->api('mr')->merge($projectId, $mergeRequestId, 'Auto merged'); } }
/** * @return Webhooks\Data * @throws Utils\JsonException In case request body is not valid JSON * @throws Utils\AssertionException In case request body is missing required keys */ public function create() { $data = Utils\Json::decode($this->request->getRawBody(), Utils\Json::FORCE_ARRAY); Utils\Validators::assert($data, 'array', 'request body'); Utils\Validators::assertField($data, 'id', 'string', 'item % in request body'); Utils\Validators::assertField($data, 'suspectId', 'string', 'item % in request body'); Utils\Validators::assertField($data, 'externalId', 'string|null', 'item % in request body'); Utils\Validators::assertField($data, 'user', 'array', 'item % in request body'); Utils\Validators::assertField($data['user'], 'id', 'int', 'item % in user hash within request body'); Utils\Validators::assertField($data['user'], 'salescode', 'string', 'item % in user hash within request body'); Utils\Validators::assertField($data['user'], 'name', 'string', 'item % in user hash within request body'); Utils\Validators::assertField($data, 'data', 'array', 'item % in request body'); return new Webhooks\Data($id = $this->request->getHeader(Webhooks\Headers::IDENTIFIER), $interactionId = $data['id'], $suspectId = $data['suspectId'], $externalId = $data['externalId'], $campaignId = $this->request->getHeader(Webhooks\Headers::CAMPAIGN), $signature = $this->request->getHeader(Webhooks\Headers::SIGNATURE), $event = $this->request->getHeader(Webhooks\Headers::EVENT), $user = $data['user'], $suspectData = $data['data']); }
/** * @param Request $request * @return Notification */ public static function createFromRequest(Request $request) { $notification = new Notification(); $parsed = Json::decode($request->getRawBody()); $notification->setLive($parsed->live === 'true'); $items = array(); foreach ($parsed->notificationItems as $rawItem) { $item = new NotificationRequestItem($notification); $item->setAdditionalData(self::getNotificationRequestItemValue($rawItem, 'additionalData')); $item->setAmountValue(self::getNotificationRequestItemValue($rawItem, 'amount.value')); $item->setAmountCurrency(self::getNotificationRequestItemValue($rawItem, 'amount.currency')); $item->setPspReference(self::getNotificationRequestItemValue($rawItem, 'pspReference')); $item->setEventCode(self::getNotificationRequestItemValue($rawItem, 'eventCode')); $date = new DateTime(self::getNotificationRequestItemValue($rawItem, 'eventDate')); $item->setEventDate($date); $item->setMerchantAccountCode(self::getNotificationRequestItemValue($rawItem, 'merchantAccountCode')); $item->setOperations(self::getNotificationRequestItemValue($rawItem, 'operations')); $item->setMerchantReference(self::getNotificationRequestItemValue($rawItem, 'merchantReference')); $item->setOriginalReference(self::getNotificationRequestItemValue($rawItem, 'originalReference')); $item->setPaymentMethod(self::getNotificationRequestItemValue($rawItem, 'paymentMethod')); $item->setReason(self::getNotificationRequestItemValue($rawItem, 'reason')); $item->setSuccess(self::getNotificationRequestItemValue($rawItem, 'success') === 'true'); $items[] = $item; } $notification->setNotificationItems($items); return $notification; }
/** * */ public function handleSave() { if ($this->connector->checkPermission()) { $post = $this->request->getRawBody(); $locale = $this->connector->getLocale(); try { $json = Json::decode($post); } catch (JsonException $e) { $this->sendResponse(400, 'invalid json'); return; } foreach ($json as $name => $item) { if ($locale && !isset($item->locale)) { $item->locale = $locale; } $this->storage->saveContent($name, $item); } $this->sendResponse(); } else { $this->sendResponse(403); } }
public function getRawBody() { return $this->request->getRawBody(); }