Skip to content

Commit

Permalink
added errorcounter to other hosters too
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer committed Aug 20, 2024
1 parent 3346be8 commit d30b295
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
16 changes: 14 additions & 2 deletions gitea/gitea.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gitea

import (
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -554,10 +555,21 @@ func GetIssues(repo *gitea.Repository, client *gitea.Client, conf types.GenRepo)
issues := map[string]interface{}{}
if conf.Issues {
listOptions := gitea.ListIssueOption{State: gitea.StateAll, ListOptions: gitea.ListOptions{PageSize: 100}}
errorcount := 0
for {
i, _, err := client.ListRepoIssues(repo.Owner.UserName, repo.Name, listOptions)
i, response, err := client.ListRepoIssues(repo.Owner.UserName, repo.Name, listOptions)
if err != nil {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
if response.StatusCode == http.StatusForbidden {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
return issues
}
if errorcount < 5 {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
time.Sleep(5 * time.Second)
errorcount++
} else {
return issues
}
} else {
if len(i) > 0 {
for _, issue := range i {
Expand Down
16 changes: 14 additions & 2 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gitlab

import (
"fmt"
"net/http"
"path"
"strconv"
"strings"
Expand Down Expand Up @@ -506,10 +507,21 @@ func GetIssues(repo *gitlab.Project, client *gitlab.Client, conf types.GenRepo)
issues := map[string]interface{}{}
if conf.Issues {
listOptions := &gitlab.ListProjectIssuesOptions{ListOptions: gitlab.ListOptions{PerPage: 100}}
errorcount := 0
for {
i, _, err := client.Issues.ListProjectIssues(repo.ID, listOptions)
i, response, err := client.Issues.ListProjectIssues(repo.ID, listOptions)
if err != nil {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
if response.StatusCode == http.StatusForbidden {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
return issues
}
if errorcount < 5 {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
time.Sleep(5 * time.Second)
errorcount++
} else {
return issues
}
} else {
if len(i) > 0 {
for _, issue := range i {
Expand Down
9 changes: 8 additions & 1 deletion gogs/gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,17 @@ func GetIssues(repo *gogs.Repository, client *gogs.Client, conf types.GenRepo) m
issues := map[string]interface{}{}
if conf.Issues {
listOptions := gogs.ListIssueOption{State: "all"}
errorcount := 0
for {
i, err := client.ListRepoIssues(repo.Owner.UserName, repo.Name, listOptions)
if err != nil {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
if errorcount < 5 {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
time.Sleep(5 * time.Second)
errorcount++
} else {
return issues
}
} else {
if len(i) > 0 {
for _, issue := range i {
Expand Down
16 changes: 14 additions & 2 deletions onedev/onedev.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package onedev

import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -296,10 +297,21 @@ func GetIssues(repo *onedev.Project, client *onedev.Client, conf types.GenRepo,
if conf.Issues {
name := strings.TrimPrefix(repourl, conf.URL)
listOptions := &onedev.IssueQueryOptions{Count: 100, Offset: 0, Query: fmt.Sprintf("\"Project\" is \"%s\"", name)}
errorcount := 0
for {
i, _, err := client.GetIssues(listOptions)
i, returncode, err := client.GetIssues(listOptions)
if err != nil {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
if returncode == http.StatusForbidden {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
return issues
}
if errorcount < 5 {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
time.Sleep(5 * time.Second)
errorcount++
} else {
return issues
}
} else {
if len(i) > 0 {
for _, issue := range i {
Expand Down

0 comments on commit d30b295

Please sign in to comment.