Skip to content

Commit

Permalink
fix(*): 🐛 check commits log ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
dannylongeuay committed Apr 25, 2024
1 parent cb5045b commit 24cb809
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/provider/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (repo *Repository) GetCommits(fromSha, toSha string) ([]*semrel.RawCommit,
}

commits, err := repo.repo.Log(&git.LogOptions{
From: *toHash,
From: *toHash,
Order: git.LogOrderCommitterTime,
})
if err != nil {
return nil, err
Expand Down
55 changes: 54 additions & 1 deletion pkg/provider/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestGit(t *testing.T) {
t.Run("GetInfo", getInfo)
t.Run("GetReleases", getReleases)
t.Run("GetCommits", getCommits)
t.Run("GetCommitsNoFFMerge", getCommitsNoFFMerge)
t.Run("CreateRelease", createRelease)
}

Expand Down Expand Up @@ -151,6 +152,31 @@ func createRepo() (*Repository, error) {
return repo, nil
}

func cloneRepo(path string, url string) (*Repository, error) {

Check failure on line 155 in pkg/provider/git_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
_, err := git.PlainClone(path, false, &git.CloneOptions{
Auth: &http.BasicAuth{
Username: "test",
Password: "test",
},
URL: url,
})
if err != nil {
return nil, err
}
repo := &Repository{}
err = repo.Init(map[string]string{
"git_path": path,
"auth": "basic",
"auth_username": "test",
"auth_password": "test",
})
if err != nil {
return nil, err
}

return repo, nil
}

func getInfo(t *testing.T) {
require := require.New(t)
repo, err := createRepo()
Expand Down Expand Up @@ -179,6 +205,20 @@ func getCommits(t *testing.T) {
}
}

func getCommitsNoFFMerge(t *testing.T) {
require := require.New(t)
dir, err := os.MkdirTemp("", "provider-git")
require.NoError(err)
repo, err := cloneRepo(dir, "http://localhost:3000/test/no_ff_merge.git")
require.NoError(err)
releases, err := repo.GetReleases("")

Check failure on line 214 in pkg/provider/git_test.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
require.Len(releases, 1)
initialCommitSha := releases[0].GetSHA()
commits, err := repo.GetCommits(initialCommitSha, "master")
require.NoError(err)
require.Len(commits, 2)
}

func createRelease(t *testing.T) {
require := require.New(t)
repo, err := createRepo()
Expand Down Expand Up @@ -211,14 +251,27 @@ func createRelease(t *testing.T) {
Changelog: testCase.changelog,
})
require.NoError(err)
tagName := "v" + testCase.version

tagRef, err := gRepo.Tag("v" + testCase.version)
tagRef, err := gRepo.Tag(tagName)
require.NoError(err)

tagObj, err := gRepo.TagObject(tagRef.Hash())
require.NoError(err)

require.Equal(testCase.changelog+"\n", tagObj.Message)

// Clean up tags so future test runs succeed
tagRefName := ":refs/tags/" + tagName
err = gRepo.Push(&git.PushOptions{
RemoteName: "origin",
RefSpecs: []config.RefSpec{config.RefSpec(tagRefName)},
Auth: &http.BasicAuth{
Username: "test",
Password: "test",
},
})
require.NoError(err)
}
}

Expand Down
18 changes: 18 additions & 0 deletions scripts/start-gitea.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ sleep 10

echo "creating test repo..."
curl -u 'test:test' -XPOST -H 'Content-Type: application/json' -d '{"name":"test"}' http://localhost:3000/api/v1/user/repos

echo "creating no_ff_merge repo..."
curl -u 'test:test' -XPOST -H 'Content-Type: application/json' -d '{"name":"no_ff_merge"}' http://localhost:3000/api/v1/user/repos

echo "populating no_ff_merge repo..."
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpdir')
cd $tmpdir
git init --initial-branch=master
git commit -m "feat: initial commit" --allow-empty
git tag v1.0.0
git switch -C feature
sleep 1
git commit -m "feat: feature" --allow-empty
git switch master
git merge --no-ff feature --no-edit
git push http://test:test@localhost:3000/test/no_ff_merge.git master --tags
cd -
rm -rf $tmpdir

0 comments on commit 24cb809

Please sign in to comment.