Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github

import (
"context"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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 {
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
Loading