Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.
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
8 changes: 8 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -501,6 +502,13 @@ func getBucketSearchNextPageParam(jsonParsed *gabs.Container) string {
return "&pageToken=" + nextPageToken
}

// IsCommit returns true if the string matches commit format
func IsCommit(s string) bool {
re := regexp.MustCompile(`\b[0-9a-f]{5,40}\b`)

return re.MatchString(s)
}

func processBucketSearchPage(jsonParsed *gabs.Container, currentPage int, bucket string, prefix string, object string) (string, error) {
items := jsonParsed.Path("items").Children()

Expand Down
16 changes: 16 additions & 0 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ func TestGetGCPBucketCoordinates_Snapshots(t *testing.T) {
})
}

func TestIsCommit(t *testing.T) {
t.Run("Returns true with commits", func(t *testing.T) {
assert.True(t, IsCommit("abcdef1234"))
assert.True(t, IsCommit("a12345"))
assert.True(t, IsCommit("abcdef1"))
})

t.Run("Returns false with non-commits", func(t *testing.T) {
assert.False(t, IsCommit("master"))
assert.False(t, IsCommit("7.x"))
assert.False(t, IsCommit("7.12.x"))
assert.False(t, IsCommit("7.11.x"))
assert.False(t, IsCommit("pr12345"))
})
}

func TestProcessBucketSearchPage_CommitFound(t *testing.T) {
// retrieving last element in commits.json
object := "024b732844d40bdb2bf806480af2b03fcb8fbdbe/elastic-agent/elastic-agent-8.0.0-SNAPSHOT-darwin-x86_64.tar.gz"
Expand Down