Search in sources :

Example 1 with BranchContext

use of cd.go.contrib.plugins.configrepo.groovy.dsl.BranchContext in project gocd-groovy-dsl-config-plugin by gocd-contrib.

the class BranchHelper method createContext.

public static BranchContext createContext(Attributes<?> attrs, MergeCandidate merge) {
    final String ref = merge.ref();
    final String branch = prettifyRef(gitShortRef(ref), attrs);
    final BranchContext bc = new BranchContext(ref, branch, createMaterial(attrs, merge));
    bc.setProvider(attrs.asConnectionConfig());
    bc.setIdentifier(requireNonNullElse(merge.identifier(), ""));
    bc.setTitle(requireNonNullElse(merge.title(), ""));
    bc.setAuthor(requireNonNullElse(merge.author(), ""));
    bc.setReferenceUrl(requireNonNullElse(merge.showUrl(), ""));
    bc.setLabels(new ArrayList<>(requireNonNullElse(merge.labels(), Collections.emptyList())));
    validate(bc, (errors) -> {
        throw new ValidationException("Branch context binding is missing data! " + "Check the provider's API response. Error(s):\n" + errors.stream().map(ConstraintViolation::getMessage).collect(Collectors.joining("\n", "  ", "")));
    });
    return bc;
}
Also used : ValidationException(jakarta.validation.ValidationException) BranchContext(cd.go.contrib.plugins.configrepo.groovy.dsl.BranchContext)

Aggregations

BranchContext (cd.go.contrib.plugins.configrepo.groovy.dsl.BranchContext)1 ValidationException (jakarta.validation.ValidationException)1