Skip to content

Commit bfc15ed

Browse files
nealio82Neal Brooks
and
Neal Brooks
authored
add getCommit method on CodeCommit client (#1310)
add getCommit method on CodeCommit client Co-authored-by: Neal Brooks <neali82@gmail.com>
1 parent 1142e0a commit bfc15ed

File tree

11 files changed

+546
-0
lines changed

11 files changed

+546
-0
lines changed

src/CodeCommitClient.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use AsyncAws\CodeCommit\Exception\BranchDoesNotExistException;
88
use AsyncAws\CodeCommit\Exception\BranchNameRequiredException;
99
use AsyncAws\CodeCommit\Exception\CommitDoesNotExistException;
10+
use AsyncAws\CodeCommit\Exception\CommitIdDoesNotExistException;
11+
use AsyncAws\CodeCommit\Exception\CommitIdRequiredException;
1012
use AsyncAws\CodeCommit\Exception\CommitRequiredException;
1113
use AsyncAws\CodeCommit\Exception\EncryptionIntegrityChecksFailedException;
1214
use AsyncAws\CodeCommit\Exception\EncryptionKeyAccessDeniedException;
@@ -40,10 +42,12 @@
4042
use AsyncAws\CodeCommit\Exception\RepositoryTriggersListRequiredException;
4143
use AsyncAws\CodeCommit\Input\GetBlobInput;
4244
use AsyncAws\CodeCommit\Input\GetBranchInput;
45+
use AsyncAws\CodeCommit\Input\GetCommitInput;
4346
use AsyncAws\CodeCommit\Input\GetDifferencesInput;
4447
use AsyncAws\CodeCommit\Input\PutRepositoryTriggersInput;
4548
use AsyncAws\CodeCommit\Result\GetBlobOutput;
4649
use AsyncAws\CodeCommit\Result\GetBranchOutput;
50+
use AsyncAws\CodeCommit\Result\GetCommitOutput;
4751
use AsyncAws\CodeCommit\Result\GetDifferencesOutput;
4852
use AsyncAws\CodeCommit\Result\PutRepositoryTriggersOutput;
4953
use AsyncAws\CodeCommit\ValueObject\RepositoryTrigger;
@@ -145,6 +149,50 @@ public function getBranch($input = []): GetBranchOutput
145149
return new GetBranchOutput($response);
146150
}
147151

152+
/**
153+
* Returns information about a commit, including commit message and committer information.
154+
*
155+
* @see https://docs.aws.amazon.com/codecommit/latest/APIReference/API_GetCommit.html
156+
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-codecommit-2015-04-13.html#getcommit
157+
*
158+
* @param array{
159+
* repositoryName: string,
160+
* commitId: string,
161+
* @region?: string,
162+
* }|GetCommitInput $input
163+
*
164+
* @throws RepositoryNameRequiredException
165+
* @throws InvalidRepositoryNameException
166+
* @throws RepositoryDoesNotExistException
167+
* @throws CommitIdRequiredException
168+
* @throws InvalidCommitIdException
169+
* @throws CommitIdDoesNotExistException
170+
* @throws EncryptionIntegrityChecksFailedException
171+
* @throws EncryptionKeyAccessDeniedException
172+
* @throws EncryptionKeyDisabledException
173+
* @throws EncryptionKeyNotFoundException
174+
* @throws EncryptionKeyUnavailableException
175+
*/
176+
public function getCommit($input): GetCommitOutput
177+
{
178+
$input = GetCommitInput::create($input);
179+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'GetCommit', 'region' => $input->getRegion(), 'exceptionMapping' => [
180+
'RepositoryNameRequiredException' => RepositoryNameRequiredException::class,
181+
'InvalidRepositoryNameException' => InvalidRepositoryNameException::class,
182+
'RepositoryDoesNotExistException' => RepositoryDoesNotExistException::class,
183+
'CommitIdRequiredException' => CommitIdRequiredException::class,
184+
'InvalidCommitIdException' => InvalidCommitIdException::class,
185+
'CommitIdDoesNotExistException' => CommitIdDoesNotExistException::class,
186+
'EncryptionIntegrityChecksFailedException' => EncryptionIntegrityChecksFailedException::class,
187+
'EncryptionKeyAccessDeniedException' => EncryptionKeyAccessDeniedException::class,
188+
'EncryptionKeyDisabledException' => EncryptionKeyDisabledException::class,
189+
'EncryptionKeyNotFoundException' => EncryptionKeyNotFoundException::class,
190+
'EncryptionKeyUnavailableException' => EncryptionKeyUnavailableException::class,
191+
]]));
192+
193+
return new GetCommitOutput($response);
194+
}
195+
148196
/**
149197
* Returns information about the differences in a valid commit specifier (such as a branch, tag, HEAD, commit ID, or
150198
* other fully qualified reference). Results can be limited to a specified path.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace AsyncAws\CodeCommit\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
7+
/**
8+
* The specified commit ID does not exist.
9+
*/
10+
final class CommitIdDoesNotExistException extends ClientException
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace AsyncAws\CodeCommit\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
7+
/**
8+
* A commit ID was not specified.
9+
*/
10+
final class CommitIdRequiredException extends ClientException
11+
{
12+
}

src/Input/GetCommitInput.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace AsyncAws\CodeCommit\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
10+
/**
11+
* Represents the input of a get commit operation.
12+
*/
13+
final class GetCommitInput extends Input
14+
{
15+
/**
16+
* The name of the repository to which the commit was made.
17+
*
18+
* @required
19+
*
20+
* @var string|null
21+
*/
22+
private $repositoryName;
23+
24+
/**
25+
* The commit ID. Commit IDs are the full SHA ID of the commit.
26+
*
27+
* @required
28+
*
29+
* @var string|null
30+
*/
31+
private $commitId;
32+
33+
/**
34+
* @param array{
35+
* repositoryName?: string,
36+
* commitId?: string,
37+
* @region?: string,
38+
* } $input
39+
*/
40+
public function __construct(array $input = [])
41+
{
42+
$this->repositoryName = $input['repositoryName'] ?? null;
43+
$this->commitId = $input['commitId'] ?? null;
44+
parent::__construct($input);
45+
}
46+
47+
public static function create($input): self
48+
{
49+
return $input instanceof self ? $input : new self($input);
50+
}
51+
52+
public function getCommitId(): ?string
53+
{
54+
return $this->commitId;
55+
}
56+
57+
public function getRepositoryName(): ?string
58+
{
59+
return $this->repositoryName;
60+
}
61+
62+
/**
63+
* @internal
64+
*/
65+
public function request(): Request
66+
{
67+
// Prepare headers
68+
$headers = [
69+
'Content-Type' => 'application/x-amz-json-1.1',
70+
'X-Amz-Target' => 'CodeCommit_20150413.GetCommit',
71+
];
72+
73+
// Prepare query
74+
$query = [];
75+
76+
// Prepare URI
77+
$uriString = '/';
78+
79+
// Prepare Body
80+
$bodyPayload = $this->requestBody();
81+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304);
82+
83+
// Return the Request
84+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
85+
}
86+
87+
public function setCommitId(?string $value): self
88+
{
89+
$this->commitId = $value;
90+
91+
return $this;
92+
}
93+
94+
public function setRepositoryName(?string $value): self
95+
{
96+
$this->repositoryName = $value;
97+
98+
return $this;
99+
}
100+
101+
private function requestBody(): array
102+
{
103+
$payload = [];
104+
if (null === $v = $this->repositoryName) {
105+
throw new InvalidArgument(sprintf('Missing parameter "repositoryName" for "%s". The value cannot be null.', __CLASS__));
106+
}
107+
$payload['repositoryName'] = $v;
108+
if (null === $v = $this->commitId) {
109+
throw new InvalidArgument(sprintf('Missing parameter "commitId" for "%s". The value cannot be null.', __CLASS__));
110+
}
111+
$payload['commitId'] = $v;
112+
113+
return $payload;
114+
}
115+
}

src/Result/GetCommitOutput.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace AsyncAws\CodeCommit\Result;
4+
5+
use AsyncAws\CodeCommit\ValueObject\Commit;
6+
use AsyncAws\CodeCommit\ValueObject\UserInfo;
7+
use AsyncAws\Core\Response;
8+
use AsyncAws\Core\Result;
9+
10+
/**
11+
* Represents the output of a get commit operation.
12+
*/
13+
class GetCommitOutput extends Result
14+
{
15+
/**
16+
* A commit data type object that contains information about the specified commit.
17+
*/
18+
private $commit;
19+
20+
public function getCommit(): Commit
21+
{
22+
$this->initialize();
23+
24+
return $this->commit;
25+
}
26+
27+
protected function populateResult(Response $response): void
28+
{
29+
$data = $response->toArray();
30+
31+
$this->commit = $this->populateResultCommit($data['commit']);
32+
}
33+
34+
private function populateResultCommit(array $json): Commit
35+
{
36+
return new Commit([
37+
'commitId' => isset($json['commitId']) ? (string) $json['commitId'] : null,
38+
'treeId' => isset($json['treeId']) ? (string) $json['treeId'] : null,
39+
'parents' => !isset($json['parents']) ? null : $this->populateResultParentList($json['parents']),
40+
'message' => isset($json['message']) ? (string) $json['message'] : null,
41+
'author' => empty($json['author']) ? null : $this->populateResultUserInfo($json['author']),
42+
'committer' => empty($json['committer']) ? null : $this->populateResultUserInfo($json['committer']),
43+
'additionalData' => isset($json['additionalData']) ? (string) $json['additionalData'] : null,
44+
]);
45+
}
46+
47+
/**
48+
* @return string[]
49+
*/
50+
private function populateResultParentList(array $json): array
51+
{
52+
$items = [];
53+
foreach ($json as $item) {
54+
$a = isset($item) ? (string) $item : null;
55+
if (null !== $a) {
56+
$items[] = $a;
57+
}
58+
}
59+
60+
return $items;
61+
}
62+
63+
private function populateResultUserInfo(array $json): UserInfo
64+
{
65+
return new UserInfo([
66+
'name' => isset($json['name']) ? (string) $json['name'] : null,
67+
'email' => isset($json['email']) ? (string) $json['email'] : null,
68+
'date' => isset($json['date']) ? (string) $json['date'] : null,
69+
]);
70+
}
71+
}

src/ValueObject/Commit.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
namespace AsyncAws\CodeCommit\ValueObject;
4+
5+
/**
6+
* A commit data type object that contains information about the specified commit.
7+
*/
8+
final class Commit
9+
{
10+
/**
11+
* The full SHA ID of the specified commit.
12+
*/
13+
private $commitId;
14+
15+
/**
16+
* Tree information for the specified commit.
17+
*/
18+
private $treeId;
19+
20+
/**
21+
* A list of parent commits for the specified commit. Each parent commit ID is the full commit ID.
22+
*/
23+
private $parents;
24+
25+
/**
26+
* The commit message associated with the specified commit.
27+
*/
28+
private $message;
29+
30+
/**
31+
* Information about the author of the specified commit. Information includes the date in timestamp format with GMT
32+
* offset, the name of the author, and the email address for the author, as configured in Git.
33+
*/
34+
private $author;
35+
36+
/**
37+
* Information about the person who committed the specified commit, also known as the committer. Information includes
38+
* the date in timestamp format with GMT offset, the name of the committer, and the email address for the committer, as
39+
* configured in Git.
40+
*/
41+
private $committer;
42+
43+
/**
44+
* Any other data associated with the specified commit.
45+
*/
46+
private $additionalData;
47+
48+
/**
49+
* @param array{
50+
* commitId?: null|string,
51+
* treeId?: null|string,
52+
* parents?: null|string[],
53+
* message?: null|string,
54+
* author?: null|UserInfo|array,
55+
* committer?: null|UserInfo|array,
56+
* additionalData?: null|string,
57+
* } $input
58+
*/
59+
public function __construct(array $input)
60+
{
61+
$this->commitId = $input['commitId'] ?? null;
62+
$this->treeId = $input['treeId'] ?? null;
63+
$this->parents = $input['parents'] ?? null;
64+
$this->message = $input['message'] ?? null;
65+
$this->author = isset($input['author']) ? UserInfo::create($input['author']) : null;
66+
$this->committer = isset($input['committer']) ? UserInfo::create($input['committer']) : null;
67+
$this->additionalData = $input['additionalData'] ?? null;
68+
}
69+
70+
public static function create($input): self
71+
{
72+
return $input instanceof self ? $input : new self($input);
73+
}
74+
75+
public function getAdditionalData(): ?string
76+
{
77+
return $this->additionalData;
78+
}
79+
80+
public function getAuthor(): ?UserInfo
81+
{
82+
return $this->author;
83+
}
84+
85+
public function getCommitId(): ?string
86+
{
87+
return $this->commitId;
88+
}
89+
90+
public function getCommitter(): ?UserInfo
91+
{
92+
return $this->committer;
93+
}
94+
95+
public function getMessage(): ?string
96+
{
97+
return $this->message;
98+
}
99+
100+
/**
101+
* @return string[]
102+
*/
103+
public function getParents(): array
104+
{
105+
return $this->parents ?? [];
106+
}
107+
108+
public function getTreeId(): ?string
109+
{
110+
return $this->treeId;
111+
}
112+
}

0 commit comments

Comments
 (0)