Example #1
0
// GetTags returns the tags list for the current repository.
func (r *Repository) GetTags() ([]Tag, error) {
	var ts []Tag

	// Retrieve the tags
	err := r.repository.Tags.Foreach(func(name string, id *git.Oid) error {
		tn := strings.Replace(name, "refs/tags/", "", -1)
		tg, err := r.buildTag(tn, id)
		if err != nil {
			return err
		}

		if semver.IsValid(tn) {
			ts = append(ts, tg)
		}

		return nil
	})

	if err != nil {
		return nil, err
	}

	st := make(timeSlice, 0, len(ts))
	for _, d := range ts {
		st = append(st, d)
	}
	sort.Sort(st)

	if len(st) == 0 {
		return nil, errNoTagFound
	}

	return st.GetSlice(), nil
}
Example #2
0
func TestSemverValidation(t *testing.T) {
	var v bool

	Convey("Valid versions should be validated", t, func() {
		v = semver.IsValid("1.0.0")
		So(v, ShouldBeTrue)

		v = semver.IsValid("1.0.0-foo")
		So(v, ShouldBeTrue)

		v = semver.IsValid("11.12.0-rc.1")
		So(v, ShouldBeTrue)
	})

	Convey("Invalid versions should be refused", t, func() {
		v = semver.IsValid("1.0")
		So(v, ShouldBeFalse)

		v = semver.IsValid("1")
		So(v, ShouldBeFalse)

		v = semver.IsValid("foo")
		So(v, ShouldBeFalse)
	})
}