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-rc2
Show newest version
/*
 * Copyright (c) CQSE GmbH
 *
 * 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 com.teamscale.commons.links;

import org.conqat.engine.index.shared.CommitDescriptor;
import org.conqat.engine.index.shared.MergeRequestIdentifier;
import org.conqat.engine.index.shared.PublicProjectId;
import org.conqat.engine.service.shared.client.ServiceClientUris;
import org.conqat.lib.commons.net.UrlUtils;

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

	/** The primary project ID. May be null. */
	protected final PublicProjectId projectId;

	public TeamscaleProjectLinkProvider(String baseUrl, PublicProjectId projectId) {
		super(baseUrl);
		this.projectId = projectId;
	}

	/** 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/" + UrlUtils.encodePathSegment(projectId.toString())
				+ 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/" + UrlUtils.encodePathSegment(projectId.toString()) + "/"
				+ UrlUtils.encodePathSegment(mergeRequestId.toString());
	}

	/**
	 * Returns a link to the issue perspective for the given issue.
	 *
	 * @param issueId
	 *            The Teamscale internal id of the issue (see
	 *            {@code TeamscaleIssue.TeamscaleIssueId#getInternalId()})
	 */
	public String createIssuePerspectiveLink(String issueId, boolean hideResolvedFindingsInLink) {
		String link = baseUrl + "activity.html#issues/" + UrlUtils.encodePathSegment(projectId.toString())
				+ "/?action=view&id=" + UrlUtils.encodeQueryParameter(issueId);
		if (hideResolvedFindingsInLink) {
			link += "&hideResolvedFindings=true";
		}
		return link;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy