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

org.sourcelab.github.client.request.CancelWorkflowOptionsBuilder 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 CancelWorkflowOptionsBuilder {
    private String owner = null;
    private String repo = null;
    private Long runId = null;

    /**
     * Parse from WorkflowRun.rerun_url property.
     */
    public CancelWorkflowOptionsBuilder fromCancelUrl(final String cancelUrl) {
        UrlParser.JobsUrlBits bits = null;
        try {
            bits = UrlParser.parseJobsCancelUrl(cancelUrl);
        } catch (Exception e) {
            throw new BuilderValidationException("Unable to parse cancelUrl: " + cancelUrl, e);
        }
        if (bits == null) {
            throw new BuilderValidationException("Unable to parse cancelUrl: " + cancelUrl);
        }
        this
            .withOwner(bits.getOwner())
            .withRepo(bits.getRepo())
            .withRunId(bits.getRunId());
        return this;
    }

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

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

    public CancelWorkflowOptionsBuilder withRunId(final long runId) {
        this.runId = runId;
        return this;
    }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy