Skip to content

Commit

Permalink
fix: Oops incorrect function name 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
guisea committed Apr 24, 2024
1 parent 1c3d5ea commit 2707598
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
110 changes: 110 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package main

import (
"context"
"errors"
"fmt"
"strconv"
"strings"

"code.gitea.io/sdk/gitea"
"github.com/davecgh/go-spew/spew"
"github.com/go-semantic-release/semantic-release/v2/pkg/semrel"
)

type GiteaRepository struct {
client *gitea.Client
repo string
owner string
stripVTagPrefix bool
baseURL string
}

//gocyclo:ignore
func (repo *GiteaRepository) Init() error {
giteaHost := "https://hub.cybercinch.nz"
repo.baseURL = giteaHost
slug := "cybercinch/ansible-role-common"
token := "dff97800f1f8238e3c0f6a45f14f6ba3b477a4f5"
if !strings.Contains(slug, "/") {
return errors.New("invalid slug")
}
split := strings.Split(slug, "/")
// This could be due to act locally
// We'll work backwards to get the values
repo.owner = split[len(split)-2]
repo.repo = split[len(split)-1]

// Ensure no .git suffix remains
repo.repo = strings.TrimSuffix(repo.repo, ".git")

ctx := context.Background()
if giteaHost != "" {
client, err := gitea.NewClient(giteaHost,
gitea.SetToken(token),
gitea.SetContext(ctx))
if err != nil {
return err
}
repo.client = client
}

var err error
stripVTagPrefix := "false"
repo.stripVTagPrefix, err = strconv.ParseBool(stripVTagPrefix)

if stripVTagPrefix != "" && err != nil {
return fmt.Errorf("failed to set property strip_v_tag_prefix: %w", err)
}

return nil
}

func (repo *GiteaRepository) GetCommits(_, toSha string) ([]*semrel.RawCommit, error) {
allCommits := make([]*semrel.RawCommit, 0)
opts := &gitea.ListOptions{PageSize: 100}
done := false
for {
commits, resp, err := repo.client.ListRepoCommits(repo.owner, repo.repo, gitea.ListCommitOptions{
SHA: toSha,
ListOptions: *opts,
})

if err != nil {
return nil, err
}
for _, commit := range commits {
sha := commit.SHA
fmt.Println(spew.Sdump(commit))
allCommits = append(allCommits, &semrel.RawCommit{
SHA: sha,
RawMessage: commit.RepoCommit.Message,
Annotations: map[string]string{
"author_login": commit.Author.UserName,
"author_name": commit.Author.FullName,
"author_email": commit.Author.Email,
"author_date": commit.RepoCommit.Author.Date,
"committer_login": commit.Committer.UserName,
"committer_name": commit.Committer.FullName,
"committer_email": commit.Committer.Email,
"committer_date": commit.RepoCommit.Committer.Date,
},
})
}
if done || resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return allCommits, nil
}

func main() {
c := &GiteaRepository{}
c.Init()

commits, _ := c.GetCommits("0902ffb7682f11a22d85a5532231e68497f53afd", "")

println(spew.Sdump(commits))

}
2 changes: 1 addition & 1 deletion pkg/provider/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (repo *GiteaRepository) getCommitsFromGitea(fromSha string, opts *gitea.Lis
})
}

func (repo *GiteaRepository) GGetCommits(_, toSha string) ([]*semrel.RawCommit, error) {
func (repo *GiteaRepository) GetCommits(_, toSha string) ([]*semrel.RawCommit, error) {
allCommits := make([]*semrel.RawCommit, 0)
opts := &gitea.ListOptions{PageSize: 100}
done := false
Expand Down

0 comments on commit 2707598

Please sign in to comment.