protected Branch createBranchForTemplateInstance(Branch templateBranch, String branchName) { return structureService.newBranch( Branch.of( templateBranch.getProject(), NameDescription.nd( NameDescription.escapeName(branchName), "" ) ) ); }
protected Branch doCreateBranch(Project project, NameDescription nameDescription) throws Exception { return asUser().with(project.id(), BranchCreate.class).call(() -> structureService.newBranch( Branch.of(project, nameDescription) )); }
@Override public Branch cloneBranch(Branch sourceBranch, BranchCloneRequest request) { // Replacement function Function<String, String> replacementFn = replacementFn(request.getReplacements()); // Description of the target branch String targetDescription = replacementFn.apply(sourceBranch.getDescription()); // Creates the branch Branch targetBranch = structureService.newBranch( Branch.of( sourceBranch.getProject(), NameDescription.nd(request.getName(), targetDescription) ) ); // Copies the configuration doCopy(sourceBranch, targetBranch, replacementFn, SyncPolicy.COPY); // OK return targetBranch; }
@Override public Project cloneProject(Project sourceProject, ProjectCloneRequest request) { // Replacement function Function<String, String> replacementFn = replacementFn(request.getReplacements()); // Description of the target project String targetProjectDescription = replacementFn.apply(sourceProject.getDescription()); // Creates the project Project targetProject = structureService.newProject( Project.of( NameDescription.nd(request.getName(), targetProjectDescription) ) ); // Copies the properties for the project doCopyProperties(sourceProject, targetProject, replacementFn, SyncPolicy.COPY); // Creates a copy of the branch Branch sourceBranch = structureService.getBranch(request.getSourceBranchId()); String targetBranchName = replacementFn.apply(sourceBranch.getName()); String targetBranchDescription = replacementFn.apply(sourceBranch.getDescription()); Branch targetBranch = structureService.newBranch( Branch.of( targetProject, NameDescription.nd(targetBranchName, targetBranchDescription) ) ); // Configuration of the new branch doCopy(sourceBranch, targetBranch, replacementFn, SyncPolicy.COPY); // OK return targetProject; }