Skip to content
Snippets Groups Projects
Commit a68e7e13 authored by Christoph Witzko's avatar Christoph Witzko
Browse files

fix: correctly get owner/repo information and list initial commits

parent 1357f6fe
Branches
Tags v1.12.1
No related merge requests found
......@@ -6,6 +6,7 @@ import (
"os"
"regexp"
"strconv"
"strings"
"time"
"github.com/Masterminds/semver/v3"
......@@ -81,22 +82,30 @@ func (repo *GitLabRepository) GetInfo() (*provider.RepositoryInfo, error) {
if err != nil {
return nil, err
}
namespace, repoName, _ := strings.Cut(project.PathWithNamespace, "/")
return &provider.RepositoryInfo{
Owner: "",
Repo: "",
Owner: namespace,
Repo: repoName,
DefaultBranch: project.DefaultBranch,
Private: project.Visibility == gitlab.PrivateVisibility,
}, nil
}
func (repo *GitLabRepository) GetCommits(fromSha, toSha string) ([]*semrel.RawCommit, error) {
var refName *string
if fromSha == "" {
refName = gitlab.String(toSha)
} else {
// No Matter the order ofr fromSha and toSha gitlab always returns commits in reverse chronological order
refName = gitlab.String(fmt.Sprintf("%s...%s", fromSha, toSha))
}
opts := &gitlab.ListCommitsOptions{
ListOptions: gitlab.ListOptions{
Page: 1,
PerPage: 100,
},
// No Matter the order ofr fromSha and toSha gitlab always returns commits in reverse chronological order
RefName: gitlab.String(fmt.Sprintf("%s...%s", fromSha, toSha)),
RefName: refName,
}
allCommits := make([]*semrel.RawCommit, 0)
......
......@@ -71,7 +71,7 @@ func createGitlabTag(name string) *gitlab.Tag {
var (
gitlabProjectID = 12324322
gitlabDefaultBranch = "master"
gitlabProjects = gitlab.Project{DefaultBranch: gitlabDefaultBranch, Visibility: gitlab.PrivateVisibility, ID: gitlabProjectID}
gitlabProjects = gitlab.Project{DefaultBranch: gitlabDefaultBranch, Visibility: gitlab.PrivateVisibility, ID: gitlabProjectID, PathWithNamespace: "owner/repo"}
gitlabCommits = []*gitlab.Commit{
createGitlabCommit("abcd", "feat(app): new feature"),
createGitlabCommit("dcba", "Fix: bug"),
......@@ -156,6 +156,8 @@ func TestGitlabGetInfo(t *testing.T) {
require.NoError(t, err)
require.Equal(t, gitlabDefaultBranch, repoInfo.DefaultBranch)
require.True(t, repoInfo.Private)
require.Equal(t, "owner", repoInfo.Owner)
require.Equal(t, "repo", repoInfo.Repo)
}
func TestGitlabGetCommits(t *testing.T) {
......
#!/usr/bin/env bash
set -euo pipefail
pluginDir=".semrel/$(go env GOOS)_$(go env GOARCH)/provider-gitlab/0.0.0-dev/"
[[ ! -d "$pluginDir" ]] && {
echo "creating $pluginDir"
mkdir -p "$pluginDir"
}
go build -o "$pluginDir/provider-gitlab" ./cmd/provider-gitlab
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment