-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Coerce build- and source-ref to valid prerelease tokens
- Loading branch information
1 parent
49482c2
commit cf4dd11
Showing
2 changed files
with
38 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
package trunkver | ||
|
||
import "time" | ||
import ( | ||
"regexp" | ||
"time" | ||
) | ||
|
||
var sourceRefFilterRegex *regexp.Regexp = regexp.MustCompile(`[^a-zA-Z0-9]`) | ||
|
||
func coerceSourceRef(sourceRef string) string { | ||
return sourceRefFilterRegex.ReplaceAllString(sourceRef, "") | ||
} | ||
|
||
var buildRefFilterRegex *regexp.Regexp = regexp.MustCompile(`[^a-zA-Z0-9-]`) | ||
|
||
func coerceBuildRef(buildRef string) string { | ||
return buildRefFilterRegex.ReplaceAllString(buildRef, "-") | ||
} | ||
|
||
func GenerateMajorTrunkver(ts time.Time, sourceRef, buildRef string) string { | ||
return ts.UTC().Format("20060102150405") + ".0.0-" + sourceRef + "-" + buildRef | ||
trunkVer := ts.UTC().Format("20060102150405") + ".0.0-" + coerceSourceRef(sourceRef) + "-" + coerceBuildRef(buildRef) | ||
if _, err := ParseTrunkVer(trunkVer); err != nil { | ||
panic(err) | ||
} | ||
return trunkVer | ||
} | ||
|
||
func GeneratePrereleaseTrunkver(ts time.Time, sourceRef, buildRef string) string { | ||
return ts.UTC().Format("20060102150405") + "-" + sourceRef + "-" + buildRef | ||
trunkVer := ts.UTC().Format("20060102150405") + "-" + coerceSourceRef(sourceRef) + "-" + coerceBuildRef(buildRef) | ||
if _, err := ParseTrunkVer(trunkVer); err != nil { | ||
panic(err) | ||
} | ||
return trunkVer | ||
} |
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