Commit 0f869110 authored by Reficul's avatar Reficul Committed by Sander van Harmelen

fix event structs (#274)

parent d2fe6f36
......@@ -49,9 +49,21 @@ type PushEvent struct {
WebURL string `json:"web_url"`
Visibility VisibilityValue `json:"visibility"`
} `json:"project"`
Repository *Repository `json:"repository"`
Commits []*Commit `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
Repository *Repository `json:"repository"`
Commits []*struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
Added []string `json:"added"`
Modified []string `json:"modified"`
Removed []string `json:"removed"`
} `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
}
// TagEvent represents a tag event.
......@@ -84,9 +96,21 @@ type TagEvent struct {
WebURL string `json:"web_url"`
Visibility VisibilityValue `json:"visibility"`
} `json:"project"`
Repository *Repository `json:"repository"`
Commits []*Commit `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
Repository *Repository `json:"repository"`
Commits []*struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
Added []string `json:"added"`
Modified []string `json:"modified"`
Removed []string `json:"removed"`
} `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
}
// IssueEvent represents a issue event.
......@@ -186,7 +210,16 @@ type CommitCommentEvent struct {
DeletedFile bool `json:"deleted_file"`
} `json:"st_diff"`
} `json:"object_attributes"`
Commit *Commit `json:"commit"`
Commit *struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
} `json:"commit"`
}
// MergeCommentEvent represents a comment on a merge event.
......@@ -272,7 +305,10 @@ type MergeCommentEvent struct {
Message string `json:"message"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author *Author `json:"author"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
} `json:"last_commit"`
WorkInProgress bool `json:"work_in_progress"`
TotalTimeSpent int `json:"total_time_spent"`
......@@ -431,7 +467,10 @@ type MergeEvent struct {
Message string `json:"message"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author *Author `json:"author"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
} `json:"last_commit"`
WorkInProgress bool `json:"work_in_progress"`
URL string `json:"url"`
......@@ -531,10 +570,10 @@ type PipelineEvent struct {
Visibility VisibilityValue `json:"visibility"`
} `json:"project"`
Commit struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
URL string `json:"url"`
ID string `json:"id"`
Message string `json:"message"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
......
......@@ -87,6 +87,17 @@ func TestPushEventUnmarshal(t *testing.T) {
t.Errorf("ProjectID is %v, want %v", event.ProjectID, 15)
}
if event.UserName != "John Smith" {
t.Errorf("Username is %s, want %s", event.UserName, "John Smith")
}
if event.Commits[0] == nil || event.Commits[0].Timestamp == nil {
t.Errorf("Commit Timestamp isn't nil")
}
if event.Commits[0] == nil || event.Commits[0].Author.Name != "Jordi Mallach" {
t.Errorf("Commit Username is %s, want %s", event.UserName, "Jordi Mallach")
}
}
func TestMergeEventUnmarshal(t *testing.T) {
......@@ -199,6 +210,17 @@ func TestMergeEventUnmarshal(t *testing.T) {
t.Errorf("ObjectAttributes is %v, want %v", event.ObjectAttributes.Assignee.Username, "user1")
}
if event.User.Name == "" {
t.Errorf("Username is %s, want %s", event.User.Name, "Administrator")
}
if event.ObjectAttributes.LastCommit.Timestamp == nil {
t.Errorf("Timestamp isn't nil")
}
if name := event.ObjectAttributes.LastCommit.Author.Name; name != "GitLab dev user" {
t.Errorf("Commit Username is %s, want %s", name, "GitLab dev user")
}
}
func TestPipelineEventUnmarshal(t *testing.T) {
......@@ -376,6 +398,17 @@ func TestPipelineEventUnmarshal(t *testing.T) {
t.Errorf("ObjectAttributes is %v, want %v", event.ObjectAttributes.ID, 1977)
}
if event.User.Name == "" {
t.Errorf("Username is %s, want %s", event.User.Name, "Administrator")
}
if event.Commit.Timestamp == nil {
t.Errorf("Timestamp isn't nil")
}
if name := event.Commit.Author.Name; name != "User" {
t.Errorf("Commit Username is %s, want %s", name, "User")
}
}
func TestBuildEventUnmarshal(t *testing.T) {
......@@ -595,4 +628,16 @@ func TestMergeEventUnmarshalFromGroup(t *testing.T) {
if event.Assignee.Username != "root" {
t.Errorf("Assignee.Username is %v, want %v", event.Assignee, "root")
}
if event.User.Name == "" {
t.Errorf("Username is %s, want %s", event.User.Name, "Administrator")
}
if event.ObjectAttributes.LastCommit.Timestamp == nil {
t.Errorf("Timestamp isn't nil")
}
if name := event.ObjectAttributes.LastCommit.Author.Name; name != "Test User" {
t.Errorf("Commit Username is %s, want %s", name, "Test User")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment