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

org.sourcelab.github.client.request.RerunJobsFromWorkflowOptionsBuilder 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;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public final class RerunJobsFromWorkflowOptionsBuilder {
    private String owner = null;
    private String repo = null;
    private Set jobIds = new HashSet<>();
    private Boolean enableDebugLogging;

    /**
     * Parse from WorkflowRun.rerun_url property.
     */
    public RerunJobsFromWorkflowOptionsBuilder 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 RerunJobsFromWorkflowOptionsBuilder withOwner(final String owner) {
        this.owner = owner;
        return this;
    }

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

    public RerunJobsFromWorkflowOptionsBuilder withJobId(final long jobId) {
        this.jobIds.add(jobId);
        return this;
    }

    public RerunJobsFromWorkflowOptionsBuilder withJobIds(final Collection jobIds) {
        this.jobIds.addAll(jobIds);
        return this;
    }

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy