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_cifunc GetCommit(owner, repo, id string) (*Commit, error) { 26ba991379Sopenharmony_ci url := fmt.Sprintf("https://gitee.com/api/v5/repos/%s/%s/commits/%s", owner, repo, id) 27ba991379Sopenharmony_ci var resp []byte 28ba991379Sopenharmony_ci if c, found := utils.CacheGet("gitee", url); found { 29ba991379Sopenharmony_ci resp = c.([]byte) 30ba991379Sopenharmony_ci } else { 31ba991379Sopenharmony_ci var err error 32ba991379Sopenharmony_ci resp, err = utils.DoSimpleHttpReq(http.MethodGet, url, nil, nil) 33ba991379Sopenharmony_ci if err != nil { 34ba991379Sopenharmony_ci return nil, err 35ba991379Sopenharmony_ci } 36ba991379Sopenharmony_ci utils.CacheSet("gitee", url, resp) 37ba991379Sopenharmony_ci } 38ba991379Sopenharmony_ci var commitResp Commit 39ba991379Sopenharmony_ci if err := json.Unmarshal(resp, &commitResp); err != nil { 40ba991379Sopenharmony_ci return nil, err 41ba991379Sopenharmony_ci } 42ba991379Sopenharmony_ci commitResp.Owner = owner 43ba991379Sopenharmony_ci commitResp.Repo = repo 44ba991379Sopenharmony_ci return &commitResp, nil 45ba991379Sopenharmony_ci} 46