1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 16package gitee 17 18import ( 19 "encoding/json" 20 "fmt" 21 "fotff/utils" 22 "net/http" 23) 24 25type PRIssueResp struct { 26 URL string `json:"html_url"` 27} 28 29func GetMRIssueURL(owner string, repo string, num int) ([]string, error) { 30 url := fmt.Sprintf("https://gitee.com/api/v5/repos/%s/%s/pulls/%d/issues", owner, repo, num) 31 var resp []byte 32 if c, found := utils.CacheGet("gitee", url); found { 33 resp = c.([]byte) 34 } else { 35 var err error 36 resp, err = utils.DoSimpleHttpReq(http.MethodGet, url, nil, nil) 37 if err != nil { 38 return nil, err 39 } 40 utils.CacheSet("gitee", url, resp) 41 } 42 var prIssues []PRIssueResp 43 if err := json.Unmarshal(resp, &prIssues); err != nil { 44 return nil, err 45 } 46 ret := make([]string, len(prIssues)) 47 for i, issue := range prIssues { 48 ret[i] = issue.URL 49 } 50 return ret, nil 51} 52