Skip to content

Commit 9e357d8

Browse files
committed
initiate streams package
This contains definitions for all message types present in "JSON stream" messages, produced by the `gerrit stream-events` command, or the webhook plugin. As per the discussion in andygrunwald#187 (comment), this is put in a separate package to avoid clashes with other types. Closes andygrunwald#187.
1 parent 650ad12 commit 9e357d8

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed

streams/events.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package streams
2+
3+
// Event represents events sent via the `gerrit stream-events` command, or sent as a webhook.
4+
// It differs slightly from the REST API types, which is why this lives in a separate package.
5+
// Docs: https://gerrit-review.googlesource.com/Documentation/cmd-stream-events.html#events
6+
type Event struct {
7+
Type string `json:"type"`
8+
9+
Change Change `json:"change"`
10+
PatchSet PatchSet `json:"patchSet"`
11+
12+
Abandoner Account `json:"abandoner"`
13+
Author Account `json:"author"`
14+
Adder Account `json:"adder"`
15+
Changer Account `json:"changer"`
16+
Deleter Account `json:"deleter"`
17+
Editor Account `json:"editor"`
18+
Restorer Account `json:"restorer"`
19+
Remover Account `json:"remover"`
20+
Reviewer Account `json:"reviewer"`
21+
Submitter Account `json:"submitter"`
22+
Uploader Account `json:"uploader"`
23+
24+
Reason string `json:"reason,omitempty"`
25+
EventCreatedOn int `json:"eventCreatedOn,omitempty"`
26+
NewRev string `json:"newRev,omitempty"`
27+
Approvals []Approval `json:"approvals,omitempty"`
28+
Comment string `json:"comment,omitempty"`
29+
30+
Added []string `json:"added,omitempty"`
31+
Removed []string `json:"removed,omitempty"`
32+
Hashtags []string `json:"hashtags,omitempty"`
33+
34+
ProjectName string `json:"projectName,omitempty"`
35+
ProjectHead string `json:"projectHead,omitempty"`
36+
37+
RefUpdate RefUpdate `json:"refUpdate"`
38+
RefUpdates []RefUpdate `json:"refUpdates,omitempty"`
39+
40+
OldTopic string `json:"oldTopic,omitempty"`
41+
42+
OldHead string `json:"oldHead,omitempty"`
43+
NewHead string `json:"newHead,omitempty"`
44+
}

streams/types.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package streams
2+
3+
type Change struct {
4+
Project string `json:"project,omitempty"`
5+
Branch string `json:"branch,omitempty"`
6+
Topic string `json:"topic,omitempty"`
7+
ID string `json:"id,omitempty"`
8+
Number string `json:"number,omitempty"`
9+
Subject string `json:"subject,omitempty"`
10+
Owner Account `json:"owner"`
11+
URL string `json:"url,omitempty"`
12+
CommitMessage string `json:"commitMessage,omitempty"`
13+
Hashtags []string `json:"hashtags,omitempty"`
14+
CreatedOn int `json:"createdOn,omitempty"`
15+
LastUpdated int `json:"lastUpdated,omitempty"`
16+
Open bool `json:"open,omitempty"`
17+
Status string `json:"status,omitempty"`
18+
Private bool `json:"private,omitempty"`
19+
Wip bool `json:"wip,omitempty"`
20+
Comments []Message `json:"comments,omitempty"`
21+
TrackingIDs []TrackingID `json:"trackingIds,omitempty"`
22+
CurrentPatchSet PatchSet `json:"currentPatchSet"`
23+
PatchSets []PatchSet `json:"patchSets,omitempty"`
24+
DependsOn []Dependency `json:"dependsOn,omitempty"`
25+
NeededBy []Dependency `json:"neededBy,omitempty"`
26+
SubmitRecords SubmitRecord `json:"submitRecords"`
27+
AllReviewers []Account `json:"allReviewers,omitempty"`
28+
}
29+
30+
type TrackingID struct {
31+
System string `json:"system,omitempty"`
32+
ID string `json:"id,omitempty"`
33+
}
34+
35+
type Account struct {
36+
Name string `json:"name,omitempty"`
37+
Email string `json:"email,omitempty"`
38+
Username string `json:"username,omitempty"`
39+
}
40+
41+
type PatchSet struct {
42+
Number string `json:"number,omitempty"`
43+
Revision string `json:"revision,omitempty"`
44+
Parents []string `json:"parents,omitempty"`
45+
Ref string `json:"ref,omitempty"`
46+
Uploader Account `json:"uploader"`
47+
Author Account `json:"author"`
48+
CreatedOn int `json:"createdOn,omitempty"`
49+
Kind string `json:"kind,omitempty"`
50+
Approvals Approval `json:"approvals"`
51+
Comments []PatchsetComment `json:"comments,omitempty"`
52+
Files []File `json:"files,omitempty"`
53+
SizeInsertions int `json:"sizeInsertions,omitempty"`
54+
SizeDeletions int `json:"sizeDeletions,omitempty"`
55+
}
56+
57+
type Approval struct {
58+
Type string `json:"type,omitempty"`
59+
Description string `json:"description,omitempty"`
60+
Value string `json:"value,omitempty"`
61+
OldValue string `json:"oldValue,omitempty"`
62+
GrantedOn int `json:"grantedOn,omitempty"`
63+
By Account `json:"by"`
64+
}
65+
66+
type RefUpdate struct {
67+
OldRev string `json:"oldRev,omitempty"`
68+
NewRev string `json:"newRev,omitempty"`
69+
RefName string `json:"refName,omitempty"`
70+
Project string `json:"project,omitempty"`
71+
}
72+
73+
type SubmitRecord struct {
74+
Status string `json:"status,omitempty"`
75+
Labels []Label `json:"labels,omitempty"`
76+
Requirements []Requirement `json:"requirements,omitempty"`
77+
}
78+
79+
type Requirement struct {
80+
FallbackText string `json:"fallbackText,omitempty"`
81+
Type string `json:"type,omitempty"`
82+
Data interface{} `json:"data,omitempty"`
83+
}
84+
85+
type Label struct {
86+
Label string `json:"label,omitempty"`
87+
Status string `json:"status,omitempty"`
88+
By Account `json:"by"`
89+
}
90+
91+
type Dependency struct {
92+
ID string `json:"id,omitempty"`
93+
Number string `json:"number,omitempty"`
94+
Revision string `json:"revision,omitempty"`
95+
Ref string `json:"ref,omitempty"`
96+
IsCurrentPatchSet bool `json:"isCurrentPatchSet,omitempty"`
97+
}
98+
99+
type Message struct {
100+
Timestamp int `json:"timestamp,omitempty"`
101+
Reviewer Account `json:"reviewer"`
102+
Message string `json:"message,omitempty"`
103+
}
104+
105+
type PatchsetComment struct {
106+
File string `json:"file,omitempty"`
107+
Line string `json:"line,omitempty"`
108+
Reviewer Account `json:"reviewer"`
109+
Message string `json:"message,omitempty"`
110+
}
111+
112+
type File struct {
113+
File string `json:"file,omitempty"`
114+
FileOld string `json:"fileOld,omitempty"`
115+
Type string `json:"type,omitempty"`
116+
Insertions int `json:"insertions,omitempty"`
117+
Deletions int `json:"deletions,omitempty"`
118+
}

0 commit comments

Comments
 (0)