Beispiel #1
0
func fetchTags(releasePattern string, sortON bool) []string {
	out, _ := exec.Command("git", "log", "--tags", "--simplify-by-decoration", "--pretty=\"%ai @%d\"").Output()
	uncuratedTags := strings.Split(string(out), "\n")

	var tags []string
	validTag := regexp.MustCompile(fmt.Sprintf(`(.*\s)@\s.*tag:\s(%v)`, releasePattern))

	var match [][]string
	for _, tag := range uncuratedTags {
		match = validTag.FindAllStringSubmatch(tag, -1)
		if len(match) > 0 && len(match[0]) > 2 {
			// fmt.Printf("%v => %v \n", match[0][1], match[0][2])
			tags = append(tags, strings.Replace(match[0][2], ",", "", -1))
		}
	}
	if sortON {
		tags = utils.OnlyStable(tags)
		sort.Sort(utils.ByVersion(tags))
	}
	return tags
}
func TestSortByVersionWithAflfanumeric(t *testing.T) {
	versions := []string{"release-0.999", "release-1.0.0", "release-1.0.123", "release-1.0.123.1"}
	sort.Sort(utils.ByVersion(versions))
	assert.Equal(t, []string{"release-1.0.123.1", "release-1.0.123", "release-1.0.0", "release-0.999"}, versions)
}
func TestSortByVersion(t *testing.T) {
	versions := []string{"0.999", "1.0.0", "1.0.123", "1.0.123.1"}
	sort.Sort(utils.ByVersion(versions))
	assert.Equal(t, []string{"1.0.123.1", "1.0.123", "1.0.0", "0.999"}, versions)
}