-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: extract function * print resolved version when applicable * refactor: simplify conditionals * refactor: simplify conditional * test cases: version row for major and minor lock * build correct version info row string * refactor: remove useless code * print dotted changelog URL * refactor: put major and minor test case together * test case: url cropping * empty line in box under version info * dont show update info if latest version fits lock * remove development related temp code * remove unrelated logic from tests * improve test case name * refactor: simplify string production * test case for 1.x and 1.x.x format * refactor: extract update handling to separate file * refactor: consolidate update check flow * handle semver parse error * remove testing code * refactor: make naming consistent * monkey patch dependency * fallback to repo url when releases url is unknown * dep update Co-authored-by: lszucs <[email protected]>
- Loading branch information
Showing
10 changed files
with
670 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package bitrise | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/bitrise-io/go-utils/log" | ||
stepmanModels "github.com/bitrise-io/stepman/models" | ||
ver "github.com/hashicorp/go-version" | ||
) | ||
|
||
func isUpdateAvailable(stepInfo stepmanModels.StepInfoModel) bool { | ||
if stepInfo.LatestVersion == "" { | ||
return false | ||
} | ||
|
||
re := regexp.MustCompile(`\d+`) | ||
components := re.FindAllString(stepInfo.Version, -1) | ||
normalized := strings.Join(components, ".") | ||
locked, err := ver.NewSemver(normalized) | ||
|
||
if err != nil { | ||
log.Warnf("Error processing version (%s): normalized version (%s) not in semver format: %s", stepInfo.Version, normalized, err) | ||
return false | ||
} | ||
|
||
latest, err := ver.NewSemver(stepInfo.LatestVersion) | ||
if err != nil { | ||
log.Warnf("Error processing latest version (%s): %s", stepInfo.LatestVersion, err) | ||
return false | ||
} | ||
|
||
switch len(components) { | ||
case 1: | ||
return locked.Segments()[0] < latest.Segments()[0] | ||
case 2: | ||
return locked.Segments()[0] < latest.Segments()[0] || locked.Segments()[1] < latest.Segments()[1] | ||
case 3: | ||
return locked.LessThan(latest) | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func repoReleasesURL(repoURL string) string { | ||
if strings.Contains(repoURL, "github") || strings.Contains(repoURL, "gitlab") { | ||
return repoURL + "/releases" | ||
} | ||
|
||
return repoURL | ||
} |
Oops, something went wrong.