All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cd.go.contrib.plugins.configrepo.groovy.dsl.GitHubPRMaterial Maven / Gradle / Ivy

Go to download

Groovy DSL for GoCD pipeline definitions, for use with the gocd-groovy-dsl-plugin

The newest version!
// Generated by delombok at Fri Dec 20 00:19:58 PST 2024
/*
 * Copyright 2022 Thoughtworks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cd.go.contrib.plugins.configrepo.groovy.dsl;

import cd.go.contrib.plugins.configrepo.groovy.dsl.mixins.Configurable;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import groovy.transform.stc.ClosureParams;
import groovy.transform.stc.SimpleType;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.function.Consumer;
import static groovy.lang.Closure.DELEGATE_ONLY;

public class GitHubPRMaterial extends ScmMaterial {
    private String url;
    private String branch;

    public GitHubPRMaterial(String name, Consumer configure) {
        super(name, configure);
    }

    public GitHubPRMaterial(@DelegatesTo(value = GitHubPRMaterial.class, strategy = DELEGATE_ONLY) @ClosureParams(value = SimpleType.class, options = "cd.go.contrib.plugins.configrepo.groovy.dsl.GitHubPRMaterial") Closure cl) {
        this(null, cl);
    }

    public GitHubPRMaterial(String name, @DelegatesTo(value = GitHubPRMaterial.class, strategy = DELEGATE_ONLY) @ClosureParams(value = SimpleType.class, options = "cd.go.contrib.plugins.configrepo.groovy.dsl.GitHubPRMaterial") Closure cl) {
        super(name);
        configure(cl);
    }

    @Override
    public GitHubPRMaterial dup(@DelegatesTo(value = GitHubPRMaterial.class, strategy = DELEGATE_ONLY) @ClosureParams(value = SimpleType.class, options = "cd.go.contrib.plugins.configrepo.groovy.dsl.GitHubPRMaterial") Closure config) {
        return Configurable.applyTo(config, deepClone());
    }

    public Object toPluggableMaterial() {
        LinkedHashMap result = new LinkedHashMap<>();
        result.put("name", name);
        result.put("type", "plugin");
        result.put("plugin_configuration", pluginConfig());
        result.put("configuration", configuration());
        return result;
    }

    @Override
    protected GitHubPRMaterial deepClone() {
        return new GitHubPRMaterial(name, g -> {
            injectSettings(g);
            g.url = url;
            g.branch = branch;
        });
    }

    private Object configuration() {
        ArrayList result = new ArrayList<>();
        result.add(kvp("url", url, false));
        result.add(kvp("username", username, false));
        result.add(kvp("password", encryptedPassword, true));
        result.add(kvp("defaultBranch", branch, false));
        return result;
    }

    private Object kvp(String key, String value, boolean encrypted) {
        LinkedHashMap result = new LinkedHashMap<>();
        result.put("key", key);
        if (encrypted) {
            result.put("encrypted_value", value);
        } else {
            result.put("value", value);
        }
        return result;
    }

    private Object pluginConfig() {
        LinkedHashMap result = new LinkedHashMap<>();
        result.put("id", "github.pr");
        result.put("version", "1");
        return result;
    }

    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public String getUrl() {
        return this.url;
    }

    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public String getBranch() {
        return this.branch;
    }

    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setUrl(final String url) {
        this.url = url;
    }

    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public void setBranch(final String branch) {
        this.branch = branch;
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public boolean equals(final java.lang.Object o) {
        if (o == this) return true;
        if (!(o instanceof GitHubPRMaterial)) return false;
        final GitHubPRMaterial other = (GitHubPRMaterial) o;
        if (!other.canEqual((java.lang.Object) this)) return false;
        if (!super.equals(o)) return false;
        final java.lang.Object this$url = this.getUrl();
        final java.lang.Object other$url = other.getUrl();
        if (this$url == null ? other$url != null : !this$url.equals(other$url)) return false;
        final java.lang.Object this$branch = this.getBranch();
        final java.lang.Object other$branch = other.getBranch();
        if (this$branch == null ? other$branch != null : !this$branch.equals(other$branch)) return false;
        return true;
    }

    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    protected boolean canEqual(final java.lang.Object other) {
        return other instanceof GitHubPRMaterial;
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public int hashCode() {
        final int PRIME = 59;
        int result = super.hashCode();
        final java.lang.Object $url = this.getUrl();
        result = result * PRIME + ($url == null ? 43 : $url.hashCode());
        final java.lang.Object $branch = this.getBranch();
        result = result * PRIME + ($branch == null ? 43 : $branch.hashCode());
        return result;
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public java.lang.String toString() {
        return "GitHubPRMaterial(super=" + super.toString() + ", url=" + this.getUrl() + ", branch=" + this.getBranch() + ")";
    }
}