Skip to content

Commit

Permalink
fix code check
Browse files Browse the repository at this point in the history
  • Loading branch information
Hourunze1997 committed Dec 26, 2024
1 parent 4b06afa commit 5fd5297
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
8 changes: 0 additions & 8 deletions common/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func getManagerToken(appId string, appSecret string) (string, error) {
return
}
}(resp.Body)

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
Expand All @@ -99,19 +98,16 @@ func GetEulerUserName(ctx *gin.Context) (string, error) {
if err != nil {
return "", err
}

managerToken, err := getManagerToken(config.EulerAppId, config.EulerAppSecret)
if err != nil {
logrus.Errorf("get manager token failed, err:%v", err)
return "", err
}

userName, err := fetchUserName(managerToken, token, YGCookie)
if err != nil {
logrus.Errorf("get user name failed, err:%v", err)
return "", err
}

return userName, nil
}

Expand All @@ -136,24 +132,20 @@ func fetchUserName(managerToken, userToken, YGCookie string) (string, error) {
req.Header.Add("token", managerToken)
req.Header.Add("user-token", userToken)
req.Header.Add("Cookie", OneIdUserCookie+"="+YGCookie)

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}

var data GetUserInfoResponse
if err = json.Unmarshal(body, &data); err != nil {
return "", err
}

if data.UserName == "" {
return "", xerrors.Errorf("the user name is null")
}
Expand Down
11 changes: 0 additions & 11 deletions utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,15 @@ func GetUserSigInfo(userName string) ([]string, error) {
if err != nil {
return []string{}, err
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return []string{}, err
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return []string{}, err
}

var repoSig SigInfo
err = json.Unmarshal(body, &repoSig)
if err != nil {
Expand All @@ -170,22 +167,18 @@ func GetUserAdminRepos(userName string) ([]string, error) {
var repos []GiteeRepo
page := 1
perPage := 100

for {
members, err := fetchUserRepos(userName, page, perPage)
if err != nil {
return nil, err // 直接返回 nil 而不是空切片
}

repos = append(repos, members...)

// 如果返回的成员少于每页数量,则表示没有更多数据
if len(members) < perPage {
break
}
page++
}

return filterAdminRepos(repos), nil
}

Expand All @@ -195,24 +188,20 @@ func fetchUserRepos(userName string, page, perPage int) ([]GiteeRepo, error) {
if err != nil {
return nil, err
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close() // 确保在函数结束时关闭响应体

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

var members []GiteeRepo
err = json.Unmarshal(body, &members)
if err != nil {
return nil, err
}

return members, nil
}

Expand Down

0 comments on commit 5fd5297

Please sign in to comment.