Skip to content

Commit

Permalink
Added CLI bitbucket pull feature (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsKedar authored Oct 3, 2024
1 parent 77deea1 commit 1046d95
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/main/java/com/checkmarx/flow/CxFlowRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,32 @@ private void commandLineRunner(ApplicationArguments args) throws ExitThrowable {
break;
case BITBUCKETPULL:
case bitbucketserverpull:
log.info("BitBucket Pull not currently supported from command line");
exit(ExitCode.BUILD_INTERRUPTED_INTENTIONALLY);
if(usingBitBucketCloud){
bugType = BugTracker.Type.BITBUCKETPULL;
bt = BugTracker.builder()
.type(bugType)
.build();
repoType = ScanRequest.Repository.BITBUCKET;
if (ScanUtils.empty(namespace) || ScanUtils.empty(repoName) || ScanUtils.empty(mergeId)) {
log.error("Namespace/Repo/MergeId must be provided for Bitbucket pull bug tracking");
exit(ExitCode.BUILD_INTERRUPTED_INTENTIONALLY);
}
mergeNoteUri = bitBucketProperties.getCloudMergeNoteUri(namespace, repoName, mergeId);
}else if(usingBitBucketServer) {
bugType = BugTracker.Type.BITBUCKETSERVERPULL;
bt = BugTracker.builder()
.type(bugType)
.build();
repoType = ScanRequest.Repository.BITBUCKETSERVER;
if (ScanUtils.empty(namespace) || ScanUtils.empty(repoName) || ScanUtils.empty(mergeId)) {
log.error("Namespace/Repo/MergeId must be provided for Bitbucket-server pull bug tracking");
exit(ExitCode.BUILD_INTERRUPTED_INTENTIONALLY);
}
mergeNoteUri = bitBucketProperties.getServerMergeNoteUri(namespace, repoName, mergeId);
}else{
log.info("Please provide cli parameters --bb for bitbucket cloud or --bbs for bitbucket server");
exit(ExitCode.BUILD_INTERRUPTED_INTENTIONALLY);
}
break;
case EMAIL:
bugType = BugTracker.Type.EMAIL;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/checkmarx/flow/config/BitBucketProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ public String getGitUri(String namespace, String repoName) {
String format = "%s/%s/%s.git";
return String.format(format, getUrl(), namespace, repoName);
}

public String getCloudMergeNoteUri(String namespace, String repo, String mergeId){
String format = "%s/%s/repositories/%s/%s/pullRequests/%s/comments";
return String.format(format, getApiUrl(),getApiPath(), namespace, repo, mergeId);
//https://api.bitbucket.org/2.0/repositories/{namespace}/{repo}/pullRequests/{merge-id}/comments
}

public String getServerMergeNoteUri(String namespace, String repo, String mergeId){
String format = "%s/%s/projects/%s/repos/%s/pull-requests/%s/comments";
return String.format(format, getApiUrl(),getApiPath() ,namespace, repo, mergeId);
//http://localhost:8080/projects/{namespace}/repos/{repo}/pull-requests/{merge-id}/comments
}
}

0 comments on commit 1046d95

Please sign in to comment.