CreateRepositoryProtectedBranchResult.cc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/codeup/model/CreateRepositoryProtectedBranchResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Codeup;
  19. using namespace AlibabaCloud::Codeup::Model;
  20. CreateRepositoryProtectedBranchResult::CreateRepositoryProtectedBranchResult() :
  21. ServiceResult()
  22. {}
  23. CreateRepositoryProtectedBranchResult::CreateRepositoryProtectedBranchResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. CreateRepositoryProtectedBranchResult::~CreateRepositoryProtectedBranchResult()
  29. {}
  30. void CreateRepositoryProtectedBranchResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto resultNode = value["Result"];
  37. if(!resultNode["Id"].isNull())
  38. result_.id = std::stol(resultNode["Id"].asString());
  39. if(!resultNode["Branch"].isNull())
  40. result_.branch = resultNode["Branch"].asString();
  41. auto mergeRequestSettingNode = resultNode["MergeRequestSetting"];
  42. if(!mergeRequestSettingNode["Required"].isNull())
  43. result_.mergeRequestSetting.required = mergeRequestSettingNode["Required"].asString() == "true";
  44. if(!mergeRequestSettingNode["MergeRequestMode"].isNull())
  45. result_.mergeRequestSetting.mergeRequestMode = mergeRequestSettingNode["MergeRequestMode"].asString();
  46. if(!mergeRequestSettingNode["AllowSelfApproval"].isNull())
  47. result_.mergeRequestSetting.allowSelfApproval = mergeRequestSettingNode["AllowSelfApproval"].asString() == "true";
  48. if(!mergeRequestSettingNode["IsRequireDiscussionProcessed"].isNull())
  49. result_.mergeRequestSetting.isRequireDiscussionProcessed = mergeRequestSettingNode["IsRequireDiscussionProcessed"].asString() == "true";
  50. if(!mergeRequestSettingNode["IsResetApprovalWhenNewPush"].isNull())
  51. result_.mergeRequestSetting.isResetApprovalWhenNewPush = mergeRequestSettingNode["IsResetApprovalWhenNewPush"].asString() == "true";
  52. if(!mergeRequestSettingNode["MinimualApproval"].isNull())
  53. result_.mergeRequestSetting.minimualApproval = std::stoi(mergeRequestSettingNode["MinimualApproval"].asString());
  54. auto allAllowMergeRequestRoles = mergeRequestSettingNode["AllowMergeRequestRoles"]["AllowMergeRequestRoles"];
  55. for (auto value : allAllowMergeRequestRoles)
  56. result_.mergeRequestSetting.allowMergeRequestRoles.push_back(value.asString());
  57. auto allDefaultAssignees = mergeRequestSettingNode["DefaultAssignees"]["DefaultAssignees"];
  58. for (auto value : allDefaultAssignees)
  59. result_.mergeRequestSetting.defaultAssignees.push_back(value.asString());
  60. auto testSettingNode = resultNode["TestSetting"];
  61. if(!testSettingNode["Required"].isNull())
  62. result_.testSetting.required = testSettingNode["Required"].asString() == "true";
  63. auto codingGuidelinesDetectionNode = testSettingNode["CodingGuidelinesDetection"];
  64. if(!codingGuidelinesDetectionNode["Enabled"].isNull())
  65. result_.testSetting.codingGuidelinesDetection.enabled = codingGuidelinesDetectionNode["Enabled"].asString() == "true";
  66. if(!codingGuidelinesDetectionNode["Message"].isNull())
  67. result_.testSetting.codingGuidelinesDetection.message = codingGuidelinesDetectionNode["Message"].asString();
  68. auto sensitiveInfoDetectionNode = testSettingNode["SensitiveInfoDetection"];
  69. if(!sensitiveInfoDetectionNode["Enabled"].isNull())
  70. result_.testSetting.sensitiveInfoDetection.enabled = sensitiveInfoDetectionNode["Enabled"].asString() == "true";
  71. if(!sensitiveInfoDetectionNode["Message"].isNull())
  72. result_.testSetting.sensitiveInfoDetection.message = sensitiveInfoDetectionNode["Message"].asString();
  73. auto checkConfigNode = testSettingNode["CheckConfig"];
  74. auto allCheckItemsNode = checkConfigNode["CheckItems"]["CheckItemsItem"];
  75. for (auto checkConfigNodeCheckItemsCheckItemsItem : allCheckItemsNode)
  76. {
  77. Result::TestSetting::CheckConfig::CheckItemsItem checkItemsItemObject;
  78. if(!checkConfigNodeCheckItemsCheckItemsItem["Name"].isNull())
  79. checkItemsItemObject.name = checkConfigNodeCheckItemsCheckItemsItem["Name"].asString();
  80. if(!checkConfigNodeCheckItemsCheckItemsItem["Required"].isNull())
  81. checkItemsItemObject.required = checkConfigNodeCheckItemsCheckItemsItem["Required"].asString() == "true";
  82. result_.testSetting.checkConfig.checkItems.push_back(checkItemsItemObject);
  83. }
  84. auto allAllowPushRoles = resultNode["AllowPushRoles"]["AllowPushRoles"];
  85. for (auto value : allAllowPushRoles)
  86. result_.allowPushRoles.push_back(value.asString());
  87. auto allAllowMergeRoles = resultNode["AllowMergeRoles"]["AllowMergeRoles"];
  88. for (auto value : allAllowMergeRoles)
  89. result_.allowMergeRoles.push_back(value.asString());
  90. if(!value["ErrorCode"].isNull())
  91. errorCode_ = value["ErrorCode"].asString();
  92. if(!value["ErrorMessage"].isNull())
  93. errorMessage_ = value["ErrorMessage"].asString();
  94. if(!value["Success"].isNull())
  95. success_ = value["Success"].asString() == "true";
  96. }
  97. std::string CreateRepositoryProtectedBranchResult::getErrorCode()const
  98. {
  99. return errorCode_;
  100. }
  101. std::string CreateRepositoryProtectedBranchResult::getErrorMessage()const
  102. {
  103. return errorMessage_;
  104. }
  105. bool CreateRepositoryProtectedBranchResult::getSuccess()const
  106. {
  107. return success_;
  108. }
  109. CreateRepositoryProtectedBranchResult::Result CreateRepositoryProtectedBranchResult::getResult()const
  110. {
  111. return result_;
  112. }