go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/bisection/tools/link_constructors.ts (about)

     1  // Copyright 2023 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { BuilderID } from '@/proto/go.chromium.org/luci/buildbucket/proto/builder_common.pb';
    16  import { GitilesCommit } from '@/proto/go.chromium.org/luci/buildbucket/proto/common.pb';
    17  
    18  import { getCommitShortHash } from './commit_formatters';
    19  
    20  export const EMPTY_LINK: ExternalLink = {
    21    linkText: '',
    22    url: '',
    23  };
    24  
    25  export interface ExternalLink {
    26    linkText: string;
    27    url: string;
    28  }
    29  
    30  export const linkToBuild = (buildID: string): ExternalLink => {
    31    return {
    32      linkText: buildID,
    33      url: `https://ci.chromium.org/b/${buildID}`,
    34    };
    35  };
    36  
    37  export const linkToBuilder = (builderID: BuilderID): ExternalLink => {
    38    const { project, bucket, builder } = builderID;
    39    return {
    40      linkText: `${project}/${bucket}/${builder}`,
    41      url: `https://ci.chromium.org/p/${project}/builders/${bucket}/${builder}`,
    42    };
    43  };
    44  
    45  export const linkToCommit = (commit: GitilesCommit): ExternalLink => {
    46    const { host, project, id } = commit;
    47    return {
    48      linkText: getCommitShortHash(id),
    49      url: `https://${host}/${project}/+/${id}`,
    50    };
    51  };
    52  
    53  export const linkToCommitRange = (
    54    lastPassed: GitilesCommit,
    55    firstFailed: GitilesCommit,
    56  ): ExternalLink => {
    57    const host = lastPassed.host;
    58    const project = lastPassed.project;
    59    const lastPassedShortHash = getCommitShortHash(lastPassed.id);
    60    const firstFailedShortHash = getCommitShortHash(firstFailed.id);
    61    return {
    62      linkText: `${lastPassedShortHash} ... ${firstFailedShortHash}`,
    63      url: `https://${host}/${project}/+log/${lastPassed.id}..${firstFailed.id}`,
    64    };
    65  };