Skip to content

Commit 2a0b008

Browse files
authored
Fix/commit handling (#533)
<!-- Describe in detail the changes you are proposing, and the rationale. --> <!-- Link all GitHub issues fixed by this PR, and add references to prior related PRs. --> Fixes # ### NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES | EXPERIMENTS <!-- Write a short description of your changes. Examples: - Fixed a bug - Added a new feature - Updated documentation --> -
2 parents 61a2404 + 5d1e78b commit 2a0b008

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixed
2+
body: Improved check for LatestVersion when component has no previous versions
3+
time: 2025-08-15T18:44:31.55796646+02:00
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixed
2+
body: Improve path filter when comparing paths with from different roots
3+
time: 2025-08-15T18:45:38.055338092+02:00

internal/cloud/client_wrapper.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cloud
33
import (
44
"context"
55
"github.com/mach-composer/mcc-sdk-go/mccsdk"
6+
"io"
67
)
78

89
var _ ClientWrapper = (*MccSdkClientWrapper)(nil)
@@ -47,7 +48,15 @@ func (m *MccSdkClientWrapper) GetLatestComponentVersion(ctx context.Context, org
4748

4849
// Small hack because the mccsdk cannot deserialize an empty response body
4950
if res != nil && res.StatusCode == 200 {
50-
return nil, nil
51+
b, err := io.ReadAll(res.Body)
52+
if err != nil {
53+
return nil, err
54+
}
55+
56+
if string(b) == "{}" {
57+
// No version found, return nil without an error
58+
return nil, nil
59+
}
5160
}
5261

5362
return r, err

internal/gitutils/diff.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gitutils
33
import (
44
"context"
55
"fmt"
6+
"path/filepath"
67
"strings"
78

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

2122
for _, p := range paths {
22-
if strings.HasPrefix(path, p) {
23+
dirPath := filepath.Dir(path)
24+
25+
if strings.Contains(p, dirPath) {
2326
return true
2427
}
2528
}
@@ -67,6 +70,8 @@ func commitsBetween(ctx context.Context, repository *git.Repository, first, last
6770
lastHash = val
6871
}
6972

73+
log.Debug().Msgf("First hash: %s, Last hash: %s", firstHash, lastHash)
74+
7075
cIter, err := repository.Log(&git.LogOptions{
7176
Order: git.LogOrderCommitterTime,
7277
PathFilter: pathFilter(paths),

internal/gitutils/diff_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
func TestPathFilter(t *testing.T) {
1212
assert.True(t, pathFilter([]string{})("test/test"))
1313
assert.True(t, pathFilter([]string{"test"})("test/test"))
14+
assert.True(t, pathFilter([]string{"foo/bar/baz/test"})("test/file.txt"))
1415
assert.False(t, pathFilter([]string{"foo"})("test/test"))
1516
}
1617

0 commit comments

Comments
 (0)