diff --git a/cli/commands/generate/generate_test.go b/cli/commands/generate/generate_test.go index 55d6fb5..6599ba2 100644 --- a/cli/commands/generate/generate_test.go +++ b/cli/commands/generate/generate_test.go @@ -31,7 +31,7 @@ import ( _ "github.com/artem-sidorenko/chagen/internal/testing/testconnector" ) -func genOutput(newRelease, testingTag, secondTag, excludedIssue bool) string { +func genOutput(newRelease, testingTag, minorTags, excludedIssue bool) string { // nolint: lll tpl := `Changelog ========= @@ -42,59 +42,99 @@ func genOutput(newRelease, testingTag, secondTag, excludedIssue bool) string { Closed issues ------------- -- Issue 3 [\#3](http://test.example.com/issues/3) -{{- if .ExcludedIssue }} -- Issue 6 [\#6](http://test.example.com/issues/6) -{{- else }} -- Issue 5 [\#5](http://test.example.com/issues/5) +- Test issue title 13 [\#1234](http://test.example.com/issues/1234) +{{- if not .ExcludedIssue }} +- Test issue title 12 [\#1224](http://test.example.com/issues/1224) {{- end }} -- Issue 4 [\#4](http://test.example.com/issues/4) Merged pull requests -------------------- -- MR 4 [\#4](https://test.example.com/mrs/4) ([testauthor](https://test.example.com/authors/testauthor)) +- Test PR title 14 [\#2344](https://test.example.com/mrs/2344) ([te77st-user](https://test.example.com/authors/te77st-user)) +- Test PR title 13 [\#2334](https://test.example.com/mrs/2334) ([test-user](https://test.example.com/authors/test-user)) {{- end }} -## [v0.0.3](https://test.example.com/tags/v0.0.3) (13.07.2009) +{{- if .SecondTag }} + +## [v0.1.2](https://test.example.com/tags/v0.1.2) (20.03.2003) + +## [v0.1.1](https://test.example.com/tags/v0.1.1) (19.03.2003) + +Merged pull requests +-------------------- +- Test PR title 10 [\#2304](https://test.example.com/mrs/2304) ([test-user](https://test.example.com/authors/test-user)) + +## [v0.1.0](https://test.example.com/tags/v0.1.0) (18.03.2003) Closed issues ------------- -- Issue 2 [\#2](http://test.example.com/issues/2) +- Test issue title 9 [\#1294](http://test.example.com/issues/1294) Merged pull requests -------------------- -- MR 2 [\#2](https://test.example.com/mrs/2) ([testauthor](https://test.example.com/authors/testauthor)) +- Test PR title 9 [\#2294](https://test.example.com/mrs/2294) ([test-user](https://test.example.com/authors/test-user)) -{{- if not .SecondTag }} -- MR 3 [\#3](https://test.example.com/mrs/3) ([testauthor](https://test.example.com/authors/testauthor)) {{- end }} +## [v0.0.9](https://test.example.com/tags/v0.0.9) (17.03.2003) + +## [v0.0.8](https://test.example.com/tags/v0.0.8) (16.03.2003) + +Merged pull requests +-------------------- +- Test PR title 7 [\#2274](https://test.example.com/mrs/2274) ([test5-user](https://test.example.com/authors/test5-user)) + +## [v0.0.7](https://test.example.com/tags/v0.0.7) (14.03.2003) + +Merged pull requests +-------------------- +- Test PR title 6 [\#2264](https://test.example.com/mrs/2264) ([test-user](https://test.example.com/authors/test-user)) + {{- if .TestingTag }} -## [testingtag](https://test.example.com/tags/testingtag) (16.05.2006) +## [testingtag](https://test.example.com/tags/testingtag) (13.03.2003) {{- end }} -{{- if .SecondTag }} +## [v0.0.6](https://test.example.com/tags/v0.0.6) (13.03.2003) + +Merged pull requests +-------------------- +- Test PR title 5 [\#2254](https://test.example.com/mrs/2254) ([test-user](https://test.example.com/authors/test-user)) + +## [v0.0.5](https://test.example.com/tags/v0.0.5) (12.03.2003) + +Closed issues +------------- +- Test issue title 4 [\#1244](http://test.example.com/issues/1244) -## [v0.0.2](https://test.example.com/tags/v0.0.2) (13.05.2006) +## [v0.0.4](https://test.example.com/tags/v0.0.4) (11.03.2003) Merged pull requests -------------------- -- MR 3 [\#3](https://test.example.com/mrs/3) ([testauthor](https://test.example.com/authors/testauthor)) +- Test PR title 3 [\#2234](https://test.example.com/mrs/2234) ([test-user](https://test.example.com/authors/test-user)) -{{- end }} +## [v0.0.3](https://test.example.com/tags/v0.0.3) (10.03.2003) + +Closed issues +------------- +- Test issue title 2 [\#1227](http://test.example.com/issues/1227) -## [v0.0.1](https://test.example.com/tags/v0.0.1) (12.03.2003) +Merged pull requests +-------------------- +- Test PR title 2 [\#2224](https://test.example.com/mrs/2224) ([test-user2](https://test.example.com/authors/test-user2)) + +## [v0.0.2](https://test.example.com/tags/v0.0.2) (09.03.2003) Closed issues ------------- -- Issue 1 [\#1](http://test.example.com/issues/1) +- Test issue title 1 [\#1214](http://test.example.com/issues/1214) Merged pull requests -------------------- -- MR 1 [\#1](https://test.example.com/mrs/1) ([testauthor](https://test.example.com/authors/testauthor)) +- Test PR title 1 [\#2214](https://test.example.com/mrs/2214) ([test-user](https://test.example.com/authors/test-user)) + +## [v0.0.1](https://test.example.com/tags/v0.0.1) (08.03.2003) *This Changelog was automatically generated with [chagen unknown](https://github.com/artem-sidorenko/chagen)* ` @@ -105,7 +145,7 @@ Merged pull requests TestingTag bool SecondTag bool ExcludedIssue bool - }{newRelease, time.Now().Format("02.01.2006"), testingTag, secondTag, excludedIssue} + }{newRelease, time.Now().Format("02.01.2006"), testingTag, minorTags, excludedIssue} t := template.Must(template.New("Output template").Parse(tpl)) @@ -153,7 +193,7 @@ func TestGenerate(t *testing.T) { // nolint: gocyclo { name: "With customized filter", cliParams: cliParams{ - filterExpr: `^v\d+\.\d+\.(1|3)+$`, + filterExpr: `^v\d+\.0\.\d+$`, }, wantOutput: genOutput(false, false, false, false), }, @@ -167,7 +207,7 @@ func TestGenerate(t *testing.T) { // nolint: gocyclo { name: "With customized labels", cliParams: cliParams{ - excludeLabels: "issue5", + excludeLabels: "issue12, duplicate, question, invalid, wontfix, no changelog", newRelease: "v10.10.0", }, wantOutput: genOutput(true, false, true, true), diff --git a/data/helpers.go b/data/helpers.go index 6f9d1ee..148ebf6 100644 --- a/data/helpers.go +++ b/data/helpers.go @@ -24,3 +24,18 @@ func sliceContains(slice []string, str string) bool { } return false } + +// UTCDate sets all time within data to the UTC +func UTCDate(ts Tags, is Issues, mrs MRs) { + for i, t := range ts { + ts[i].Date = t.Date.UTC() + } + + for i, d := range is { + is[i].ClosedDate = d.ClosedDate.UTC() + } + + for i, mr := range mrs { + mrs[i].MergedDate = mr.MergedDate.UTC() + } +} diff --git a/data/issue_test.go b/data/issue_test.go index 8558016..596d6c2 100644 --- a/data/issue_test.go +++ b/data/issue_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/artem-sidorenko/chagen/data" + "github.com/artem-sidorenko/chagen/internal/testing/helpers" ) func TestIssues_Sort(t *testing.T) { @@ -36,29 +37,29 @@ func TestIssues_Sort(t *testing.T) { is: &data.Issues{ { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), }, }, want: &data.Issues{ { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), }, }, }, @@ -67,29 +68,29 @@ func TestIssues_Sort(t *testing.T) { is: &data.Issues{ { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), }, }, want: &data.Issues{ { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), }, }, }, @@ -121,25 +122,25 @@ func TestIssues_Filter(t *testing.T) { is: data.Issues{ { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), }, }, args: args{ - fromDate: time.Unix(1057483647, 0), - toDate: time.Unix(1337483647, 0), + fromDate: helpers.Time(1057483647), + toDate: helpers.Time(1337483647), }, wantRet: data.Issues{ { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, }, }, @@ -148,25 +149,25 @@ func TestIssues_Filter(t *testing.T) { is: data.Issues{ { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), }, }, args: args{ - fromDate: time.Unix(1057483647, 0), - toDate: time.Unix(1247483647, 0), + fromDate: helpers.Time(1057483647), + toDate: helpers.Time(1247483647), }, wantRet: data.Issues{ { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, }, }, @@ -197,16 +198,16 @@ func TestFilterIssuesByLabel(t *testing.T) { is: data.Issues{ { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), Labels: []string{"bugfix"}, }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, }, @@ -215,16 +216,16 @@ func TestFilterIssuesByLabel(t *testing.T) { want: data.Issues{ { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), Labels: []string{"bugfix"}, }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, }, @@ -235,27 +236,27 @@ func TestFilterIssuesByLabel(t *testing.T) { is: data.Issues{ { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), Labels: []string{"bugfix", "enhancement"}, }, { Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), + ClosedDate: helpers.Time(1247483647), Labels: []string{"no changelog"}, }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, { Name: "Issue 4", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), Labels: []string{"enhancement", "no changelog"}, }, { Name: "Issue 5", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), Labels: []string{"bug", "wontfix"}, }, }, @@ -264,12 +265,12 @@ func TestFilterIssuesByLabel(t *testing.T) { want: data.Issues{ { Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), + ClosedDate: helpers.Time(1047483647), Labels: []string{"bugfix", "enhancement"}, }, { Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), + ClosedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, }, diff --git a/data/mrs_test.go b/data/mrs_test.go index 4c76f09..2d6f41c 100644 --- a/data/mrs_test.go +++ b/data/mrs_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/artem-sidorenko/chagen/data" + "github.com/artem-sidorenko/chagen/internal/testing/helpers" ) func TestMRs_Sort(t *testing.T) { @@ -36,29 +37,29 @@ func TestMRs_Sort(t *testing.T) { m: &data.MRs{ { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), }, }, want: &data.MRs{ { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), }, }, }, @@ -67,29 +68,29 @@ func TestMRs_Sort(t *testing.T) { m: &data.MRs{ { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), }, }, want: &data.MRs{ { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), }, }, }, @@ -121,25 +122,25 @@ func TestMRs_Filter(t *testing.T) { m: data.MRs{ { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), }, }, args: args{ - fromDate: time.Unix(1057483647, 0), - toDate: time.Unix(1337483647, 0), + fromDate: helpers.Time(1057483647), + toDate: helpers.Time(1337483647), }, wantRet: data.MRs{ { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, }, }, @@ -148,25 +149,25 @@ func TestMRs_Filter(t *testing.T) { m: data.MRs{ { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), }, }, args: args{ - fromDate: time.Unix(1057483647, 0), - toDate: time.Unix(1247483647, 0), + fromDate: helpers.Time(1057483647), + toDate: helpers.Time(1247483647), }, wantRet: data.MRs{ { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, }, }, @@ -197,16 +198,16 @@ func TestFilterMRsByLabel(t *testing.T) { m: data.MRs{ { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), Labels: []string{"bugfix"}, }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, }, @@ -215,16 +216,16 @@ func TestFilterMRsByLabel(t *testing.T) { want: data.MRs{ { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), Labels: []string{"bugfix"}, }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, }, @@ -235,27 +236,27 @@ func TestFilterMRsByLabel(t *testing.T) { m: data.MRs{ { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), Labels: []string{"bugfix", "enhancement"}, }, { Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), + MergedDate: helpers.Time(1247483647), Labels: []string{"no changelog"}, }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, { Name: "MR 4", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), Labels: []string{"enhancement", "no changelog"}, }, { Name: "MR 5", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), Labels: []string{"bug", "wontfix"}, }, }, @@ -264,12 +265,12 @@ func TestFilterMRsByLabel(t *testing.T) { want: data.MRs{ { Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), + MergedDate: helpers.Time(1047483647), Labels: []string{"bugfix", "enhancement"}, }, { Name: "MR 3", - MergedDate: time.Unix(1347483647, 0), + MergedDate: helpers.Time(1347483647), Labels: []string{"enhancement"}, }, }, diff --git a/data/releases.go b/data/releases.go index 21318c7..beab7f9 100644 --- a/data/releases.go +++ b/data/releases.go @@ -41,6 +41,9 @@ func NewReleases(tags Tags, issues Issues, mrs MRs) Releases { var ret Releases var lastReleaseDate time.Time + // we should work always with UTC time to avoid surprises + UTCDate(tags, issues, mrs) + // we should have a proper sorted data to avoid surprises sort.Sort(&tags) sort.Sort(&issues) diff --git a/data/releases_test.go b/data/releases_test.go index ab16ac1..c327fa4 100644 --- a/data/releases_test.go +++ b/data/releases_test.go @@ -19,10 +19,10 @@ package data_test import ( "reflect" "testing" - "time" "github.com/artem-sidorenko/chagen/data" - "github.com/artem-sidorenko/chagen/internal/testing/testconnector/testdata" + "github.com/artem-sidorenko/chagen/internal/testing/helpers" + "github.com/artem-sidorenko/chagen/internal/testing/testdata" ) func TestNewReleases(t *testing.T) { @@ -34,74 +34,243 @@ func TestNewReleases(t *testing.T) { name: "proper data with all elements", wantRet: data.Releases{ data.Release{ - Release: "v0.0.3", - Date: "13.07.2009", - ReleaseURL: "https://test.example.com/tags/v0.0.3", + Release: "v0.1.2", + Date: "20.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.1.2", + MRs: data.MRs{ + data.MR{ + ID: 2314, + Name: "Test PR title 11", + URL: "https://test.example.com/mrs/2314", + MergedDate: helpers.Time(1048094647), + Author: "test-user8", + AuthorURL: "https://test.example.com/authors/test-user8", + Labels: []string{"no changelog"}, + }, + }, + }, + data.Release{ + Release: "v0.1.1", + Date: "19.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.1.1", Issues: data.Issues{ data.Issue{ - ID: 2, - Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), - URL: "http://test.example.com/issues/2", + ID: 1304, + Name: "Test issue title 10", + ClosedDate: helpers.Time(1047993647), + URL: "http://test.example.com/issues/1304", + Labels: []string{"wontfix"}, }, }, MRs: data.MRs{ data.MR{ - ID: 2, - Name: "MR 2", - URL: "https://test.example.com/mrs/2", - MergedDate: time.Unix(1247483647, 0), - Author: "testauthor", - AuthorURL: "https://test.example.com/authors/testauthor", + ID: 2304, + Name: "Test PR title 10", + URL: "https://test.example.com/mrs/2304", + MergedDate: helpers.Time(1047994647), + Author: "test-user", + AuthorURL: "https://test.example.com/authors/test-user", + Labels: []string{"bugfix"}, }, }, }, data.Release{ - Release: "v0.0.2", - Date: "13.05.2006", - ReleaseURL: "https://test.example.com/tags/v0.0.2", + Release: "v0.1.0", + Date: "18.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.1.0", + Issues: data.Issues{ + data.Issue{ + ID: 1294, + Name: "Test issue title 9", + ClosedDate: helpers.Time(1047893647), + URL: "http://test.example.com/issues/1294", + }, + }, MRs: data.MRs{ data.MR{ - ID: 3, - Name: "MR 3", - URL: "https://test.example.com/mrs/3", - MergedDate: time.Unix(1057483647, 0), - Author: "testauthor", - AuthorURL: "https://test.example.com/authors/testauthor", + ID: 2294, + Name: "Test PR title 9", + URL: "https://test.example.com/mrs/2294", + MergedDate: helpers.Time(1047894647), + Author: "test-user", + AuthorURL: "https://test.example.com/authors/test-user", + Labels: []string{"bugfix"}, }, }, }, data.Release{ - Release: "v0.0.1", + Release: "v0.0.9", + Date: "17.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.9", + MRs: data.MRs{ + data.MR{ + ID: 2284, + Name: "Test PR title 8", + URL: "https://test.example.com/mrs/2284", + MergedDate: helpers.Time(1047794647), + Author: "test-user", + AuthorURL: "https://test.example.com/authors/test-user", + Labels: []string{"invalid"}, + }, + }, + }, + data.Release{ + Release: "v0.0.8", + Date: "16.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.8", + Issues: data.Issues{ + data.Issue{ + ID: 1274, + Name: "Test issue title 7", + ClosedDate: helpers.Time(1047693647), + URL: "http://test.example.com/issues/1274", + Labels: []string{"no changelog"}, + }, + }, + MRs: data.MRs{ + data.MR{ + ID: 2274, + Name: "Test PR title 7", + URL: "https://test.example.com/mrs/2274", + MergedDate: helpers.Time(1047694647), + Author: "test5-user", + AuthorURL: "https://test.example.com/authors/test5-user", + Labels: []string{"bugfix"}, + }, + }, + }, + data.Release{ + Release: "v0.0.7", + Date: "14.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.7", + Issues: data.Issues{ + data.Issue{ + ID: 1264, + Name: "Test issue title 6", + ClosedDate: helpers.Time(1047593647), + URL: "http://test.example.com/issues/1264", + Labels: []string{"invalid"}, + }, + }, + MRs: data.MRs{ + data.MR{ + ID: 2264, + Name: "Test PR title 6", + URL: "https://test.example.com/mrs/2264", + MergedDate: helpers.Time(1047594647), + Author: "test-user", + AuthorURL: "https://test.example.com/authors/test-user", + Labels: []string{"enhancement"}, + }, + }, + }, + data.Release{ + Release: "v0.0.6", + Date: "13.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.6", + MRs: data.MRs{ + data.MR{ + ID: 2254, + Name: "Test PR title 5", + URL: "https://test.example.com/mrs/2254", + MergedDate: helpers.Time(1047494647), + Author: "test-user", + AuthorURL: "https://test.example.com/authors/test-user", + Labels: []string{"bugfix"}, + }, + }, + }, + data.Release{ + Release: "v0.0.5", Date: "12.03.2003", - ReleaseURL: "https://test.example.com/tags/v0.0.1", + ReleaseURL: "https://test.example.com/tags/v0.0.5", Issues: data.Issues{ data.Issue{ - ID: 1, - Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), - URL: "http://test.example.com/issues/1", + ID: 1244, + Name: "Test issue title 4", + ClosedDate: helpers.Time(1047393647), + URL: "http://test.example.com/issues/1244", }, }, + }, + data.Release{ + Release: "v0.0.4", + Date: "11.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.4", MRs: data.MRs{ data.MR{ - ID: 1, - Name: "MR 1", - URL: "https://test.example.com/mrs/1", - MergedDate: time.Unix(1047483647, 0), - Author: "testauthor", - AuthorURL: "https://test.example.com/authors/testauthor", + ID: 2234, + Name: "Test PR title 3", + URL: "https://test.example.com/mrs/2234", + MergedDate: helpers.Time(1047294647), + Author: "test-user", + AuthorURL: "https://test.example.com/authors/test-user", + Labels: []string{"enhancement", "bugfix"}, + }, + }, + }, + data.Release{ + Release: "v0.0.3", + Date: "10.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.3", + Issues: data.Issues{ + data.Issue{ + ID: 1227, + Name: "Test issue title 2", + ClosedDate: helpers.Time(1047193647), + URL: "http://test.example.com/issues/1227", + Labels: []string{"enhancement", "bugfix"}, }, }, + MRs: data.MRs{ + data.MR{ + ID: 2224, + Name: "Test PR title 2", + URL: "https://test.example.com/mrs/2224", + MergedDate: helpers.Time(1047194647), + Author: "test-user2", + AuthorURL: "https://test.example.com/authors/test-user2", + }, + }, + }, + data.Release{ + Release: "v0.0.2", + Date: "09.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.2", + Issues: data.Issues{ + data.Issue{ + ID: 1214, + Name: "Test issue title 1", + ClosedDate: helpers.Time(1047093647), + URL: "http://test.example.com/issues/1214", + Labels: []string{"enhancement"}, + }, + }, + MRs: data.MRs{ + data.MR{ + ID: 2214, + Name: "Test PR title 1", + URL: "https://test.example.com/mrs/2214", + MergedDate: helpers.Time(1047094647), + Author: "test-user", + AuthorURL: "https://test.example.com/authors/test-user", + Labels: []string{"bugfix"}, + }, + }, + }, + data.Release{ + Release: "v0.0.1", + Date: "08.03.2003", + ReleaseURL: "https://test.example.com/tags/v0.0.1", }, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - tags := testdata.Tags() - issues := testdata.Issues() - mrs := testdata.MRs() + tags := testdata.DataTags() + issues := testdata.DataIssues() + mrs := testdata.DataMRs() gotRet := data.NewReleases(tags, issues, mrs) if len(gotRet) != len(tt.wantRet) { t.Errorf("NewReleases() different amount of results. got %#v, want %#v", diff --git a/datasource/connectors/github/internal/testclient/testclient.go b/datasource/connectors/github/internal/testclient/testclient.go index b90ff22..4aecf72 100644 --- a/datasource/connectors/github/internal/testclient/testclient.go +++ b/datasource/connectors/github/internal/testclient/testclient.go @@ -23,7 +23,7 @@ import ( "fmt" "github.com/artem-sidorenko/chagen/datasource/connectors/github/internal/client" - "github.com/artem-sidorenko/chagen/datasource/connectors/internal/testing/apitestdata" + "github.com/artem-sidorenko/chagen/internal/testing/testdata" "github.com/google/go-github/github" ) @@ -164,11 +164,11 @@ func newGitHubRepoService() *RepoService { rcommits := map[string]*github.RepositoryCommit{} rreleases := map[string]*github.RepositoryRelease{} - for _, v := range apitestdata.Commits() { + for _, v := range testdata.Commits() { rcommits[v.SHA] = genRepositoryCommit(v.SHA, v.AuthoredDate) } - for _, v := range apitestdata.Tags() { + for _, v := range testdata.Tags() { rtags = append(rtags, genRepositoryTag(v.Tag, rcommits[v.Commit].Commit)) if v.ReleaseTime != nil { @@ -191,7 +191,7 @@ func newGitHubRepoService() *RepoService { func newGitHubIssueService() *IssueService { rissues := []*github.Issue{} - for _, v := range apitestdata.Issues() { + for _, v := range testdata.Issues() { var i *github.Issue if v.PR { i = genIssuePR( @@ -218,7 +218,7 @@ func newGitHubIssueService() *IssueService { func newGitHubPullRequestsService() *PullRequestsService { rprs := []*github.PullRequest{} - for _, v := range apitestdata.MRs() { + for _, v := range testdata.MRs() { rprs = append(rprs, genPR( v.ID, v.Title, fmt.Sprintf("https://example.com/pulls/%v", v.ID), diff --git a/datasource/connectors/github/issues.go b/datasource/connectors/github/issues.go index aeb24b9..7998e2f 100644 --- a/datasource/connectors/github/issues.go +++ b/datasource/connectors/github/issues.go @@ -217,7 +217,7 @@ func (c *Connector) processIssues( issue := data.Issue{ ID: issue.GetNumber(), Name: issue.GetTitle(), - ClosedDate: issue.GetClosedAt(), + ClosedDate: issue.GetClosedAt().UTC(), URL: issue.GetHTMLURL(), Labels: lbs, } diff --git a/datasource/connectors/github/issues_test.go b/datasource/connectors/github/issues_test.go index fc55c79..5c34072 100644 --- a/datasource/connectors/github/issues_test.go +++ b/datasource/connectors/github/issues_test.go @@ -44,63 +44,63 @@ func TestConnector_Issues(t *testing.T) { data.Issue{ ID: 1234, Name: "Test issue title 13", - ClosedDate: time.Unix(2048293647, 0), + ClosedDate: helpers.Time(1048293647), URL: "http://example.com/issues/1234", Labels: []string{"enhancement"}, }, data.Issue{ ID: 1224, Name: "Test issue title 12", - ClosedDate: time.Unix(2048193647, 0), + ClosedDate: helpers.Time(1048193647), URL: "http://example.com/issues/1224", - Labels: []string(nil), + Labels: []string{"issue12"}, }, data.Issue{ ID: 1304, Name: "Test issue title 10", - ClosedDate: time.Unix(2047993647, 0), + ClosedDate: helpers.Time(1047993647), URL: "http://example.com/issues/1304", Labels: []string{"wontfix"}, }, data.Issue{ ID: 1294, Name: "Test issue title 9", - ClosedDate: time.Unix(2047893647, 0), + ClosedDate: helpers.Time(1047893647), URL: "http://example.com/issues/1294", Labels: []string(nil), }, data.Issue{ ID: 1274, Name: "Test issue title 7", - ClosedDate: time.Unix(2047693647, 0), + ClosedDate: helpers.Time(1047693647), URL: "http://example.com/issues/1274", Labels: []string{"no changelog"}, }, data.Issue{ ID: 1264, Name: "Test issue title 6", - ClosedDate: time.Unix(2047593647, 0), + ClosedDate: helpers.Time(1047593647), URL: "http://example.com/issues/1264", Labels: []string{"invalid"}, }, data.Issue{ ID: 1244, Name: "Test issue title 4", - ClosedDate: time.Unix(2047393647, 0), + ClosedDate: helpers.Time(1047393647), URL: "http://example.com/issues/1244", Labels: []string(nil), }, data.Issue{ ID: 1227, Name: "Test issue title 2", - ClosedDate: time.Unix(2047193647, 0), + ClosedDate: helpers.Time(1047193647), URL: "http://example.com/issues/1227", Labels: []string{"enhancement", "bugfix"}, }, data.Issue{ ID: 1214, Name: "Test issue title 1", - ClosedDate: time.Unix(2047093647, 0), + ClosedDate: helpers.Time(1047093647), URL: "http://example.com/issues/1214", Labels: []string{"enhancement"}, }, diff --git a/datasource/connectors/github/prs.go b/datasource/connectors/github/prs.go index 13deae1..020d2e8 100644 --- a/datasource/connectors/github/prs.go +++ b/datasource/connectors/github/prs.go @@ -221,7 +221,7 @@ func (c *Connector) processPRs( pr := data.MR{ ID: pr.GetNumber(), Name: pr.GetTitle(), - MergedDate: pr.GetMergedAt(), + MergedDate: pr.GetMergedAt().UTC(), URL: pr.GetHTMLURL(), Author: pr.User.GetLogin(), AuthorURL: pr.User.GetHTMLURL(), diff --git a/datasource/connectors/github/prs_test.go b/datasource/connectors/github/prs_test.go index 72a5efc..7576f3e 100644 --- a/datasource/connectors/github/prs_test.go +++ b/datasource/connectors/github/prs_test.go @@ -47,7 +47,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2344", Author: "te77st-user", AuthorURL: "https://example.com/users/te77st-user", - MergedDate: time.Unix(2048394647, 0), + MergedDate: helpers.Time(1048394647), Labels: []string{"bugfix"}, }, data.MR{ @@ -56,7 +56,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2334", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2048294647, 0), + MergedDate: helpers.Time(1048294647), Labels: []string{"bugfix"}, }, data.MR{ @@ -65,7 +65,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2314", Author: "test-user8", AuthorURL: "https://example.com/users/test-user8", - MergedDate: time.Unix(2048094647, 0), + MergedDate: helpers.Time(1048094647), Labels: []string{"no changelog"}, }, data.MR{ @@ -74,7 +74,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2304", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2047994647, 0), + MergedDate: helpers.Time(1047994647), Labels: []string{"bugfix"}, }, data.MR{ @@ -83,7 +83,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2294", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2047894647, 0), + MergedDate: helpers.Time(1047894647), Labels: []string{"bugfix"}, }, data.MR{ @@ -92,7 +92,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2284", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2047794647, 0), + MergedDate: helpers.Time(1047794647), Labels: []string{"invalid"}, }, data.MR{ @@ -101,7 +101,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2274", Author: "test5-user", AuthorURL: "https://example.com/users/test5-user", - MergedDate: time.Unix(2047694647, 0), + MergedDate: helpers.Time(1047694647), Labels: []string{"bugfix"}, }, data.MR{ @@ -110,7 +110,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2264", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2047594647, 0), + MergedDate: helpers.Time(1047594647), Labels: []string{"enhancement"}, }, data.MR{ @@ -119,7 +119,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2254", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2047494647, 0), + MergedDate: helpers.Time(1047494647), Labels: []string{"bugfix"}, }, data.MR{ @@ -128,7 +128,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2234", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2047294647, 0), + MergedDate: helpers.Time(1047294647), Labels: []string{"enhancement", "bugfix"}, }, data.MR{ @@ -137,7 +137,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2224", Author: "test-user2", AuthorURL: "https://example.com/users/test-user2", - MergedDate: time.Unix(2047194647, 0), + MergedDate: helpers.Time(1047194647), Labels: []string(nil), }, data.MR{ @@ -146,7 +146,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2214", Author: "test-user", AuthorURL: "https://example.com/users/test-user", - MergedDate: time.Unix(2047094647, 0), + MergedDate: helpers.Time(1047094647), Labels: []string{"bugfix"}, }, }, diff --git a/datasource/connectors/github/tags.go b/datasource/connectors/github/tags.go index 0e85f4c..7d799a9 100644 --- a/datasource/connectors/github/tags.go +++ b/datasource/connectors/github/tags.go @@ -246,7 +246,7 @@ func (c *Connector) processTags( tag := data.Tag{ Name: tagName, Commit: commit.Commit.GetSHA(), - Date: commit.Commit.Committer.GetDate(), + Date: commit.Commit.Committer.GetDate().UTC(), URL: tagURL, } diff --git a/datasource/connectors/github/tags_test.go b/datasource/connectors/github/tags_test.go index 8915bd6..037caa5 100644 --- a/datasource/connectors/github/tags_test.go +++ b/datasource/connectors/github/tags_test.go @@ -44,73 +44,73 @@ func TestConnector_Tags(t *testing.T) { { Name: "v0.1.2", Commit: "d8351413f688c96c2c5d6fe58ebf5ac17f545bc0", - Date: time.Unix(2048183647, 0), + Date: helpers.Time(1048183647), URL: "https://github.com/testowner/testrepo/releases/v0.1.2", }, { Name: "v0.1.1", Commit: "fc5d68ff1cf691e09f6ead044813274953c9b843", - Date: time.Unix(2048083647, 0), + Date: helpers.Time(1048083647), URL: "https://github.com/testowner/testrepo/releases/v0.1.1", }, { Name: "v0.1.0", Commit: "dbbf36ffaae700a2ce03ef849d6f944031f34b95", - Date: time.Unix(2047983647, 0), + Date: helpers.Time(1047983647), URL: "https://github.com/testowner/testrepo/releases/v0.1.0", }, { Name: "v0.0.9", Commit: "fc9f16ecc043e3fe422834cd127311d11d423668", - Date: time.Unix(2047883647, 0), + Date: helpers.Time(1047883647), URL: "https://github.com/testowner/testrepo/tree/v0.0.9", }, { Name: "v0.0.8", Commit: "8d8d817a530bc1c3f792d9508c187b5769c434c5", - Date: time.Unix(2047783647, 0), + Date: helpers.Time(1047783647), URL: "https://github.com/testowner/testrepo/tree/v0.0.8", }, { Name: "v0.0.7", Commit: "d21438494dd0722c1d13dc496ae1f60fb85084c1", - Date: time.Unix(2047683647, 0), + Date: helpers.Time(1047683647), URL: "https://github.com/testowner/testrepo/releases/v0.0.7", }, { Name: "v0.0.6", Commit: "ddde800c451bae606713ae0f8418badcf31db120", - Date: time.Unix(2047583647, 0), + Date: helpers.Time(1047583647), URL: "https://github.com/testowner/testrepo/tree/v0.0.6", }, { Name: "v0.0.5", Commit: "746e45ea014e257bcb7caa2c100ed1e5f63ed234", - Date: time.Unix(2047483647, 0), + Date: helpers.Time(1047483647), URL: "https://github.com/testowner/testrepo/tree/v0.0.5", }, { Name: "v0.0.4", Commit: "d4ff341587bc80a9c897c28340df9fe8f9fc6309", - Date: time.Unix(2047383647, 0), + Date: helpers.Time(1047383647), URL: "https://github.com/testowner/testrepo/tree/v0.0.4", }, { Name: "v0.0.3", Commit: "52f214dc3bf6c0e2a87eae6eab363a317c5a665f", - Date: time.Unix(2047283647, 0), + Date: helpers.Time(1047283647), URL: "https://github.com/testowner/testrepo/releases/v0.0.3", }, { Name: "v0.0.2", Commit: "b3622b516b8ad70ce5dc3fa422fb90c3b58fa9da", - Date: time.Unix(2047183647, 0), + Date: helpers.Time(1047183647), URL: "https://github.com/testowner/testrepo/tree/v0.0.2", }, { Name: "v0.0.1", Commit: "7d84cdb2f7c2d4619cda4b8adeb1897097b5c8fc", - Date: time.Unix(2047083647, 0), + Date: helpers.Time(1047083647), URL: "https://github.com/testowner/testrepo/releases/v0.0.1", }, }, diff --git a/datasource/connectors/gitlab/internal/testclient/testclient.go b/datasource/connectors/gitlab/internal/testclient/testclient.go index 19dcba4..bcd0796 100644 --- a/datasource/connectors/gitlab/internal/testclient/testclient.go +++ b/datasource/connectors/gitlab/internal/testclient/testclient.go @@ -22,7 +22,7 @@ import ( "time" "github.com/artem-sidorenko/chagen/datasource/connectors/gitlab/internal/client" - "github.com/artem-sidorenko/chagen/datasource/connectors/internal/testing/apitestdata" + "github.com/artem-sidorenko/chagen/internal/testing/testdata" gitlab "github.com/xanzy/go-gitlab" ) @@ -173,9 +173,9 @@ func newProjectService() *ProjectsService { func newTagsService() *TagsService { rtags := []*gitlab.Tag{} - commits := apitestdata.CommitsBySHA() + commits := testdata.CommitsBySHA() - for _, tag := range apitestdata.Tags() { + for _, tag := range testdata.Tags() { commit := commits[tag.Commit] rtags = append(rtags, genTag( tag.Tag, @@ -192,7 +192,7 @@ func newTagsService() *TagsService { func newMergeRequestsService() *MergeRequestsService { ret := []*gitlab.MergeRequest{} - for _, mr := range apitestdata.MRs() { + for _, mr := range testdata.MRs() { // return only merged MRs, because of filter sent to API in the request if mr.MergedAt != (time.Time{}) { ret = append(ret, genMR( @@ -221,7 +221,7 @@ func newMergeRequestsService() *MergeRequestsService { func newCommitsService() *CommitsService { ret := map[string]*gitlab.Commit{} - for _, commit := range apitestdata.Commits() { + for _, commit := range testdata.Commits() { ret[commit.SHA] = genCommit(commit.SHA, commit.AuthoredDate) } @@ -234,7 +234,7 @@ func newCommitsService() *CommitsService { func newIssuesService() *IssuesService { ret := []*gitlab.Issue{} - for _, is := range apitestdata.Issues() { + for _, is := range testdata.Issues() { // proceed only issues as GitLab API returns no MRs here if !is.PR { ret = append(ret, genIssue( diff --git a/datasource/connectors/gitlab/issues.go b/datasource/connectors/gitlab/issues.go index 2ddd4b5..eb0ed2c 100644 --- a/datasource/connectors/gitlab/issues.go +++ b/datasource/connectors/gitlab/issues.go @@ -209,7 +209,7 @@ func (c *Connector) processIssues( issue := data.Issue{ ID: issue.IID, Name: issue.Title, - ClosedDate: *issue.ClosedAt, + ClosedDate: (*issue.ClosedAt).UTC(), URL: issue.WebURL, Labels: issue.Labels, } diff --git a/datasource/connectors/gitlab/issues_test.go b/datasource/connectors/gitlab/issues_test.go index c793f06..19d21fa 100644 --- a/datasource/connectors/gitlab/issues_test.go +++ b/datasource/connectors/gitlab/issues_test.go @@ -19,7 +19,6 @@ package gitlab_test import ( "context" "errors" - "fmt" "reflect" "sort" "testing" @@ -45,63 +44,63 @@ func TestConnector_Issues(t *testing.T) { data.Issue{ ID: 1234, Name: "Test issue title 13", - ClosedDate: time.Unix(2048293647, 0), + ClosedDate: helpers.Time(1048293647), URL: "https://example.com/issues/1234", Labels: []string{"enhancement"}, }, data.Issue{ ID: 1224, Name: "Test issue title 12", - ClosedDate: time.Unix(2048193647, 0), + ClosedDate: helpers.Time(1048193647), URL: "https://example.com/issues/1224", - Labels: []string(nil), + Labels: []string{"issue12"}, }, data.Issue{ ID: 1304, Name: "Test issue title 10", - ClosedDate: time.Unix(2047993647, 0), + ClosedDate: helpers.Time(1047993647), URL: "https://example.com/issues/1304", Labels: []string{"wontfix"}, }, data.Issue{ ID: 1294, Name: "Test issue title 9", - ClosedDate: time.Unix(2047893647, 0), + ClosedDate: helpers.Time(1047893647), URL: "https://example.com/issues/1294", Labels: []string(nil), }, data.Issue{ ID: 1274, Name: "Test issue title 7", - ClosedDate: time.Unix(2047693647, 0), + ClosedDate: helpers.Time(1047693647), URL: "https://example.com/issues/1274", Labels: []string{"no changelog"}, }, data.Issue{ ID: 1264, Name: "Test issue title 6", - ClosedDate: time.Unix(2047593647, 0), + ClosedDate: helpers.Time(1047593647), URL: "https://example.com/issues/1264", Labels: []string{"invalid"}, }, data.Issue{ ID: 1244, Name: "Test issue title 4", - ClosedDate: time.Unix(2047393647, 0), + ClosedDate: helpers.Time(1047393647), URL: "https://example.com/issues/1244", Labels: []string(nil), }, data.Issue{ ID: 1227, Name: "Test issue title 2", - ClosedDate: time.Unix(2047193647, 0), + ClosedDate: helpers.Time(1047193647), URL: "https://example.com/issues/1227", Labels: []string{"enhancement", "bugfix"}, }, data.Issue{ ID: 1214, Name: "Test issue title 1", - ClosedDate: time.Unix(2047093647, 0), + ClosedDate: helpers.Time(1047093647), URL: "https://example.com/issues/1214", Labels: []string{"enhancement"}, }, @@ -147,9 +146,6 @@ func TestConnector_Issues(t *testing.T) { if !reflect.DeepEqual(got, tt.want) { t.Errorf("Connector.Issues() = %+v, want %+v", got, tt.want) - for i, g := range got { - fmt.Printf("%#v \n %#v \n\n", g, tt.want[i]) - } } if err == nil { // compare the processed Issues only in non-error situation diff --git a/datasource/connectors/gitlab/mrs.go b/datasource/connectors/gitlab/mrs.go index 4085bec..4b918c6 100644 --- a/datasource/connectors/gitlab/mrs.go +++ b/datasource/connectors/gitlab/mrs.go @@ -220,7 +220,7 @@ func (c *Connector) processMRs( ID: mr.IID, Name: mr.Title, URL: mr.WebURL, - MergedDate: *commit.AuthoredDate, + MergedDate: (*commit.AuthoredDate).UTC(), Author: mr.Author.Username, AuthorURL: authorURL, Labels: mr.Labels, diff --git a/datasource/connectors/gitlab/mrs_test.go b/datasource/connectors/gitlab/mrs_test.go index a4aaca5..1264e3b 100644 --- a/datasource/connectors/gitlab/mrs_test.go +++ b/datasource/connectors/gitlab/mrs_test.go @@ -47,7 +47,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2344", Author: "te77st-user", AuthorURL: "https://gitlab.com/te77st-user", - MergedDate: time.Unix(2048394647, 0), + MergedDate: helpers.Time(1048394647), Labels: []string{"bugfix"}, }, data.MR{ @@ -56,7 +56,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2334", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2048294647, 0), + MergedDate: helpers.Time(1048294647), Labels: []string{"bugfix"}, }, data.MR{ @@ -65,7 +65,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2314", Author: "test-user8", AuthorURL: "https://gitlab.com/test-user8", - MergedDate: time.Unix(2048094647, 0), + MergedDate: helpers.Time(1048094647), Labels: []string{"no changelog"}, }, data.MR{ @@ -74,7 +74,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2304", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2047994647, 0), + MergedDate: helpers.Time(1047994647), Labels: []string{"bugfix"}, }, data.MR{ @@ -83,7 +83,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2294", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2047894647, 0), + MergedDate: helpers.Time(1047894647), Labels: []string{"bugfix"}, }, data.MR{ @@ -92,7 +92,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2284", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2047794647, 0), + MergedDate: helpers.Time(1047794647), Labels: []string{"invalid"}, }, data.MR{ @@ -101,7 +101,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2274", Author: "test5-user", AuthorURL: "https://gitlab.com/test5-user", - MergedDate: time.Unix(2047694647, 0), + MergedDate: helpers.Time(1047694647), Labels: []string{"bugfix"}, }, data.MR{ @@ -110,7 +110,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2264", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2047594647, 0), + MergedDate: helpers.Time(1047594647), Labels: []string{"enhancement"}, }, data.MR{ @@ -119,7 +119,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2254", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2047494647, 0), + MergedDate: helpers.Time(1047494647), Labels: []string{"bugfix"}, }, data.MR{ @@ -128,7 +128,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2234", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2047294647, 0), + MergedDate: helpers.Time(1047294647), Labels: []string{"enhancement", "bugfix"}, }, data.MR{ @@ -137,7 +137,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2224", Author: "test-user2", AuthorURL: "https://gitlab.com/test-user2", - MergedDate: time.Unix(2047194647, 0), + MergedDate: helpers.Time(1047194647), Labels: []string(nil), }, data.MR{ @@ -146,7 +146,7 @@ func TestConnector_MRs(t *testing.T) { URL: "https://example.com/pulls/2214", Author: "test-user", AuthorURL: "https://gitlab.com/test-user", - MergedDate: time.Unix(2047094647, 0), + MergedDate: helpers.Time(1047094647), Labels: []string{"bugfix"}, }, }, diff --git a/datasource/connectors/gitlab/tags.go b/datasource/connectors/gitlab/tags.go index 6f9e615..d9dd829 100644 --- a/datasource/connectors/gitlab/tags.go +++ b/datasource/connectors/gitlab/tags.go @@ -211,7 +211,7 @@ func (c *Connector) processTags( tag := data.Tag{ Name: tagName, Commit: commit.ID, - Date: *commit.AuthoredDate, + Date: (*commit.AuthoredDate).UTC(), URL: tagURL, } diff --git a/datasource/connectors/gitlab/tags_test.go b/datasource/connectors/gitlab/tags_test.go index 5e97cb1..8af6148 100644 --- a/datasource/connectors/gitlab/tags_test.go +++ b/datasource/connectors/gitlab/tags_test.go @@ -44,73 +44,73 @@ func TestConnector_Tags(t *testing.T) { { Name: "v0.1.2", Commit: "d8351413f688c96c2c5d6fe58ebf5ac17f545bc0", - Date: time.Unix(2048183647, 0), + Date: helpers.Time(1048183647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.1.2", }, { Name: "v0.1.1", Commit: "fc5d68ff1cf691e09f6ead044813274953c9b843", - Date: time.Unix(2048083647, 0), + Date: helpers.Time(1048083647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.1.1", }, { Name: "v0.1.0", Commit: "dbbf36ffaae700a2ce03ef849d6f944031f34b95", - Date: time.Unix(2047983647, 0), + Date: helpers.Time(1047983647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.1.0", }, { Name: "v0.0.9", Commit: "fc9f16ecc043e3fe422834cd127311d11d423668", - Date: time.Unix(2047883647, 0), + Date: helpers.Time(1047883647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.9", }, { Name: "v0.0.8", Commit: "8d8d817a530bc1c3f792d9508c187b5769c434c5", - Date: time.Unix(2047783647, 0), + Date: helpers.Time(1047783647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.8", }, { Name: "v0.0.7", Commit: "d21438494dd0722c1d13dc496ae1f60fb85084c1", - Date: time.Unix(2047683647, 0), + Date: helpers.Time(1047683647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.7", }, { Name: "v0.0.6", Commit: "ddde800c451bae606713ae0f8418badcf31db120", - Date: time.Unix(2047583647, 0), + Date: helpers.Time(1047583647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.6", }, { Name: "v0.0.5", Commit: "746e45ea014e257bcb7caa2c100ed1e5f63ed234", - Date: time.Unix(2047483647, 0), + Date: helpers.Time(1047483647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.5", }, { Name: "v0.0.4", Commit: "d4ff341587bc80a9c897c28340df9fe8f9fc6309", - Date: time.Unix(2047383647, 0), + Date: helpers.Time(1047383647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.4", }, { Name: "v0.0.3", Commit: "52f214dc3bf6c0e2a87eae6eab363a317c5a665f", - Date: time.Unix(2047283647, 0), + Date: helpers.Time(1047283647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.3", }, { Name: "v0.0.2", Commit: "b3622b516b8ad70ce5dc3fa422fb90c3b58fa9da", - Date: time.Unix(2047183647, 0), + Date: helpers.Time(1047183647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.2", }, { Name: "v0.0.1", Commit: "7d84cdb2f7c2d4619cda4b8adeb1897097b5c8fc", - Date: time.Unix(2047083647, 0), + Date: helpers.Time(1047083647), URL: "https://gitlab.com/testowner/testrepo/tags/v0.0.1", }, }, diff --git a/datasource/connectors/internal/testing/apitestdata/issues.go b/datasource/connectors/internal/testing/apitestdata/issues.go deleted file mode 100644 index 4b7c1f3..0000000 --- a/datasource/connectors/internal/testing/apitestdata/issues.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2019 Artem Sidorenko - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package apitestdata - -import "time" - -// Issue describes a struct with issue information -type Issue struct { - ID int - Title string - ClosedAt time.Time - Labels []string - PR bool -} - -// Issues returns different issues -func Issues() []Issue { - return []Issue{ - {1214, "Test issue title 1", time.Unix(2047093647, 0), []string{"enhancement"}, false}, - {1227, "Test issue title 2", time.Unix(2047193647, 0), []string{"enhancement", "bugfix"}, false}, - {1239, "Test PR title 3", time.Unix(2047293647, 0), nil, true}, - {1244, "Test issue title 4", time.Unix(2047393647, 0), nil, false}, - {1254, "Test PR title 5", time.Unix(2047493647, 0), []string{"wontfix"}, true}, - {1264, "Test issue title 6", time.Unix(2047593647, 0), []string{"invalid"}, false}, - {1274, "Test issue title 7", time.Unix(2047693647, 0), []string{"no changelog"}, false}, - {1284, "Test PR title 8", time.Unix(2047793647, 0), []string{"enhancement"}, true}, - {1294, "Test issue title 9", time.Unix(2047893647, 0), nil, false}, - {1304, "Test issue title 10", time.Unix(2047993647, 0), []string{"wontfix"}, false}, - {1214, "Test PR title 11", time.Unix(2048093647, 0), []string{"enhancement"}, true}, - {1224, "Test issue title 12", time.Unix(2048193647, 0), nil, false}, - {1234, "Test issue title 13", time.Unix(2048293647, 0), []string{"enhancement"}, false}, - } -} diff --git a/internal/testing/helpers/time.go b/internal/testing/helpers/time.go new file mode 100644 index 0000000..36af727 --- /dev/null +++ b/internal/testing/helpers/time.go @@ -0,0 +1,30 @@ +/* + Copyright 2019 Artem Sidorenko + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package helpers + +import "time" + +// Time returns a UTC time for given timestamp +func Time(sec int64) time.Time { + return time.Unix(sec, 0).UTC() +} + +// TimePtr returns a pointer to time.Time for a given timestamp +func TimePtr(sec int64) *time.Time { + t := Time(sec) + return &t +} diff --git a/internal/testing/testconnector/testconnector.go b/internal/testing/testconnector/testconnector.go index d2fecab..8ae75b4 100644 --- a/internal/testing/testconnector/testconnector.go +++ b/internal/testing/testconnector/testconnector.go @@ -24,7 +24,7 @@ import ( "github.com/artem-sidorenko/chagen/data" "github.com/artem-sidorenko/chagen/datasource/connectors" - "github.com/artem-sidorenko/chagen/internal/testing/testconnector/testdata" + "github.com/artem-sidorenko/chagen/internal/testing/testdata" "github.com/urfave/cli" ) @@ -56,12 +56,12 @@ func (c *Connector) Tags( <-chan bool, <-chan int, ) { - tags := testdata.Tags() + tags := testdata.DataTags() if RetTestingTag { tags = append(tags, data.Tag{ Name: "testingtag", - Date: time.Unix(1147783647, 0), + Date: time.Unix(1047591647, 0), Commit: "ad59c6b54ba53f54383d7c4661bdd4e29fe87c15", URL: "https://test.example.com/tags/testingtag", }) @@ -94,7 +94,7 @@ func (c *Connector) Issues( go func() { defer close(cissues) - for _, t := range testdata.Issues() { + for _, t := range testdata.DataIssues() { cissues <- t } }() @@ -116,7 +116,7 @@ func (c *Connector) MRs( go func() { defer close(cmrs) - for _, t := range testdata.MRs() { + for _, t := range testdata.DataMRs() { cmrs <- t } }() diff --git a/internal/testing/testconnector/testdata/testdata.go b/internal/testing/testconnector/testdata/testdata.go deleted file mode 100644 index ad21d7c..0000000 --- a/internal/testing/testconnector/testdata/testdata.go +++ /dev/null @@ -1,130 +0,0 @@ -/* - Copyright 2019 Artem Sidorenko - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// Package testdata provides some test data -package testdata - -import ( - "time" - - "github.com/artem-sidorenko/chagen/data" -) - -// Tags returns some tags -func Tags() data.Tags { - return data.Tags{ - { - Name: "v0.0.2", - Date: time.Unix(1147483647, 0), - Commit: "b6a735dcb420a82865abe8c194900e59f6af9dea", - URL: "https://test.example.com/tags/v0.0.2", - }, - { - Name: "v0.0.1", - Date: time.Unix(1047483647, 0), - Commit: "d85645cbe6288cce5e5d066f8c7864040266cce3", - URL: "https://test.example.com/tags/v0.0.1", - }, - { - Name: "v0.0.3", - Date: time.Unix(1247483647, 0), - Commit: "25362c337d524025bf98e978059bf9bcd2b56221", - URL: "https://test.example.com/tags/v0.0.3", - }, - } -} - -// Issues returns some issues -func Issues() data.Issues { - return data.Issues{ - { - ID: 2, - Name: "Issue 2", - ClosedDate: time.Unix(1247483647, 0), - URL: "http://test.example.com/issues/2", - }, - { - ID: 1, - Name: "Issue 1", - ClosedDate: time.Unix(1047483647, 0), - URL: "http://test.example.com/issues/1", - }, - { - ID: 3, - Name: "Issue 3", - ClosedDate: time.Unix(1347483647, 0), - URL: "http://test.example.com/issues/3", - }, - { - ID: 4, - Name: "Issue 4", - ClosedDate: time.Unix(1297483647, 0), - URL: "http://test.example.com/issues/4", - }, - { - ID: 5, - Name: "Issue 5", - ClosedDate: time.Unix(1298483647, 0), - URL: "http://test.example.com/issues/5", - Labels: []string{"issue5"}, - }, - { - ID: 6, - Name: "Issue 6", - ClosedDate: time.Unix(1299483647, 0), - URL: "http://test.example.com/issues/6", - Labels: []string{"no changelog"}, - }, - } -} - -// MRs returns some MRs -func MRs() data.MRs { - return data.MRs{ - { - ID: 2, - Name: "MR 2", - MergedDate: time.Unix(1247483647, 0), - Author: "testauthor", - AuthorURL: "https://test.example.com/authors/testauthor", - URL: "https://test.example.com/mrs/2", - }, - { - ID: 1, - Name: "MR 1", - MergedDate: time.Unix(1047483647, 0), - Author: "testauthor", - AuthorURL: "https://test.example.com/authors/testauthor", - URL: "https://test.example.com/mrs/1", - }, - { - ID: 3, - Name: "MR 3", - MergedDate: time.Unix(1057483647, 0), - Author: "testauthor", - AuthorURL: "https://test.example.com/authors/testauthor", - URL: "https://test.example.com/mrs/3", - }, - { - ID: 4, - Name: "MR 4", - MergedDate: time.Unix(1299483647, 0), - Author: "testauthor", - AuthorURL: "https://test.example.com/authors/testauthor", - URL: "https://test.example.com/mrs/4", - }, - } -} diff --git a/datasource/connectors/internal/testing/apitestdata/commits.go b/internal/testing/testdata/commits.go similarity index 56% rename from datasource/connectors/internal/testing/apitestdata/commits.go rename to internal/testing/testdata/commits.go index d0d07a0..b08d161 100644 --- a/datasource/connectors/internal/testing/apitestdata/commits.go +++ b/internal/testing/testdata/commits.go @@ -14,7 +14,7 @@ limitations under the License. */ -package apitestdata +package testdata import "time" @@ -28,43 +28,43 @@ type Commit struct { // Commits returns different Commits func Commits() []Commit { return []Commit{ - {"041152be02b2d69141d3a8d2278460f4777474f7", time.Unix(2047094647, 0), + {"041152be02b2d69141d3a8d2278460f4777474f7", time.Unix(1047094647, 0), "Merge branch 'pr1' into 'master'"}, - {"1080a10971e4a887ae8a827bb16e0b04801f630b", time.Unix(2047194647, 0), + {"1080a10971e4a887ae8a827bb16e0b04801f630b", time.Unix(1047194647, 0), "Merge branch 'pr2' into 'master'"}, - {"d72866aa0a25e58b7fb0365fba0fd6791d627451", time.Unix(2047294647, 0), + {"d72866aa0a25e58b7fb0365fba0fd6791d627451", time.Unix(1047294647, 0), "Merge branch 'pr3' into 'master'"}, - {"433a7f849f0a5c21a0f24886ff72a91e1e74888e", time.Unix(2047494647, 0), + {"433a7f849f0a5c21a0f24886ff72a91e1e74888e", time.Unix(1047494647, 0), "Merge branch 'pr5' into 'master'"}, - {"e5bc67e0c5d2ed17639a6499d1d0c05d4073dc80", time.Unix(2047594647, 0), + {"e5bc67e0c5d2ed17639a6499d1d0c05d4073dc80", time.Unix(1047594647, 0), "Merge branch 'pr6' into 'master'"}, - {"d4c421f840e35fb15ae99683df23caf451db7377", time.Unix(2047694647, 0), + {"d4c421f840e35fb15ae99683df23caf451db7377", time.Unix(1047694647, 0), "Merge branch 'pr7' into 'master'"}, - {"fd81ac08493e550604dd04fa39b9c2eb1907cea6", time.Unix(2047794647, 0), + {"fd81ac08493e550604dd04fa39b9c2eb1907cea6", time.Unix(1047794647, 0), "Merge branch 'pr8' into 'master'"}, - {"cc1cf9b1441962bdd6b98a4e09363dffb2037835", time.Unix(2047894647, 0), + {"cc1cf9b1441962bdd6b98a4e09363dffb2037835", time.Unix(1047894647, 0), "Merge branch 'pr9' into 'master'"}, - {"9772a06643b77ec1a16646df4bb909c771c09fba", time.Unix(2047994647, 0), + {"9772a06643b77ec1a16646df4bb909c771c09fba", time.Unix(1047994647, 0), "Merge branch 'pr10' into 'master'"}, - {"627b94d1e87e938ea140c592f3ebd115d5a98929", time.Unix(2048094647, 0), + {"627b94d1e87e938ea140c592f3ebd115d5a98929", time.Unix(1048094647, 0), "Merge branch 'pr11' into 'master'"}, - {"c31af03759e2262d99b2c4a7571a8e0115f37d68", time.Unix(2048294647, 0), + {"c31af03759e2262d99b2c4a7571a8e0115f37d68", time.Unix(1048294647, 0), "Merge branch 'pr13' into 'master'"}, - {"9618c791ab1f643aeffb7c5e1abe5877223aaa91", time.Unix(2048394647, 0), + {"9618c791ab1f643aeffb7c5e1abe5877223aaa91", time.Unix(1048394647, 0), "Merge branch 'pr14' into 'master'"}, - {"7d84cdb2f7c2d4619cda4b8adeb1897097b5c8fc", time.Unix(2047083647, 0), "Release v0.0.1"}, - {"b3622b516b8ad70ce5dc3fa422fb90c3b58fa9da", time.Unix(2047183647, 0), "Release v0.0.2"}, - {"52f214dc3bf6c0e2a87eae6eab363a317c5a665f", time.Unix(2047283647, 0), "Release v0.0.3"}, - {"d4ff341587bc80a9c897c28340df9fe8f9fc6309", time.Unix(2047383647, 0), "Release v0.0.4"}, - {"746e45ea014e257bcb7caa2c100ed1e5f63ed234", time.Unix(2047483647, 0), "Release v0.0.5"}, - {"ddde800c451bae606713ae0f8418badcf31db120", time.Unix(2047583647, 0), "Release v0.0.6"}, - {"d21438494dd0722c1d13dc496ae1f60fb85084c1", time.Unix(2047683647, 0), "Release v0.0.7"}, - {"8d8d817a530bc1c3f792d9508c187b5769c434c5", time.Unix(2047783647, 0), "Release v0.0.8"}, - {"fc9f16ecc043e3fe422834cd127311d11d423668", time.Unix(2047883647, 0), "Release v0.0.9"}, - {"dbbf36ffaae700a2ce03ef849d6f944031f34b95", time.Unix(2047983647, 0), "Release v0.1.0"}, - {"fc5d68ff1cf691e09f6ead044813274953c9b843", time.Unix(2048083647, 0), "Release v0.1.1"}, - {"d8351413f688c96c2c5d6fe58ebf5ac17f545bc0", time.Unix(2048183647, 0), "Release v0.1.2"}, + {"7d84cdb2f7c2d4619cda4b8adeb1897097b5c8fc", time.Unix(1047083647, 0), "Release v0.0.1"}, + {"b3622b516b8ad70ce5dc3fa422fb90c3b58fa9da", time.Unix(1047183647, 0), "Release v0.0.2"}, + {"52f214dc3bf6c0e2a87eae6eab363a317c5a665f", time.Unix(1047283647, 0), "Release v0.0.3"}, + {"d4ff341587bc80a9c897c28340df9fe8f9fc6309", time.Unix(1047383647, 0), "Release v0.0.4"}, + {"746e45ea014e257bcb7caa2c100ed1e5f63ed234", time.Unix(1047483647, 0), "Release v0.0.5"}, + {"ddde800c451bae606713ae0f8418badcf31db120", time.Unix(1047583647, 0), "Release v0.0.6"}, + {"d21438494dd0722c1d13dc496ae1f60fb85084c1", time.Unix(1047683647, 0), "Release v0.0.7"}, + {"8d8d817a530bc1c3f792d9508c187b5769c434c5", time.Unix(1047783647, 0), "Release v0.0.8"}, + {"fc9f16ecc043e3fe422834cd127311d11d423668", time.Unix(1047883647, 0), "Release v0.0.9"}, + {"dbbf36ffaae700a2ce03ef849d6f944031f34b95", time.Unix(1047983647, 0), "Release v0.1.0"}, + {"fc5d68ff1cf691e09f6ead044813274953c9b843", time.Unix(1048083647, 0), "Release v0.1.1"}, + {"d8351413f688c96c2c5d6fe58ebf5ac17f545bc0", time.Unix(1048183647, 0), "Release v0.1.2"}, } } diff --git a/internal/testing/testdata/issues.go b/internal/testing/testdata/issues.go new file mode 100644 index 0000000..62fa4aa --- /dev/null +++ b/internal/testing/testdata/issues.go @@ -0,0 +1,71 @@ +/* + Copyright 2019 Artem Sidorenko + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package testdata + +import ( + "fmt" + "time" + + "github.com/artem-sidorenko/chagen/data" + "github.com/artem-sidorenko/chagen/internal/testing/helpers" +) + +// Issue describes a struct with issue information +type Issue struct { + ID int + Title string + ClosedAt time.Time + Labels []string + PR bool +} + +// Issues returns different issues +func Issues() []Issue { + return []Issue{ + {1214, "Test issue title 1", helpers.Time(1047093647), []string{"enhancement"}, false}, + {1227, "Test issue title 2", helpers.Time(1047193647), []string{"enhancement", "bugfix"}, false}, + {1239, "Test PR title 3", helpers.Time(1047293647), nil, true}, + {1244, "Test issue title 4", helpers.Time(1047393647), nil, false}, + {1254, "Test PR title 5", helpers.Time(1047493647), []string{"wontfix"}, true}, + {1264, "Test issue title 6", helpers.Time(1047593647), []string{"invalid"}, false}, + {1274, "Test issue title 7", helpers.Time(1047693647), []string{"no changelog"}, false}, + {1284, "Test PR title 8", helpers.Time(1047793647), []string{"enhancement"}, true}, + {1294, "Test issue title 9", helpers.Time(1047893647), nil, false}, + {1304, "Test issue title 10", helpers.Time(1047993647), []string{"wontfix"}, false}, + {1214, "Test PR title 11", helpers.Time(1048093647), []string{"enhancement"}, true}, + {1224, "Test issue title 12", helpers.Time(1048193647), []string{"issue12"}, false}, + {1234, "Test issue title 13", helpers.Time(1048293647), []string{"enhancement"}, false}, + } +} + +// DataIssues returns the tags in the data.Issue format +func DataIssues() []data.Issue { + var r []data.Issue + for _, i := range Issues() { + if i.PR { + continue + } + r = append(r, data.Issue{ + ID: i.ID, + Name: i.Title, + URL: fmt.Sprintf("http://test.example.com/issues/%v", i.ID), + Labels: i.Labels, + ClosedDate: i.ClosedAt, + }) + } + return r +} diff --git a/datasource/connectors/internal/testing/apitestdata/mrs.go b/internal/testing/testdata/mrs.go similarity index 58% rename from datasource/connectors/internal/testing/apitestdata/mrs.go rename to internal/testing/testdata/mrs.go index 070ed4c..d9d0ff2 100644 --- a/datasource/connectors/internal/testing/apitestdata/mrs.go +++ b/internal/testing/testdata/mrs.go @@ -14,9 +14,15 @@ limitations under the License. */ -package apitestdata +package testdata -import "time" +import ( + "fmt" + "time" + + "github.com/artem-sidorenko/chagen/data" + "github.com/artem-sidorenko/chagen/internal/testing/helpers" +) // MR describes a struct with PR/MR information type MR struct { @@ -31,34 +37,51 @@ type MR struct { // MRs returns different PRs/MRs func MRs() []MR { return []MR{ - {2214, "Test PR title 1", "test-user", time.Unix(2047094647, 0), + {2214, "Test PR title 1", "test-user", helpers.Time(1047094647), "041152be02b2d69141d3a8d2278460f4777474f7", []string{"bugfix"}}, - {2224, "Test PR title 2", "test-user2", time.Unix(2047194647, 0), + {2224, "Test PR title 2", "test-user2", helpers.Time(1047194647), "1080a10971e4a887ae8a827bb16e0b04801f630b", nil}, - {2234, "Test PR title 3", "test-user", time.Unix(2047294647, 0), + {2234, "Test PR title 3", "test-user", helpers.Time(1047294647), "d72866aa0a25e58b7fb0365fba0fd6791d627451", []string{"enhancement", "bugfix"}}, {2244, "Test PR title 4 closed", "test-user", time.Time{}, "", []string{"wontfix"}}, - {2254, "Test PR title 5", "test-user", time.Unix(2047494647, 0), + {2254, "Test PR title 5", "test-user", helpers.Time(1047494647), "433a7f849f0a5c21a0f24886ff72a91e1e74888e", []string{"bugfix"}}, - {2264, "Test PR title 6", "test-user", time.Unix(2047594647, 0), + {2264, "Test PR title 6", "test-user", helpers.Time(1047594647), "e5bc67e0c5d2ed17639a6499d1d0c05d4073dc80", []string{"enhancement"}}, - {2274, "Test PR title 7", "test5-user", time.Unix(2047694647, 0), + {2274, "Test PR title 7", "test5-user", helpers.Time(1047694647), "d4c421f840e35fb15ae99683df23caf451db7377", []string{"bugfix"}}, - {2284, "Test PR title 8", "test-user", time.Unix(2047794647, 0), + {2284, "Test PR title 8", "test-user", helpers.Time(1047794647), "fd81ac08493e550604dd04fa39b9c2eb1907cea6", []string{"invalid"}}, - {2294, "Test PR title 9", "test-user", time.Unix(2047894647, 0), + {2294, "Test PR title 9", "test-user", helpers.Time(1047894647), "cc1cf9b1441962bdd6b98a4e09363dffb2037835", []string{"bugfix"}}, - {2304, "Test PR title 10", "test-user", time.Unix(2047994647, 0), + {2304, "Test PR title 10", "test-user", helpers.Time(1047994647), "9772a06643b77ec1a16646df4bb909c771c09fba", []string{"bugfix"}}, - {2314, "Test PR title 11", "test-user8", time.Unix(2048094647, 0), + {2314, "Test PR title 11", "test-user8", helpers.Time(1048094647), "627b94d1e87e938ea140c592f3ebd115d5a98929", []string{"no changelog"}}, {2324, "Test PR title 12 closed", "test-user", time.Time{}, "", []string{"bugfix"}}, - {2334, "Test PR title 13", "test-user", time.Unix(2048294647, 0), + {2334, "Test PR title 13", "test-user", helpers.Time(1048294647), "c31af03759e2262d99b2c4a7571a8e0115f37d68", []string{"bugfix"}}, - {2344, "Test PR title 14", "te77st-user", time.Unix(2048394647, 0), + {2344, "Test PR title 14", "te77st-user", helpers.Time(1048394647), "9618c791ab1f643aeffb7c5e1abe5877223aaa91", []string{"bugfix"}}, } } + +// DataMRs returns the tags in the data.MR format +func DataMRs() []data.MR { + var r []data.MR + for _, m := range MRs() { + r = append(r, data.MR{ + ID: m.ID, + Author: m.Username, + AuthorURL: fmt.Sprintf("https://test.example.com/authors/%v", m.Username), + Labels: m.Labels, + MergedDate: m.MergedAt, + Name: m.Title, + URL: fmt.Sprintf("https://test.example.com/mrs/%v", m.ID), + }) + } + return r +} diff --git a/datasource/connectors/internal/testing/apitestdata/tags.go b/internal/testing/testdata/tags.go similarity index 69% rename from datasource/connectors/internal/testing/apitestdata/tags.go rename to internal/testing/testdata/tags.go index 3b92f1c..3c4ab29 100644 --- a/datasource/connectors/internal/testing/apitestdata/tags.go +++ b/internal/testing/testdata/tags.go @@ -14,35 +14,52 @@ limitations under the License. */ -package apitestdata +package testdata import ( + "fmt" "time" - "github.com/artem-sidorenko/chagen/datasource/connectors/helpers" + "github.com/artem-sidorenko/chagen/data" + "github.com/artem-sidorenko/chagen/internal/testing/helpers" ) // Tag describes a struct with tag information type Tag struct { Tag string Commit string - ReleaseTime *time.Time + ReleaseTime *time.Time // if its nil -> there is no Release present, just the tag } // Tags returns different tags func Tags() []Tag { return []Tag{ - {"v0.0.1", "7d84cdb2f7c2d4619cda4b8adeb1897097b5c8fc", helpers.TimePtr(time.Unix(2047083657, 0))}, + {"v0.0.1", "7d84cdb2f7c2d4619cda4b8adeb1897097b5c8fc", helpers.TimePtr(1047083657)}, {"v0.0.2", "b3622b516b8ad70ce5dc3fa422fb90c3b58fa9da", nil}, - {"v0.0.3", "52f214dc3bf6c0e2a87eae6eab363a317c5a665f", helpers.TimePtr(time.Unix(2047283657, 0))}, + {"v0.0.3", "52f214dc3bf6c0e2a87eae6eab363a317c5a665f", helpers.TimePtr(1047283657)}, {"v0.0.4", "d4ff341587bc80a9c897c28340df9fe8f9fc6309", nil}, {"v0.0.5", "746e45ea014e257bcb7caa2c100ed1e5f63ed234", nil}, {"v0.0.6", "ddde800c451bae606713ae0f8418badcf31db120", nil}, - {"v0.0.7", "d21438494dd0722c1d13dc496ae1f60fb85084c1", helpers.TimePtr(time.Unix(2047683657, 0))}, + {"v0.0.7", "d21438494dd0722c1d13dc496ae1f60fb85084c1", helpers.TimePtr(1047683657)}, {"v0.0.8", "8d8d817a530bc1c3f792d9508c187b5769c434c5", nil}, {"v0.0.9", "fc9f16ecc043e3fe422834cd127311d11d423668", nil}, - {"v0.1.0", "dbbf36ffaae700a2ce03ef849d6f944031f34b95", helpers.TimePtr(time.Unix(2047983657, 0))}, - {"v0.1.1", "fc5d68ff1cf691e09f6ead044813274953c9b843", helpers.TimePtr(time.Unix(2048083657, 0))}, - {"v0.1.2", "d8351413f688c96c2c5d6fe58ebf5ac17f545bc0", helpers.TimePtr(time.Unix(2048183657, 0))}, + {"v0.1.0", "dbbf36ffaae700a2ce03ef849d6f944031f34b95", helpers.TimePtr(1047983657)}, + {"v0.1.1", "fc5d68ff1cf691e09f6ead044813274953c9b843", helpers.TimePtr(1048083657)}, + {"v0.1.2", "d8351413f688c96c2c5d6fe58ebf5ac17f545bc0", helpers.TimePtr(1048183657)}, } } + +// DataTags returns the tags in the data.Tag format +func DataTags() []data.Tag { + var r []data.Tag + commits := CommitsBySHA() + for _, t := range Tags() { + r = append(r, data.Tag{ + Commit: t.Commit, + Date: commits[t.Commit].AuthoredDate, + Name: t.Tag, + URL: fmt.Sprintf("https://test.example.com/tags/%v", t.Tag), + }) + } + return r +} diff --git a/datasource/connectors/internal/testing/apitestdata/apitestdata.go b/internal/testing/testdata/testdata.go similarity index 87% rename from datasource/connectors/internal/testing/apitestdata/apitestdata.go rename to internal/testing/testdata/testdata.go index f2f8ba4..fd9f5d4 100644 --- a/datasource/connectors/internal/testing/apitestdata/apitestdata.go +++ b/internal/testing/testdata/testdata.go @@ -14,5 +14,5 @@ limitations under the License. */ -// Package apitestdata provides some data for test clients of APIs -package apitestdata +// Package testdata provides some data for testing purposes +package testdata