use of software.amazon.awssdk.services.codecommit.model.CodeCommitException in project aws-doc-sdk-examples by awsdocs.
the class GetPullRequest method getPR.
// snippet-start:[codecommit.java2.get_pull_request.main]
public static void getPR(CodeCommitClient codeCommitClient, String pullRequestId) {
try {
GetPullRequestRequest pullRequestRequest = GetPullRequestRequest.builder().pullRequestId(pullRequestId).build();
GetPullRequestResponse pullResponse = codeCommitClient.getPullRequest(pullRequestRequest);
System.out.println("The title of the pull request is " + pullResponse.pullRequest().title());
System.out.println("The pull request status is " + pullResponse.pullRequest().pullRequestStatus());
System.out.println("The pull request id is " + pullResponse.pullRequest().pullRequestId());
} catch (CodeCommitException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.codecommit.model.CodeCommitException in project aws-doc-sdk-examples by awsdocs.
the class PutFile method uploadFile.
// snippet-start:[codecommit.java2.put_file.main]
public static void uploadFile(CodeCommitClient codeCommitClient, String filePath, String repoName, String branchName, String email, String name, String repoPath, String commitId) {
try {
// Create an SdkBytes object that represents the file to upload
File myFile = new File(filePath);
InputStream is = new FileInputStream(myFile);
SdkBytes fileToUpload = SdkBytes.fromInputStream(is);
PutFileRequest fileRequest = PutFileRequest.builder().fileContent(fileToUpload).repositoryName(repoName).commitMessage("Uploaded via the Java API").branchName(branchName).filePath(repoPath).parentCommitId(commitId).email(email).name(name).build();
// Upload file to the branch
PutFileResponse fileResponse = codeCommitClient.putFile(fileRequest);
System.out.println("The commit ID is " + fileResponse.commitId());
} catch (CodeCommitException | FileNotFoundException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.codecommit.model.CodeCommitException in project aws-doc-sdk-examples by awsdocs.
the class GetMergeOptions method getMergeValues.
// snippet-start:[codecommit.java2.get_merge_options.main]
public static String getMergeValues(CodeCommitClient codeCommitClient, String repoName, String destinationReference, String sourceReference) {
try {
GetMergeOptionsRequest optionsRequest = GetMergeOptionsRequest.builder().repositoryName(repoName).destinationCommitSpecifier(destinationReference).sourceCommitSpecifier(sourceReference).build();
GetMergeOptionsResponse response = codeCommitClient.getMergeOptions(optionsRequest);
return response.baseCommitId();
} catch (CodeCommitException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.codecommit.model.CodeCommitException in project aws-doc-sdk-examples by awsdocs.
the class CreatePullRequest method createPR.
// snippet-start:[codecommit.java2.create_pr.main]
public static String createPR(CodeCommitClient codeCommitClient, String repoName, String destinationReference, String sourceReference) {
try {
// Create a Target object that contains the destination and source
Target target = Target.builder().repositoryName(repoName).destinationReference(destinationReference).sourceReference(sourceReference).build();
List<Target> myList = new ArrayList<>();
myList.add(target);
CreatePullRequestRequest pullRequestRequest = CreatePullRequestRequest.builder().description("A Pull request created by the Java API").title("Example Pull Request").targets(myList).build();
CreatePullRequestResponse requestResponse = codeCommitClient.createPullRequest(pullRequestRequest);
return requestResponse.pullRequest().pullRequestId();
} catch (CodeCommitException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.codecommit.model.CodeCommitException in project aws-doc-sdk-examples by awsdocs.
the class DeleteBranch method deleteSpecificBranch.
// snippet-start:[codecommit.java2.del_branch.main]
public static void deleteSpecificBranch(CodeCommitClient codeCommitClient, String repoName, String branchName) {
try {
DeleteBranchRequest branchRequest = DeleteBranchRequest.builder().branchName(branchName).repositoryName(repoName).build();
codeCommitClient.deleteBranch(branchRequest);
System.out.println("The " + branchName + " branch was deleted!");
} catch (CodeCommitException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations