Skip to content

Commit

Permalink
added date info for commits in push hook (#223)
Browse files Browse the repository at this point in the history
* added date info for commits in push hook
  • Loading branch information
raghavharness committed Sep 5, 2022
1 parent f4a3110 commit c43e9f0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/webhooks/branch_create.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"id": "c4c79227ed610f1151f05bbc5be33b4f340d39c8",
"message": "update readme\n",
"timestamp": "2017-12-10T08:28:36-08:00",
"timestamp": "2017-12-10T08:28:36+00:00",
"url": "https://gitlab.com/gitlab-org/hello-world/commit/c4c79227ed610f1151f05bbc5be33b4f340d39c8",
"author": {
"name": "Sid Sijbrandij",
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/gitlab/testdata/webhooks/branch_create.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"Author": {
"Name": "Sid Sijbrandij",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Date": "2017-12-10T08:28:36Z",
"Login": "",
"Avatar": ""
},
"Committer": {
"Name": "Sid Sijbrandij",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Date": "2017-12-10T08:28:36Z",
"Login": "",
"Avatar": ""
},
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/webhooks/push.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"id": "2adc9465c4edfc33834e173fe89436a7cb899a1d",
"message": "added readme\n",
"timestamp": "2017-12-10T08:26:38-08:00",
"timestamp": "2017-12-10T08:26:38+00:00",
"url": "https://gitlab.com/gitlab-org/hello-world/commit/2adc9465c4edfc33834e173fe89436a7cb899a1d",
"author": {
"name": "Sid Sijbrandij",
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/gitlab/testdata/webhooks/push.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"Author": {
"Name": "Sid Sijbrandij",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Date": "2017-12-10T08:26:38Z",
"Login": "",
"Avatar": ""
},
"Committer": {
"Name": "Sid Sijbrandij",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Date": "2017-12-10T08:26:38Z",
"Login": "",
"Avatar": ""
},
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/webhooks/tag_create.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"id": "2adc9465c4edfc33834e173fe89436a7cb899a1d",
"message": "added readme\n",
"timestamp": "2017-12-10T08:26:38-08:00",
"timestamp": "2017-12-10T08:26:38+00:00",
"url": "https://gitlab.com/gitlab-org/hello-world/commit/2adc9465c4edfc33834e173fe89436a7cb899a1d",
"author": {
"name": "Sid Sijbrandij",
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/gitlab/testdata/webhooks/tag_create.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"Author": {
"Name": "Sid Sijbrandij",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Date": "2017-12-10T08:26:38Z",
"Login": "",
"Avatar": ""
},
"Committer": {
"Name": "Sid Sijbrandij",
"Email": "[email protected]",
"Date": "0001-01-01T00:00:00Z",
"Date": "2017-12-10T08:26:38Z",
"Login": "",
"Avatar": ""
},
Expand Down
52 changes: 27 additions & 25 deletions scm/driver/gitlab/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/drone/go-scm/scm"
"github.com/drone/go-scm/scm/driver/internal/null"
)

type webhookService struct {
Expand Down Expand Up @@ -130,10 +131,12 @@ func convertPushHook(src *pushHook) *scm.PushHook {
Author: scm.Signature{
Name: c.Author.Name,
Email: c.Author.Email,
Date: c.Timestamp.ValueOrZero(),
},
Committer: scm.Signature{
Name: c.Author.Name,
Email: c.Author.Email,
Date: c.Timestamp.ValueOrZero(),
},
})
}
Expand Down Expand Up @@ -219,8 +222,8 @@ func converBranchHook(src *pushHook) *scm.BranchHook {
}

func convertCommentHook(src *commentHook) (*scm.IssueCommentHook, error) {
var issue scm.Issue
var comment scm.Comment
var issue scm.Issue
var comment scm.Comment

switch src.ObjectAttributes.NoteableType {
case "Commit", "Issue", "Snippet":
Expand All @@ -242,7 +245,7 @@ func convertCommentHook(src *commentHook) (*scm.IssueCommentHook, error) {
Updated: parseTimeString(src.MergeRequest.UpdatedAt),
}
for _, l := range src.MergeRequest.Labels {
label := scm.Label {
label := scm.Label{
Name: l.Title,
Color: l.Color,
}
Expand Down Expand Up @@ -271,16 +274,16 @@ func convertCommentHook(src *commentHook) (*scm.IssueCommentHook, error) {

namespace, _ := scm.Split(src.Project.PathWithNamespace)
dst := scm.IssueCommentHook{
Action: scm.ActionCreate,
Repo: scm.Repository{
ID: strconv.Itoa(src.Project.ID),
Namespace: namespace,
Name: src.Repository.Name,
Clone: src.Project.GitHTTPURL,
CloneSSH: src.Project.GitSSHURL,
Link: src.Project.WebURL,
Branch: src.Project.DefaultBranch,
Private: false, // TODO how do we correctly set Private vs Public?
Action: scm.ActionCreate,
Repo: scm.Repository{
ID: strconv.Itoa(src.Project.ID),
Namespace: namespace,
Name: src.Repository.Name,
Clone: src.Project.GitHTTPURL,
CloneSSH: src.Project.GitSSHURL,
Link: src.Project.WebURL,
Branch: src.Project.DefaultBranch,
Private: false, // TODO how do we correctly set Private vs Public?
},
Issue: issue,
Comment: comment,
Expand Down Expand Up @@ -383,7 +386,7 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
}
}

func parseTimeString(timeString string) (time.Time) {
func parseTimeString(timeString string) time.Time {
layout := "2006-01-02 15:04:05 UTC"
// Returns zero value of time in case of an error 0001-01-01 00:00:00 +0000 UTC
t, _ := time.Parse(layout, timeString)
Expand Down Expand Up @@ -424,10 +427,10 @@ type (
HTTPURL string `json:"http_url"`
} `json:"project"`
Commits []struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp string `json:"timestamp"`
URL string `json:"url"`
ID string `json:"id"`
Message string `json:"message"`
Timestamp null.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
Expand Down Expand Up @@ -471,7 +474,7 @@ type (
SSHURL string `json:"ssh_url"`
HTTPURL string `json:"http_url"`
} `json:"project"`
ObjectAttributes struct {
ObjectAttributes struct {
ID int `json:"id"`
Note string `json:"note"`
NoteableType string `json:"noteable_type"`
Expand All @@ -496,13 +499,13 @@ type (
Type interface{} `json:"type"`
Description string `json:"description"`
} `json:"object_attributes"`
Repository struct {
Repository struct {
Name string `json:"name"`
URL string `json:"url"`
Description string `json:"description"`
Homepage string `json:"homepage"`
} `json:"repository"`
MergeRequest struct {
MergeRequest struct {
AssigneeID interface{} `json:"assignee_id"`
AuthorID int `json:"author_id"`
CreatedAt string `json:"created_at"`
Expand Down Expand Up @@ -558,7 +561,7 @@ type (
SSHURL string `json:"ssh_url"`
HTTPURL string `json:"http_url"`
} `json:"source"`
Target struct {
Target struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Expand All @@ -576,7 +579,7 @@ type (
SSHURL string `json:"ssh_url"`
HTTPURL string `json:"http_url"`
} `json:"target"`
LastCommit struct {
LastCommit struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp string `json:"timestamp"`
Expand All @@ -586,7 +589,7 @@ type (
Email string `json:"email"`
} `json:"author"`
} `json:"last_commit"`
Labels []struct {
Labels []struct {
ID int `json:"id"`
Title string `json:"title"`
Color string `json:"color"`
Expand All @@ -598,7 +601,6 @@ type (
Type string `json:"type"`
GroupID interface{} `json:"group_id"`
} `json:"labels"`

} `json:"merge_request"`
}

Expand Down

0 comments on commit c43e9f0

Please sign in to comment.