Skip to content

Commit

Permalink
added onedev
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer committed Nov 28, 2023
1 parent 0105a8b commit fabc4a2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func Locally(repo types.Repo, l types.Local, dry bool) bool {
}

if len(repo.Issues) > 0 {
_, err := os.Stat(fmt.Sprintf("%s.issues", repo.Name))
if os.IsNotExist(err) && !dry {
if err := os.MkdirAll(fmt.Sprintf("%s.issues", repo.Name), 0o777); err != nil {
sub.Error().
Expand Down
42 changes: 42 additions & 0 deletions onedev/onedev.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package onedev

import (
"fmt"
"strconv"
"strings"
"time"

"github.com/cooperspencer/gickup/logger"
Expand Down Expand Up @@ -135,6 +137,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
Owner: repo.User,
Hoster: types.GetHost(repo.URL),
Description: r.Description,
Issues: GetIssues(&r, client, repo, urls.HTTP),
})
}

Expand Down Expand Up @@ -197,6 +200,7 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
Owner: org,
Hoster: types.GetHost(repo.URL),
Description: r.Description,
Issues: GetIssues(&r, client, repo, urls.HTTP),
})
}
}
Expand Down Expand Up @@ -282,3 +286,41 @@ func GetOrCreate(destination types.GenRepo, repo types.Repo) (string, error) {

return cloneUrls.HTTP, nil
}

// GetIssues get issues
func GetIssues(repo *onedev.Project, client *onedev.Client, conf types.GenRepo, repourl string) map[string]interface{} {
issues := map[string]interface{}{}
if conf.Issues {
name := strings.TrimPrefix(repourl, conf.URL)
listOptions := &onedev.IssueQueryOptions{Count: 100, Offset: 0, Query: fmt.Sprintf("\"Project\" is \"%s\"", name)}
for {
i, _, err := client.GetIssues(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 {
onedevissue := Issue{Issue: issue}
comments, _, err := client.GetIssueComments(onedevissue.ID)
if err != nil {
sub.Error().Err(err).Str("repo", repo.Name).Msg("can't fetch issues")
} else {
onedevissue.Comments = comments
}

issues[strconv.Itoa(int(issue.Number))] = onedevissue
}
} else {
break
}
listOptions.Offset += listOptions.Count
}
}
}
return issues
}

type Issue struct {
onedev.Issue
Comments []onedev.Comment
}

0 comments on commit fabc4a2

Please sign in to comment.