-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Valery Piashchynski <[email protected]>
- Loading branch information
Showing
11 changed files
with
210 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
"time" | ||
|
||
m "golang.org/x/mod/module" | ||
) | ||
|
||
var vr = regexp.MustCompile(`/v(\\d+)$`) | ||
|
||
// here we accept a module name and return the version | ||
// e.g.: github.com/roadrunner-server/logger/v2 => v2 | ||
func parseModuleInfo(module string, t time.Time, rev string) string { | ||
match := vr.FindStringSubmatch(module) | ||
var version string | ||
if len(match) > 1 { | ||
if !IsDigit(match[1]) { | ||
return m.PseudoVersion("", "", t, rev) | ||
} | ||
|
||
version = fmt.Sprintf("v%s", match[1]) | ||
} | ||
|
||
return m.PseudoVersion(version, "", t, rev) | ||
} | ||
|
||
func IsDigit(num string) bool { | ||
_, err := strconv.ParseInt(num, 10, 64) | ||
return err == nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package github | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type tm struct { | ||
module string | ||
tm time.Time | ||
sha string | ||
expect string | ||
} | ||
|
||
func TestParse(t *testing.T) { | ||
tn, err := time.Parse("20060102150405", "20231008162055") | ||
require.NoError(t, err) | ||
|
||
tests := []tm{ | ||
{ | ||
module: "github.com/roadrunner-server/logger/va", | ||
tm: tn, | ||
sha: "1234567890", | ||
expect: "v0.0.0-20231008162055-1234567890", | ||
}, | ||
{ | ||
module: "github.com/roadrunner-server/logger/v2", | ||
tm: tn, | ||
sha: "1234567890", | ||
expect: "v2.0.0-20231008162055-1234567890", | ||
}, | ||
{ | ||
module: "github.com/roadrunner-server/logger/v2222222222222", | ||
tm: tn, | ||
sha: "1234567890", | ||
expect: "v2222222222222.0.0-20231008162055-1234567890", | ||
}, | ||
{ | ||
module: "github.com/roadrunner-server/logger", | ||
tm: tn, | ||
sha: "1234567890", | ||
expect: "v0.0.0-20231008162055-1234567890", | ||
}, | ||
{ | ||
module: "github.com/roadrunner-server/logger/v2", | ||
tm: tn, | ||
sha: "", | ||
expect: "v2.0.0-20231008162055-", | ||
}, | ||
{ | ||
expect: "v0.0.0-00010101000000-", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
out := parseModuleInfo(tt.module, tt.tm, tt.sha) | ||
assert.Equal(t, tt.expect, out) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.