1
1
mirror of https://github.com/cooperspencer/gickup synced 2025-05-01 00:37:55 +02:00

added error counter for issues and stop after a 403 occurs (#256)

* added error counter for issues and stop after a 403 occurs

* added errorcounter to other hosters too
This commit is contained in:
Andreas Wachter 2024-08-20 14:13:42 +02:00 committed by GitHub
parent d29454e856
commit 67db501a30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 64 additions and 9 deletions

@ -1,6 +1,7 @@
package gitea
import (
"net/http"
"strconv"
"strings"
"time"
@ -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 {

@ -2,6 +2,7 @@ package github
import (
"context"
"net/http"
"strconv"
"strings"
"time"
@ -385,10 +386,21 @@ func GetIssues(repo *github.Repository, client *github.Client, conf types.GenRep
issues := map[string]interface{}{}
if conf.Issues {
listOptions := &github.IssueListByRepoOptions{State: "all", ListOptions: github.ListOptions{Page: 0, PerPage: 100}}
errorcount := 0
for {
i, _, err := client.Issues.ListByRepo(context.Background(), *repo.Owner.Login, *repo.Name, listOptions)
i, response, err := client.Issues.ListByRepo(context.Background(), *repo.Owner.Login, *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 {

@ -2,6 +2,7 @@ package gitlab
import (
"fmt"
"net/http"
"path"
"strconv"
"strings"
@ -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 {

@ -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 {

@ -2,6 +2,7 @@ package onedev
import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
@ -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 {