Skip to content

Commit

Permalink
gitlab issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer committed Nov 28, 2023
1 parent a9dcf5d commit 6c9a0ac
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitlab
import (
"fmt"
"path"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -100,16 +101,16 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
ran := false
repos := []types.Repo{}
for _, repo := range conf.Source.Gitlab {
if repo.URL == "" {
repo.URL = "https://gitlab.com"
}
err := repo.Filter.ParseDuration()
sub = logger.CreateSubLogger("stage", "gitlab", "url", repo.URL)
if err != nil {
sub.Error().
Msg(err.Error())
}
ran = true
if repo.URL == "" {
repo.URL = "https://gitlab.com"
}

sub.Info().
Msgf("grabbing repositories from %s", repo.User)
Expand Down Expand Up @@ -230,6 +231,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
Hoster: types.GetHost(repo.URL),
Description: r.Description,
Private: r.Visibility == gitlab.PrivateVisibility,
Issues: GetIssues(r, client, repo),
})
}

Expand Down Expand Up @@ -270,6 +272,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
Hoster: types.GetHost(repo.URL),
Description: r.Description,
Private: r.Visibility == gitlab.PrivateVisibility,
Issues: GetIssues(r, client, repo),
})
}

Expand Down Expand Up @@ -395,6 +398,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
Hoster: types.GetHost(repo.URL),
Description: r.Description,
Private: r.Visibility == gitlab.PrivateVisibility,
Issues: GetIssues(r, client, repo),
})
}

Expand Down Expand Up @@ -439,6 +443,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
Hoster: types.GetHost(repo.URL),
Description: r.Description,
Private: r.Visibility == gitlab.PrivateVisibility,
Issues: GetIssues(r, client, repo),
})
}

Expand Down Expand Up @@ -483,3 +488,27 @@ func activeWiki(r *gitlab.Project, client *gitlab.Client, repo types.GenRepo) bo

return len(wikis) > 0
}

// GetIssues get issues
func GetIssues(repo *gitlab.Project, client *gitlab.Client, conf types.GenRepo) map[string]interface{} {
issues := map[string]interface{}{}
if conf.Issues {
listOptions := &gitlab.ListProjectIssuesOptions{ListOptions: gitlab.ListOptions{PerPage: 100}}
for {
i, _, err := client.Issues.ListProjectIssues(repo.ID, listOptions)
if err != nil {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
} else {
if len(i) > 0 {
for _, issue := range i {
issues[strconv.Itoa(issue.IID)] = issue
}
} else {
break
}
listOptions.Page++
}
}
}
return issues
}

0 comments on commit 6c9a0ac

Please sign in to comment.