-
Notifications
You must be signed in to change notification settings - Fork 351
/
event.go
42 lines (38 loc) · 1.48 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package actions
import (
"encoding/json"
"time"
"github.com/treeverse/lakefs/pkg/graveler"
)
type EventInfo struct {
EventType string `json:"event_type"`
EventTime string `json:"event_time"`
ActionName string `json:"action_name"`
HookID string `json:"hook_id"`
RepositoryID string `json:"repository_id"`
BranchID string `json:"branch_id,omitempty"`
SourceRef string `json:"source_ref,omitempty"`
TagID string `json:"tag_id,omitempty"`
CommitID string `json:"commit_id,omitempty"`
CommitMessage string `json:"commit_message,omitempty"`
Committer string `json:"committer,omitempty"`
CommitMetadata map[string]string `json:"commit_metadata,omitempty"`
}
func marshalEventInformation(actionName, hookID string, record graveler.HookRecord) ([]byte, error) {
now := time.Now()
info := EventInfo{
EventType: string(record.EventType),
EventTime: now.UTC().Format(time.RFC3339),
ActionName: actionName,
HookID: hookID,
RepositoryID: record.RepositoryID.String(),
BranchID: record.BranchID.String(),
SourceRef: record.SourceRef.String(),
TagID: record.TagID.String(),
CommitID: record.CommitID.String(),
CommitMessage: record.Commit.Message,
Committer: record.Commit.Committer,
CommitMetadata: record.Commit.Metadata,
}
return json.Marshal(info)
}