go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/rpc/bugs.go (about) 1 // Copyright 2022 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 package rpc 16 17 import ( 18 "fmt" 19 20 "go.chromium.org/luci/analysis/internal/bugs" 21 configpb "go.chromium.org/luci/analysis/proto/config" 22 pb "go.chromium.org/luci/analysis/proto/v1" 23 ) 24 25 func createAssociatedBugPB(b bugs.BugID, cfg *configpb.ProjectConfig) *pb.AssociatedBug { 26 // Fallback bug name and URL. 27 linkText := fmt.Sprintf("%s/%s", b.System, b.ID) 28 url := "" 29 30 switch b.System { 31 case bugs.MonorailSystem: 32 monorailCfg := cfg.BugManagement.GetMonorail() 33 if monorailCfg == nil { 34 break 35 } 36 project, id, err := b.MonorailProjectAndID() 37 if err != nil { 38 // Fallback to basic name and blank URL. 39 break 40 } 41 if project == monorailCfg.Project { 42 if monorailCfg.DisplayPrefix != "" { 43 linkText = fmt.Sprintf("%s/%s", monorailCfg.DisplayPrefix, id) 44 } else { 45 linkText = id 46 } 47 } 48 if monorailCfg.MonorailHostname != "" { 49 url = fmt.Sprintf("https://%s/p/%s/issues/detail?id=%s", monorailCfg.MonorailHostname, project, id) 50 } 51 case bugs.BuganizerSystem: 52 linkText = fmt.Sprintf("b/%s", b.ID) 53 url = fmt.Sprintf("https://issuetracker.google.com/issues/%s", b.ID) 54 default: 55 // Fallback. 56 } 57 return &pb.AssociatedBug{ 58 System: b.System, 59 Id: b.ID, 60 LinkText: linkText, 61 Url: url, 62 } 63 }