001package com.teamscale.commons.links; 002 003import org.conqat.engine.index.shared.CommitDescriptor; 004import org.conqat.engine.service.shared.ServiceUtils; 005import org.conqat.engine.service.shared.client.ServiceClientUris; 006 007import com.google.common.base.Preconditions; 008 009/** 010 * Helper class for obtaining links to global and project specific services of 011 * the current Teamscale instance. 012 */ 013public class TeamscaleProjectLinkProvider extends TeamscaleLinkProvider { 014 015 /** The project alias or id if no alias is set. */ 016 protected final String projectAliasOrId; 017 018 public TeamscaleProjectLinkProvider(String baseUrl, String projectAliasOrId) { 019 super(baseUrl); 020 Preconditions.checkNotNull(projectAliasOrId, "Project alias or id can't be null."); 021 this.projectAliasOrId = projectAliasOrId; 022 } 023 024 /** Returns a link to the delta perspective for the given commit. */ 025 public String createDeltaPerspectiveLink(CommitDescriptor firstCommit, CommitDescriptor lastCommit, 026 boolean mergeRequestMode) { 027 String result = baseUrl + "delta.html#findings/" + ServiceUtils.encodePathSegment(projectAliasOrId) 028 + ServiceClientUris.createOptionString("from", firstCommit.toServiceCallFormat(), "to", 029 lastCommit.toServiceCallFormat()); 030 if (mergeRequestMode) { 031 result += "&showMergeFindings=true"; 032 } 033 return result; 034 } 035 036 /** Returns a link to the merge request details view. */ 037 public String createMergeRequestDetailsLink(String mergeRequestId) { 038 return baseUrl + "activity.html#merge-requests/" + ServiceUtils.encodePathSegment(projectAliasOrId) + "/" 039 + ServiceUtils.encodePathSegment(mergeRequestId); 040 } 041 042 /** Returns a link to the issue perspective for the given issue. */ 043 public String createIssuePerspectiveLink(String issueId) { 044 return baseUrl + "issues.html#/" + ServiceUtils.encodePathSegment(projectAliasOrId) + "/" 045 + ServiceUtils.encodePathSegment(issueId); 046 } 047 048}