mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-01-23 02:15:12 +00:00
feat: Add Next and Previous in Tag
This commit is contained in:
parent
cd9684604b
commit
d4d2a7ed80
3 changed files with 109 additions and 16 deletions
12
fields.go
12
fields.go
|
|
@ -78,12 +78,20 @@ type CommitGroup struct {
|
|||
Commits []*Commit
|
||||
}
|
||||
|
||||
// Tag ...
|
||||
type Tag struct {
|
||||
// RelateTag ...
|
||||
type RelateTag struct {
|
||||
Name string
|
||||
Date time.Time
|
||||
}
|
||||
|
||||
// Tag ...
|
||||
type Tag struct {
|
||||
Name string
|
||||
Date time.Time
|
||||
Next *RelateTag
|
||||
Previous *RelateTag
|
||||
}
|
||||
|
||||
// Version ...
|
||||
type Version struct {
|
||||
Tag *Tag
|
||||
|
|
|
|||
|
|
@ -61,5 +61,31 @@ func (r *tagReader) ReadAll() ([]*Tag, error) {
|
|||
})
|
||||
}
|
||||
|
||||
total := len(tags)
|
||||
|
||||
for i, tag := range tags {
|
||||
var (
|
||||
next *RelateTag
|
||||
prev *RelateTag
|
||||
)
|
||||
|
||||
if i > 0 {
|
||||
next = &RelateTag{
|
||||
Name: tags[i-1].Name,
|
||||
Date: tags[i-1].Date,
|
||||
}
|
||||
}
|
||||
|
||||
if i+1 < total {
|
||||
prev = &RelateTag{
|
||||
Name: tags[i+1].Name,
|
||||
Date: tags[i+1].Date,
|
||||
}
|
||||
}
|
||||
|
||||
tag.Next = next
|
||||
tag.Previous = prev
|
||||
}
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
|
@ -29,20 +30,78 @@ func TestTagReader(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
res, err := newTagReader(client).ReadAll()
|
||||
actual, err := newTagReader(client).ReadAll()
|
||||
assert.Nil(err)
|
||||
|
||||
actual := make([]string, len(res))
|
||||
for i, tag := range res {
|
||||
actual[i] = tag.Name
|
||||
}
|
||||
|
||||
assert.Equal([]string{
|
||||
"v5.2.0-beta.1",
|
||||
"2.0.0",
|
||||
"v2.0.4-rc.1",
|
||||
"2.0.4-beta.1",
|
||||
"hoge_fuga",
|
||||
"1.9.29-alpha.0",
|
||||
}, actual)
|
||||
assert.Equal(
|
||||
[]*Tag{
|
||||
&Tag{
|
||||
Name: "v5.2.0-beta.1",
|
||||
Date: time.Unix(1518023112, 0),
|
||||
Next: nil,
|
||||
Previous: &RelateTag{
|
||||
Name: "2.0.0",
|
||||
Date: time.Unix(1517875200, 0),
|
||||
},
|
||||
},
|
||||
&Tag{
|
||||
Name: "2.0.0",
|
||||
Date: time.Unix(1517875200, 0),
|
||||
Next: &RelateTag{
|
||||
Name: "v5.2.0-beta.1",
|
||||
Date: time.Unix(1518023112, 0),
|
||||
},
|
||||
Previous: &RelateTag{
|
||||
Name: "v2.0.4-rc.1",
|
||||
Date: time.Unix(1517788800, 0),
|
||||
},
|
||||
},
|
||||
&Tag{
|
||||
Name: "v2.0.4-rc.1",
|
||||
Date: time.Unix(1517788800, 0),
|
||||
Next: &RelateTag{
|
||||
Name: "2.0.0",
|
||||
Date: time.Unix(1517875200, 0),
|
||||
},
|
||||
Previous: &RelateTag{
|
||||
Name: "2.0.4-beta.1",
|
||||
Date: time.Unix(1517702400, 0),
|
||||
},
|
||||
},
|
||||
&Tag{
|
||||
Name: "2.0.4-beta.1",
|
||||
Date: time.Unix(1517702400, 0),
|
||||
Next: &RelateTag{
|
||||
Name: "v2.0.4-rc.1",
|
||||
Date: time.Unix(1517788800, 0),
|
||||
},
|
||||
Previous: &RelateTag{
|
||||
Name: "hoge_fuga",
|
||||
Date: time.Unix(1517616000, 0),
|
||||
},
|
||||
},
|
||||
&Tag{
|
||||
Name: "hoge_fuga",
|
||||
Date: time.Unix(1517616000, 0),
|
||||
Next: &RelateTag{
|
||||
Name: "2.0.4-beta.1",
|
||||
Date: time.Unix(1517702400, 0),
|
||||
},
|
||||
Previous: &RelateTag{
|
||||
Name: "1.9.29-alpha.0",
|
||||
Date: time.Unix(1517529600, 0),
|
||||
},
|
||||
},
|
||||
&Tag{
|
||||
Name: "1.9.29-alpha.0",
|
||||
Date: time.Unix(1517529600, 0),
|
||||
Next: &RelateTag{
|
||||
Name: "hoge_fuga",
|
||||
Date: time.Unix(1517616000, 0),
|
||||
},
|
||||
Previous: nil,
|
||||
},
|
||||
},
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue