Gerrit.php 1.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

namespace FixSuggestions\Submitter;

use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

class Gerrit {

	public const ID = 'gerrit';
	/**
	 * @var string
	 */
	private $zuulProject;
	/**
	 * @var int
	 */
	private $zuulChange;
	/**
	 * @var int
	 */
	private $zuulPatchset;
	/**
	 * @var \FixSuggestions\Http\Gerrit
	 */
	private $gerritHttpClient;

	/**
	 * @param string $gerritUrl
	 * @param string $gerritUsername
	 * @param string $gerritPassword
	 * @param string $zuulProject
	 * @param int $zuulChange
	 * @param int $zuulPatchset
	 */
	public function __construct(
		string $gerritUrl,
		string $gerritUsername,
		string $gerritPassword,
		string $zuulProject,
		int $zuulChange,
		int $zuulPatchset
	) {
		$this->gerritHttpClient = new \FixSuggestions\Http\Gerrit(
			$gerritUrl,
			$gerritUsername,
			$gerritPassword
		);

		$this->zuulProject = $zuulProject;
		$this->zuulChange = $zuulChange;
		$this->zuulPatchset = $zuulPatchset;
	}

	/**
	 * @param array $suggestions
	 * @return ResponseInterface
	 * @throws TransportExceptionInterface
	 */
	public function execute( array $suggestions ): ResponseInterface {
		return $this->gerritHttpClient->postFixSuggestions(
			$suggestions,
			$this->zuulProject,
			$this->zuulChange,
			$this->zuulPatchset
		);
	}
}