/** * This method is public for easier unit testing */ public int processGitRepo(NamespaceName name, String gitUrl, String gitRef) throws IOException { BuildConfig buildConfig = new BuildConfig(); BuildConfigSpec buildConfigSpec = new BuildConfigSpec(); buildConfig.setSpec(buildConfigSpec); BuildSource buildSource = new BuildSource(); buildSource.setType("Git"); GitBuildSource gitSource = new GitBuildSource(); gitSource.setUri(gitUrl); if (Strings.isNullOrBlank(gitRef)) { gitRef = "master"; } gitSource.setRef(gitRef); buildSource.setGit(gitSource); buildConfigSpec.setSource(buildSource); return processGitRepo(name, buildConfig, gitSource, gitUrl); }
/** * Lazily creates the GitSource if need be then updates the git URL * @param buildConfig the BuildConfig to update * @param gitUrl the URL to the git repo * @param ref */ public static void updateGitSourceUrl(BuildConfig buildConfig, String gitUrl, String ref) { BuildConfigSpec spec = buildConfig.getSpec(); if (spec == null) { spec = new BuildConfigSpec(); buildConfig.setSpec(spec); } BuildSource source = spec.getSource(); if (source == null) { source = new BuildSource(); spec.setSource(source); } source.setType("Git"); GitBuildSource gitSource = source.getGit(); if (gitSource == null) { gitSource = new GitBuildSource(); source.setGit(gitSource); } gitSource.setUri(gitUrl); gitSource.setRef(ref); }