How to Retrieve SCM Information from a Bamboo Plugin?

Hi,

I am working on a Bamboo plugin and need to retrieve specific information from the SCM.

(1) If a branch has a pull request, I want to get the source branch, target branch, pull request number, and repository name. So far, I was able to retrieve the repository name and source branch using the following code:

CommonContext buildContext = taskContext.getCommonContext();

List<PlanRepositoryDefinition> repositories = buildContext.getVcsRepositories();
for (PlanRepositoryDefinition repo : repositories) {
    String repoName = repo.getVcsLocation().getConfiguration().get("repository.bitbucket.repository");
    String branch = repo.getBranch().getConfiguration().get("repository.bitbucket.branch");

    System.out.println("Repository: " + repoName);
    System.out.println("Branch: " + branch);

    Map<String, String> repoConfig = repo.getVcsLocation().getConfiguration();
    for (Map.Entry<String, String> entry : repoConfig.entrySet()) {
        System.out.println("Config Key: " + entry.getKey() + ", Value: " + entry.getValue());
    }
}

Map<String, String> envVars = System.getenv();
for (Map.Entry<String, String> entry : envVars.entrySet()) {
    System.out.println("Env Var Name: " + entry.getKey() + ", Value: " + entry.getValue());
}

I also printed all environment variables and repository configurations, but I could not find any information about the target branch, pull request number, or additional PR details. How can I retrieve these details in my Bamboo plugin?

(2) Also I need to determine which SCM is configured. Specifically, I want to know if the configured SCM is:

  • Bitbucket Cloud
  • Bitbucket Data Center
  • GitHub Cloud
  • GitHub on-prem
  • GitLab Cloud
  • GitLab on-prem

Thanks