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 BranchResp struct { 26ba991379Sopenharmony_ci Name string `json:"name"` 27ba991379Sopenharmony_ci Commit *Commit `json:"commit"` 28ba991379Sopenharmony_ci} 29ba991379Sopenharmony_ci 30ba991379Sopenharmony_cifunc GetBranch(owner, repo, branch string) (*BranchResp, error) { 31ba991379Sopenharmony_ci url := fmt.Sprintf("https://gitee.com/api/v5/repos/%s/%s/branches/%s", owner, repo, branch) 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 var branchResp BranchResp 37ba991379Sopenharmony_ci if err := json.Unmarshal(resp, &branchResp); err != nil { 38ba991379Sopenharmony_ci return nil, err 39ba991379Sopenharmony_ci } 40ba991379Sopenharmony_ci return &branchResp, nil 41ba991379Sopenharmony_ci} 42