1ba991379Sopenharmony_ci/*
2ba991379Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3ba991379Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4ba991379Sopenharmony_ci * you may not use this file except in compliance with the License.
5ba991379Sopenharmony_ci * You may obtain a copy of the License at
6ba991379Sopenharmony_ci *
7ba991379Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8ba991379Sopenharmony_ci *
9ba991379Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10ba991379Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11ba991379Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12ba991379Sopenharmony_ci * See the License for the specific language governing permissions and
13ba991379Sopenharmony_ci * limitations under the License.
14ba991379Sopenharmony_ci */
15ba991379Sopenharmony_ci
16ba991379Sopenharmony_cipackage gitee
17ba991379Sopenharmony_ci
18ba991379Sopenharmony_ciimport (
19ba991379Sopenharmony_ci	"encoding/json"
20ba991379Sopenharmony_ci	"fmt"
21ba991379Sopenharmony_ci	"fotff/utils"
22ba991379Sopenharmony_ci	"net/http"
23ba991379Sopenharmony_ci)
24ba991379Sopenharmony_ci
25ba991379Sopenharmony_citype PRIssueResp struct {
26ba991379Sopenharmony_ci	URL string `json:"html_url"`
27ba991379Sopenharmony_ci}
28ba991379Sopenharmony_ci
29ba991379Sopenharmony_cifunc GetMRIssueURL(owner string, repo string, num int) ([]string, error) {
30ba991379Sopenharmony_ci	url := fmt.Sprintf("https://gitee.com/api/v5/repos/%s/%s/pulls/%d/issues", owner, repo, num)
31ba991379Sopenharmony_ci	var resp []byte
32ba991379Sopenharmony_ci	if c, found := utils.CacheGet("gitee", url); found {
33ba991379Sopenharmony_ci		resp = c.([]byte)
34ba991379Sopenharmony_ci	} else {
35ba991379Sopenharmony_ci		var err error
36ba991379Sopenharmony_ci		resp, err = utils.DoSimpleHttpReq(http.MethodGet, url, nil, nil)
37ba991379Sopenharmony_ci		if err != nil {
38ba991379Sopenharmony_ci			return nil, err
39ba991379Sopenharmony_ci		}
40ba991379Sopenharmony_ci		utils.CacheSet("gitee", url, resp)
41ba991379Sopenharmony_ci	}
42ba991379Sopenharmony_ci	var prIssues []PRIssueResp
43ba991379Sopenharmony_ci	if err := json.Unmarshal(resp, &prIssues); err != nil {
44ba991379Sopenharmony_ci		return nil, err
45ba991379Sopenharmony_ci	}
46ba991379Sopenharmony_ci	ret := make([]string, len(prIssues))
47ba991379Sopenharmony_ci	for i, issue := range prIssues {
48ba991379Sopenharmony_ci		ret[i] = issue.URL
49ba991379Sopenharmony_ci	}
50ba991379Sopenharmony_ci	return ret, nil
51ba991379Sopenharmony_ci}
52