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

org.sourcelab.github.client.request.RerunJobFromWorkflowOptionsBuilder Maven / Gradle / Ivy

The newest version!
package org.sourcelab.github.client.request;

import org.sourcelab.github.client.exception.BuilderValidationException;
import org.sourcelab.github.client.utils.UrlParser;

public final class RerunJobFromWorkflowOptionsBuilder {
    private String owner = null;
    private String repo = null;
    private Long jobId = null;
    private Boolean enableDebugLogging;

    /**
     * Parse from WorkflowRun.rerun_url property.
     */
    public RerunJobFromWorkflowOptionsBuilder fromRerunUrl(final String rerunUrl) {
        UrlParser.JobsUrlBits bits = null;
        try {
            bits = UrlParser.parseJobsRerunUrl(rerunUrl);
        } catch (Exception e) {
            throw new BuilderValidationException("Unable to parse jobsUrl: " + rerunUrl, e);
        }
        if (bits == null) {
            throw new BuilderValidationException("Unable to parse jobsUrl: " + rerunUrl);
        }
        this
            .withOwner(bits.getOwner())
            .withRepo(bits.getRepo())
            .withJobId(bits.getRunId());
        return this;
    }

    public RerunJobFromWorkflowOptionsBuilder withOwner(final String owner) {
        this.owner = owner;
        return this;
    }

    public RerunJobFromWorkflowOptionsBuilder withRepo(final String repo) {
        this.repo = repo;
        return this;
    }

    public RerunJobFromWorkflowOptionsBuilder withJobId(final long jobId) {
        this.jobId = jobId;
        return this;
    }

    public RerunJobFromWorkflowOptionsBuilder withEnableDebugLogging(final boolean enableDebugLogging) {
        this.enableDebugLogging = enableDebugLogging;
        return this;
    }

    /**
     * Create new instance from builder.
     * @return Create new instance from builder.
     */
    public RerunJobFromWorkflowOptions build() {
        if (owner == null) {
            throw new BuilderValidationException("owner property is required.");
        }
        if (repo == null) {
            throw new BuilderValidationException("repo property is required.");
        }
        if (jobId == null) {
            throw new BuilderValidationException("jobId property is required.");
        }
        return new RerunJobFromWorkflowOptions(owner, repo, jobId, enableDebugLogging);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy