#8 delete cobra, add micro-config-flag #11
@ -404,39 +404,48 @@ func DeleteBranch(ctx context.Context, url, owner, repo, branch, token string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull, error) {
|
func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull, error) {
|
||||||
var pulls []*giteaPull
|
var pullsAll, pulls []*giteaPull
|
||||||
var err error
|
page := 1
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(
|
for page != 0 {
|
||||||
ctx,
|
req, err := http.NewRequestWithContext(
|
||||||
http.MethodGet,
|
ctx,
|
||||||
fmt.Sprintf("https://%s/api/v1//repos/%s/%s/pulls?state=open&page=99&token=%s", url, owner, repo, token),
|
http.MethodGet,
|
||||||
nil)
|
fmt.Sprintf("https://%s/api/v1//repos/%s/%s/pulls?state=open&page=%s&token=%s", url, owner, repo, page, token),
|
||||||
if err != nil {
|
nil)
|
||||||
return nil, err
|
if err != nil {
|
||||||
} //вроде запроса к репозиторию
|
return nil, err
|
||||||
|
} //вроде запроса к репозиторию
|
||||||
|
|
||||||
req.Header.Add("Accept", "application/json")
|
req.Header.Add("Accept", "application/json")
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
|
||||||
rsp, err := http.DefaultClient.Do(req) // выполнение запроса
|
rsp, err := http.DefaultClient.Do(req) // выполнение запроса
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, _ := io.ReadAll(rsp.Body)
|
|
||||||
|
|
||||||
switch rsp.StatusCode {
|
|
||||||
case http.StatusOK:
|
|
||||||
if err = json.Unmarshal(buf, &pulls); err != nil {
|
|
||||||
logger.Error(ctx, fmt.Sprintf("failed to decode response %s err: %v", buf, err))
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return pulls, nil
|
|
||||||
case http.StatusNotFound:
|
buf, _ := io.ReadAll(rsp.Body)
|
||||||
logger.Info(ctx, "PL is not exist for %s", repo)
|
|
||||||
return nil, ErrPRNotExist
|
switch rsp.StatusCode {
|
||||||
default:
|
case http.StatusOK:
|
||||||
return nil, fmt.Errorf("unknown error: %s", buf)
|
if err = json.Unmarshal(buf, &pulls); err != nil {
|
||||||
|
logger.Error(ctx, fmt.Sprintf("failed to decode response %s err: %v", buf, err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(pulls) == 0 {
|
||||||
|
page = 0
|
||||||
|
break
|
||||||
|
}
|
||||||
|
pullsAll = append(pullsAll, pulls...)
|
||||||
|
page++
|
||||||
|
case http.StatusNotFound:
|
||||||
|
logger.Info(ctx, "PL is not exist for %s", repo)
|
||||||
|
return nil, ErrPRNotExist
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unknown error: %s", buf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pullsAll, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user