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

com.teamscale.commons.links.TeamscaleProjectLinkProvider Maven / Gradle / Ivy

There is a newer version: 2025.1.0
Show newest version
package com.teamscale.commons.links;

import org.conqat.engine.index.shared.CommitDescriptor;
import org.conqat.engine.index.shared.MergeRequestIdentifier;
import org.conqat.engine.service.shared.ServiceUtils;
import org.conqat.engine.service.shared.client.ServiceClientUris;

import com.google.common.base.Preconditions;

/**
 * Helper class for obtaining links to global and project specific services of
 * the current Teamscale instance.
 */
public class TeamscaleProjectLinkProvider extends TeamscaleLinkProvider {

	/** The project alias or id if no alias is set. */
	protected final String projectAliasOrId;

	public TeamscaleProjectLinkProvider(String baseUrl, String projectAliasOrId) {
		super(baseUrl);
		Preconditions.checkNotNull(projectAliasOrId, "Project alias or id can't be null.");
		this.projectAliasOrId = projectAliasOrId;
	}

	/** Returns a link to the delta perspective for the given commit. */
	public String createDeltaPerspectiveLink(CommitDescriptor firstCommit, CommitDescriptor lastCommit,
			boolean mergeRequestMode) {
		String result = baseUrl + "delta.html#findings/" + ServiceUtils.encodePathSegment(projectAliasOrId)
				+ ServiceClientUris.createOptionString("from", firstCommit.toServiceCallFormat(), "to",
						lastCommit.toServiceCallFormat());
		if (mergeRequestMode) {
			result += "&showMergeFindings=true";
		}
		return result;
	}

	/** Returns a link to the merge request details view. */
	public String createMergeRequestDetailsLink(MergeRequestIdentifier mergeRequestId) {
		return baseUrl + "activity.html#merge-requests/" + ServiceUtils.encodePathSegment(projectAliasOrId) + "/"
				+ ServiceUtils.encodePathSegment(mergeRequestId.toString());
	}

	/** Returns a link to the issue perspective for the given issue. */
	public String createIssuePerspectiveLink(String issueId) {
		return baseUrl + "issues.html#/" + ServiceUtils.encodePathSegment(projectAliasOrId) + "/"
				+ ServiceUtils.encodePathSegment(issueId);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy