func isUpgradeRequired()

in tools/version-tracker/pkg/github/github.go [220:255]


func isUpgradeRequired(client *github.Client, org, repo, latestRevision string, currentRevisionCommitEpoch int64, currentRevisionSemver *semver.Version, allTags []*github.RepositoryTag) (bool, bool, error) {
	var needsUpgrade, shouldBreak bool

	// Get commit hash corresponding to latest revision tag.
	latestRevisionCommit := getCommitForTag(allTags, latestRevision)
	if latestRevisionCommit == "" {
		return false, false, fmt.Errorf("empty commit hash for latest revision: %s", latestRevision)
	}

	// Get Unix timestamp for latest revision's commit.
	latestRevisionCommitEpoch, err := getCommitDateEpoch(client, org, repo, latestRevisionCommit)
	if err != nil {
		return false, false, fmt.Errorf("getting epoch time corresponding to latest revision commit: %v", err)
	}

	semverRegex := regexp.MustCompile(constants.SemverRegex)
	latestRevisionForSemver := version.EnsurePatchVersion(semverRegex.FindString(latestRevision))

	// Get SemVer construct corresponding to the latest revision tag.
	latestRevisionSemver, err := semver.New(latestRevisionForSemver)
	if err != nil {
		return false, false, fmt.Errorf("getting semver for latest version: %v", err)
	}

	// If the latest revision comes after the current revision both chronologically and semantically, then declare that
	// an upgrade is required
	if latestRevisionSemver.GreaterThan(currentRevisionSemver) || latestRevisionCommitEpoch > currentRevisionCommitEpoch {
		needsUpgrade = true
		shouldBreak = true
	} else if latestRevisionSemver.Equal(currentRevisionSemver) {
		needsUpgrade = false
		shouldBreak = true
	}

	return needsUpgrade, shouldBreak, nil
}