createPullRequestApprovalRule method

Future<CreatePullRequestApprovalRuleOutput> createPullRequestApprovalRule({
  1. required String approvalRuleContent,
  2. required String approvalRuleName,
  3. required String pullRequestId,
})

Creates an approval rule for a pull request.

May throw ApprovalRuleNameRequiredException. May throw InvalidApprovalRuleNameException. May throw ApprovalRuleNameAlreadyExistsException. May throw ApprovalRuleContentRequiredException. May throw InvalidApprovalRuleContentException. May throw NumberOfRulesExceededException. May throw PullRequestDoesNotExistException. May throw InvalidPullRequestIdException. May throw PullRequestIdRequiredException. May throw PullRequestAlreadyClosedException. May throw EncryptionIntegrityChecksFailedException. May throw EncryptionKeyAccessDeniedException. May throw EncryptionKeyDisabledException. May throw EncryptionKeyNotFoundException. May throw EncryptionKeyUnavailableException.

Parameter approvalRuleContent : The content of the approval rule, including the number of approvals needed and the structure of an approval pool defined for approvals, if any. For more information about approval pools, see the AWS CodeCommit User Guide.

  • CodeCommitApprovers: This option only requires an AWS account and a resource. It can be used for both IAM users and federated access users whose name matches the provided resource name. This is a very powerful option that offers a great deal of flexibility. For example, if you specify the AWS account 123456789012 and Mary_Major, all of the following would be counted as approvals coming from that user:
    • An IAM user in the account (arn:aws:iam::123456789012:user/Mary_Major)
    • A federated user identified in IAM as Mary_Major (arn:aws:sts::123456789012:federated-user/Mary_Major)
    This option does not recognize an active session of someone assuming the role of CodeCommitReview with a role session name of Mary_Major (arn:aws:sts::123456789012:assumed-role/CodeCommitReview/Mary_Major) unless you include a wildcard (*Mary_Major).
  • Fully qualified ARN: This option allows you to specify the fully qualified Amazon Resource Name (ARN) of the IAM user or role.
For more information about IAM ARNs, wildcards, and formats, see IAM Identifiers in the IAM User Guide.

Parameter approvalRuleName : The name for the approval rule.

Parameter pullRequestId : The system-generated ID of the pull request for which you want to create the approval rule.

Implementation

Future<CreatePullRequestApprovalRuleOutput> createPullRequestApprovalRule({
  required String approvalRuleContent,
  required String approvalRuleName,
  required String pullRequestId,
}) async {
  ArgumentError.checkNotNull(approvalRuleContent, 'approvalRuleContent');
  _s.validateStringLength(
    'approvalRuleContent',
    approvalRuleContent,
    1,
    3000,
    isRequired: true,
  );
  ArgumentError.checkNotNull(approvalRuleName, 'approvalRuleName');
  _s.validateStringLength(
    'approvalRuleName',
    approvalRuleName,
    1,
    100,
    isRequired: true,
  );
  ArgumentError.checkNotNull(pullRequestId, 'pullRequestId');
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'CodeCommit_20150413.CreatePullRequestApprovalRule'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'approvalRuleContent': approvalRuleContent,
      'approvalRuleName': approvalRuleName,
      'pullRequestId': pullRequestId,
    },
  );

  return CreatePullRequestApprovalRuleOutput.fromJson(jsonResponse.body);
}