Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
meyertst-aws committed Apr 29, 2024
1 parent 74c7acb commit 62548a6
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 51 deletions.
48 changes: 48 additions & 0 deletions .doc_gen/metadata/codebuild_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,51 @@ codebuild_CreateProject:
- javascript.v3.codebuild.actions.CreateProject
services:
codebuild: {CreateProject}
codebuild_ListBuilds:
title: List &ACB; builds
title_abbrev: List builds
synopsis: list &ACB; builds.
category:
languages:
C++:
versions:
- sdk_version: 1
github: cpp/example_code/codebuild
excerpts:
- description:
snippet_tags:
- cpp.example_code.codebuild.ListBuilds
services:
codebuild: {ListBuilds}
codebuild_ListProjects:
title: List &ACB; projects
title_abbrev: List projects
synopsis: list &ACB; projects.
category:
languages:
C++:
versions:
- sdk_version: 1
github: cpp/example_code/codebuild
excerpts:
- description:
snippet_tags:
- cpp.example_code.codebuild.ListProjects
services:
codebuild: {ListProjects}
codebuild_StartBuild:
title: Start an &ACB; build
title_abbrev: Start a build
synopsis: start an &ACB; build.
category:
languages:
C++:
versions:
- sdk_version: 1
github: cpp/example_code/codebuild
excerpts:
- description:
snippet_tags:
- cpp.example_code.codebuild.StartBuild
services:
codebuild: {StartBuild}
9 changes: 9 additions & 0 deletions cpp/example_code/codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ Next, for information on code example structures and how to build and run the ex
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->

### Single actions

Code excerpts that show you how to call individual service functions.

- [List builds](list_builds.cpp#L25) (`ListBuilds`)
- [List projects](list_projects.cpp#L23) (`ListProjects`)
- [Start a build](start_build.cpp#L22) (`StartBuild`)


<!--custom.examples.start-->
<!--custom.examples.end-->

Expand Down
9 changes: 6 additions & 3 deletions cpp/example_code/codebuild/codebuild_samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ namespace AwsDoc {
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool startBuild(const Aws::String &projectName, const Aws::Client::ClientConfiguration &clientConfiguration);
bool startBuild(const Aws::String &projectName,
const Aws::Client::ClientConfiguration &clientConfiguration);

//! List the CodeBuild builds.
/*!
\param sortType: 'SortOrderType' type.
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool listBuilds(Aws::CodeBuild::Model::SortOrderType sortType, const Aws::Client::ClientConfiguration &clientConfiguration);
bool listBuilds(Aws::CodeBuild::Model::SortOrderType sortType,
const Aws::Client::ClientConfiguration &clientConfiguration);

//! List the CodeBuild projects.
/*!
\param sortType: 'SortOrderType' type.
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool listProjects(Aws::CodeBuild::Model::SortOrderType sortType, const Aws::Client::ClientConfiguration &clientConfiguration);
bool listProjects(Aws::CodeBuild::Model::SortOrderType sortType,
const Aws::Client::ClientConfiguration &clientConfiguration);
} // CodeBuild
} // AwsDoc

Expand Down
22 changes: 13 additions & 9 deletions cpp/example_code/codebuild/list_builds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
*
**/

// snippet-start:[cpp.example_code.codebuild.StartBuild]
// snippet-start:[cpp.example_code.codebuild.ListBuilds]
//! List the CodeBuild builds.
/*!
\param sortType: 'SortOrderType' type.
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc::CodeBuild::listBuilds(Aws::CodeBuild::Model::SortOrderType sortType, const Aws::Client::ClientConfiguration &clientConfiguration)
{
bool AwsDoc::CodeBuild::listBuilds(Aws::CodeBuild::Model::SortOrderType sortType,
const Aws::Client::ClientConfiguration &clientConfiguration) {
Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration);

Aws::CodeBuild::Model::ListBuildsRequest listBuildsRequest;
Expand All @@ -43,30 +43,34 @@ bool AwsDoc::CodeBuild::listBuilds(Aws::CodeBuild::Model::SortOrderType sortType
listBuildsRequest.SetNextToken(nextToken);
}

Aws::CodeBuild::Model::ListBuildsOutcome listBuildsOutcome = codeBuildClient.ListBuilds(listBuildsRequest);
Aws::CodeBuild::Model::ListBuildsOutcome listBuildsOutcome = codeBuildClient.ListBuilds(
listBuildsRequest);

if (listBuildsOutcome.IsSuccess()) {
std::cout << "Information about each build:" << std::endl;
Aws::CodeBuild::Model::BatchGetBuildsRequest getBuildsRequest;
getBuildsRequest.SetIds(listBuildsOutcome.GetResult().GetIds());
Aws::CodeBuild::Model::BatchGetBuildsOutcome getBuildsOutcome = codeBuildClient.BatchGetBuilds(getBuildsRequest);
Aws::CodeBuild::Model::BatchGetBuildsOutcome getBuildsOutcome = codeBuildClient.BatchGetBuilds(
getBuildsRequest);

if (getBuildsOutcome.IsSuccess()) {
const Aws::Vector<Aws::CodeBuild::Model::Build>& builds = getBuildsOutcome.GetResult().GetBuilds();
const Aws::Vector<Aws::CodeBuild::Model::Build> &builds = getBuildsOutcome.GetResult().GetBuilds();
std::cout << builds.size() << " build(s) found." << std::endl;
for (auto val: builds) {
std::cout << val.GetId() << std::endl;
}
}
else {
std::cout << "Error getting builds" << getBuildsOutcome.GetError().GetMessage() << std::endl;
std::cout << "Error getting builds"
<< getBuildsOutcome.GetError().GetMessage() << std::endl;
return false;
}
nextToken = listBuildsOutcome.GetResult().GetNextToken();
}

else {
std::cerr << "Error listing builds" << listBuildsOutcome.GetError().GetMessage()
std::cerr << "Error listing builds"
<< listBuildsOutcome.GetError().GetMessage()
<< std::endl;
return false;
}
Expand All @@ -75,7 +79,7 @@ bool AwsDoc::CodeBuild::listBuilds(Aws::CodeBuild::Model::SortOrderType sortType

return true;
}
// snippet-end:[cpp.example_code.codebuild.StartBuild]
// snippet-end:[cpp.example_code.codebuild.ListBuilds]

/*
*
Expand Down
12 changes: 7 additions & 5 deletions cpp/example_code/codebuild/list_projects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc::CodeBuild::listProjects(Aws::CodeBuild::Model::SortOrderType sortType, const Aws::Client::ClientConfiguration &clientConfiguration) {
bool AwsDoc::CodeBuild::listProjects(Aws::CodeBuild::Model::SortOrderType sortType,
const Aws::Client::ClientConfiguration &clientConfiguration) {
Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration);

Aws::CodeBuild::Model::ListProjectsRequest listProjectsRequest;
Expand All @@ -41,11 +42,12 @@ bool AwsDoc::CodeBuild::listProjects(Aws::CodeBuild::Model::SortOrderType sortTy
listProjectsRequest.SetNextToken(nextToken);
}

Aws::CodeBuild::Model::ListProjectsOutcome outcome = codeBuildClient.ListProjects(listProjectsRequest);
Aws::CodeBuild::Model::ListProjectsOutcome outcome = codeBuildClient.ListProjects(
listProjectsRequest);

if (outcome.IsSuccess()) {
const Aws::Vector<Aws::String> &projects = outcome.GetResult().GetProjects();
allProjects.insert(allProjects.end(), projects.begin(), projects.end());
allProjects.insert(allProjects.end(), projects.begin(), projects.end());
nextToken = outcome.GetResult().GetNextToken();
}

Expand All @@ -55,9 +57,9 @@ bool AwsDoc::CodeBuild::listProjects(Aws::CodeBuild::Model::SortOrderType sortTy
}

} while (!nextToken.empty());

std::cout << allProjects.size() << " project(s) found." << std::endl;
for (auto project : allProjects) {
for (auto project: allProjects) {
std::cout << project << std::endl;
}

Expand Down
34 changes: 17 additions & 17 deletions cpp/example_code/codebuild/start_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc::CodeBuild::startBuild(const Aws::String &projectName, const Aws::Client::ClientConfiguration &clientConfiguration)
{
Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration);
bool AwsDoc::CodeBuild::startBuild(const Aws::String &projectName,
const Aws::Client::ClientConfiguration &clientConfiguration) {
Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration);

Aws::CodeBuild::Model::StartBuildRequest startBuildRequest;
startBuildRequest.SetProjectName(projectName);
Aws::CodeBuild::Model::StartBuildRequest startBuildRequest;
startBuildRequest.SetProjectName(projectName);

Aws::CodeBuild::Model::StartBuildOutcome outcome = codeBuildClient.StartBuild(startBuildRequest);
Aws::CodeBuild::Model::StartBuildOutcome outcome = codeBuildClient.StartBuild(
startBuildRequest);

if (outcome.IsSuccess())
{
std::cout << "Successfully started build" << std::endl;
std::cout << "Build ID: " << outcome.GetResult().GetBuild().GetId() << std::endl;
}
if (outcome.IsSuccess()) {
std::cout << "Successfully started build" << std::endl;
std::cout << "Build ID: " << outcome.GetResult().GetBuild().GetId()
<< std::endl;
}

else
{
std::cerr << "Error starting build" << outcome.GetError().GetMessage()
<< std::endl;
}
else {
std::cerr << "Error starting build" << outcome.GetError().GetMessage()
<< std::endl;
}

return outcome.IsSuccess();
return outcome.IsSuccess();
}
// snippet-end:[cpp.example_code.codebuild.StartBuild]

Expand Down
11 changes: 6 additions & 5 deletions cpp/example_code/codebuild/tests/gtest_list_builds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

namespace AwsDocTest {
// NOLINTNEXTLINE(readability-named-parameter)
TEST_F(CodeBuild_GTests, list_builds_2_) {
TEST_F(CodeBuild_GTests, list_builds_2_
) {

auto result = AwsDoc::CodeBuild::listBuilds(
Aws::CodeBuild::Model::SortOrderType::ASCENDING, *s_clientConfig);
ASSERT_TRUE(result);
}
auto result = AwsDoc::CodeBuild::listBuilds(
Aws::CodeBuild::Model::SortOrderType::ASCENDING, *s_clientConfig);
ASSERT_TRUE(result);
}
} // namespace AwsDocTest
11 changes: 6 additions & 5 deletions cpp/example_code/codebuild/tests/gtest_list_projects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

namespace AwsDocTest {
// NOLINTNEXTLINE(readability-named-parameter)
TEST_F(CodeBuild_GTests, list_projects_2_) {
TEST_F(CodeBuild_GTests, list_projects_2_
) {

auto result = AwsDoc::CodeBuild::listProjects(
Aws::CodeBuild::Model::SortOrderType::ASCENDING, *s_clientConfig);
ASSERT_TRUE(result);
}
auto result = AwsDoc::CodeBuild::listProjects(
Aws::CodeBuild::Model::SortOrderType::ASCENDING, *s_clientConfig);
ASSERT_TRUE(result);
}
} // namespace AwsDocTest
21 changes: 14 additions & 7 deletions cpp/example_code/codebuild/tests/gtest_start_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@

namespace AwsDocTest {
// NOLINTNEXTLINE(readability-named-parameter)
TEST_F(CodeBuild_GTests, start_build_3_) {
MockHTTP mockHttp;
bool result = mockHttp.addResponseWithBody("mock_input/StartBuild.json");
ASSERT_TRUE(result) << preconditionError() << std::endl;
TEST_F(CodeBuild_GTests, start_build_3_
) {
MockHTTP mockHttp;
bool result = mockHttp.addResponseWithBody("mock_input/StartBuild.json");
ASSERT_TRUE(result)
<<

result = AwsDoc::CodeBuild::startBuild("test-project", *s_clientConfig);
ASSERT_TRUE(result);
}
preconditionError()

<<
std::endl;

result = AwsDoc::CodeBuild::startBuild("test-project", *s_clientConfig);
ASSERT_TRUE(result);
}
} // namespace AwsDocTest

0 comments on commit 62548a6

Please sign in to comment.