Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20250815-184431.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Improved check for LatestVersion when component has no previous versions
time: 2025-08-15T18:44:31.55796646+02:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20250815-184538.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Improve path filter when comparing paths with from different roots
time: 2025-08-15T18:45:38.055338092+02:00
11 changes: 10 additions & 1 deletion internal/cloud/client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"
"github.com/mach-composer/mcc-sdk-go/mccsdk"
"io"
)

var _ ClientWrapper = (*MccSdkClientWrapper)(nil)
Expand Down Expand Up @@ -31,7 +32,7 @@
ComponentCommitCreateDraft(mccsdk.ComponentCommitCreateDraft{
Commits: commits,
}).
Execute()

Check failure on line 35 in internal/cloud/client_wrapper.go

View workflow job for this annotation

GitHub Actions / test

response body must be closed (bodyclose)

return err
}
Expand All @@ -43,11 +44,19 @@
ComponentsApi.
ComponentLatestVersion(ctx, organization, project, componentKey).
Branch(branch).
Execute()

Check failure on line 47 in internal/cloud/client_wrapper.go

View workflow job for this annotation

GitHub Actions / test

response body must be closed (bodyclose)

// Small hack because the mccsdk cannot deserialize an empty response body
if res != nil && res.StatusCode == 200 {
return nil, nil
b, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}

if string(b) == "{}" {
// No version found, return nil without an error
return nil, nil
}
}

return r, err
Expand All @@ -61,7 +70,7 @@
Version: version,
Branch: &branch,
}).
Execute()

Check failure on line 73 in internal/cloud/client_wrapper.go

View workflow job for this annotation

GitHub Actions / test

response body must be closed (bodyclose)
return r, err
}

Expand Down
7 changes: 6 additions & 1 deletion internal/gitutils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitutils
import (
"context"
"fmt"
"path/filepath"
"strings"

"github.com/go-git/go-git/v5"
Expand All @@ -19,7 +20,9 @@ func pathFilter(paths []string) func(path string) bool {
}

for _, p := range paths {
if strings.HasPrefix(path, p) {
dirPath := filepath.Dir(path)

if strings.Contains(p, dirPath) {
return true
}
}
Expand Down Expand Up @@ -67,6 +70,8 @@ func commitsBetween(ctx context.Context, repository *git.Repository, first, last
lastHash = val
}

log.Debug().Msgf("First hash: %s, Last hash: %s", firstHash, lastHash)

cIter, err := repository.Log(&git.LogOptions{
Order: git.LogOrderCommitterTime,
PathFilter: pathFilter(paths),
Expand Down
1 change: 1 addition & 0 deletions internal/gitutils/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func TestPathFilter(t *testing.T) {
assert.True(t, pathFilter([]string{})("test/test"))
assert.True(t, pathFilter([]string{"test"})("test/test"))
assert.True(t, pathFilter([]string{"foo/bar/baz/test"})("test/file.txt"))
assert.False(t, pathFilter([]string{"foo"})("test/test"))
}

Expand Down
Loading