about summary refs log tree commit diff
path: root/fun/clbot/gerrit/gerritevents/types.go
blob: 75987a2da6016918d703ab84f225ecfd139c89af (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package gerritevents

// These types are taken from https://cl.tvl.fyi/Documentation/json.html.

// Account is a Gerrit account (or just a Git name+email pair).
type Account struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Username string `json:"username"`
}

// ChangeStatus represents the states a change can be in.
type ChangeStatus string

const (
	// ChangeStatusNew is the state a change is in during review.
	ChangeStatusNew ChangeStatus = "NEW"

	// ChangeStatusMerged indicates a change was merged to the target branch.
	ChangeStatusMerged ChangeStatus = "MERGED"

	// ChangeStatusAbandoned indicates a change was marked as abandoned.
	ChangeStatusAbandoned ChangeStatus = "ABANDONED"
)

// Message is a message left by a reviewer.
type Message struct {
	Timestamp Time    `json:"timestamp"`
	Reviewer  Account `json:"reviewer"`
	Message   string  `json:"message"`
}

// TrackingID allows storing identifiers from external systems, i.e. bug trackers.
type TrackingID struct {
	System string `json:"system"`
	ID     string `json:"id"`
}

// ChangeKind indicates the different changes that can be made to a change.
type ChangeKind string

const (
	// ChangeKindRework indicates a non-trivial content change.
	ChangeKindRework ChangeKind = "REWORK"

	// ChangeKindTrivialRebase indicates a conflict-free merge between the new parent and the prior patch set.
	ChangeKindTrivialRebase ChangeKind = "TRIVIAL_REBASE"

	// ChangeKindMergeFirstParentUpdate indicates a conflict-free change of the first parent of a merge commit.
	ChangeKindMergeFirstParentUpdate ChangeKind = "MERGE_FIRST_PARENT_UPDATE"

	// ChangeKindNoCodeChange indicates no code change (the tree and parent trees are unchanged) - commit message probably changed.
	ChangeKindNoCodeChange ChangeKind = "NO_CODE_CHANGE"

	// ChangeKindNoChange indicates nothing changes: the commit message, tree, and parent tree are unchanged.
	ChangeKindNoChange ChangeKind = "NO_CHANGE"
)

// Approval represents the current and past state of an approval label.
type Approval struct {
	Type        string   `json:"type"`
	Description string   `json:"description"`
	Value       string   `json:"value"`
	OldValue    *string  `json:"oldValue"`
	GrantedOn   *Time    `json:"grantedOn"`
	By          *Account `json:"by"`
}

// PatchSetComment is a single comment left on a patchset.
type PatchSetComment struct {
	File     string  `json:"file"`
	Line     int     `json:"line"`
	Reviewer Account `json:"reviewer"`
	Message  string  `json:"message"`
}

// FilePatchType represents the different modifications that can be made to a file by a patchset.
type FilePatchType string

const (
	// FilePatchTypeAdded indicates the file did not exist, and this patchset adds it to the tree.
	FilePatchTypeAdded FilePatchType = "ADDED"

	// FilePatchTypeModified indicates the file exists before and after this patchset.
	FilePatchTypeModified FilePatchType = "MODIFIED"

	// FilePatchTypeDeleted indicates the file is removed by this patchset.
	FilePatchTypeDeleted FilePatchType = "DELETED"

	// FilePatchTypeRenamed indicates the file has a different name before this patchset than after.
	FilePatchTypeRenamed FilePatchType = "RENAMED"

	// FilePatchTypeCopied indicates the file was copied from a different file.
	FilePatchTypeCopied FilePatchType = "COPIED"

	// FilePatchTypeRewrite indicates the file had a significant quantity of content changed.
	FilePatchTypeRewrite FilePatchType = "REWRITE"
)

// File represents a file in a patchset as well as how it is being modified.
type File struct {
	File    string        `json:"file"`
	FileOld string        `json:"fileOld"`
	Type    FilePatchType `json:"type"`
}

// PatchSet represents a single patchset within a change.
type PatchSet struct {
	Number         int               `json:"number"`
	Revision       string            `json:"revision"`
	Parents        []string          `json:"parents"`
	Ref            string            `json:"ref"`
	Uploader       Account           `json:"uploader"`
	Author         Account           `json:"author"`
	CreatedOn      Time              `json:"createdOn"`
	Kind           ChangeKind        `json:"kind"`
	Approvals      []Approval        `json:"approvals"`
	Comments       []PatchSetComment `json:"comments"`
	Files          []File            `json:"file"`
	SizeInsertions int               `json:"sizeInsertions"`
	SizeDeletions  int               `json:"sizeDeletions"`
}

// Dependency represents a change on which this change is dependent.
type Dependency struct {
	ID                string `json:"id"`
	Number            int    `json:"number"`
	Revision          string `json:"revision"`
	Ref               string `json:"ref"`
	IsCurrentPatchSet bool   `json:"isCurrentPatchSet"`
}

// SubmitStatus indicates whether this change has met the submit conditions and is ready to submit.
type SubmitStatus string

const (
	// SubmitStatusOK indicates this change is ready to submit - all submit requirements are met.
	SubmitStatusOK SubmitStatus = "OK"

	// SubmitStatusNotReady indicates this change cannot yet be submitted.
	SubmitStatusNotReady SubmitStatus = "NOT_READY"

	// SubmitStatusRuleError indicates the submit rules could not be evaluted. Administrator intervention is required.
	SubmitStatusRuleError SubmitStatus = "RULE_ERROR"
)

// LabelStatus indicates whether this label permits submission and if the label can be granted by anyone.
type LabelStatus string

const (
	// LabelStatusOK indicates that this label provides what is necessary for submission (e.g. CR+2).
	LabelStatusOK LabelStatus = "OK"

	// LabelStatusReject indicates this label prevents submission (e.g. CR-2).
	LabelStatusReject LabelStatus = "REJECT"

	// LabelStatusNeed indicates this label is required for submission, but has not been satisfied (e.g. CR0).
	LabelStatusNeed LabelStatus = "NEED"

	// LabelStatusMay indicates this label is not required for submission. It may or may not be set.
	LabelStatusMay LabelStatus = "MAY"

	// LabelStatusImpossible indicates this label is required for submission, but cannot be satisfied. The ACLs on this label may be set incorrectly.
	LabelStatusImpossible LabelStatus = "IMPOSSIBLE"
)

// Label represents the status of a particular label.
type Label struct {
	Label  string      `json:"label"`
	Status LabelStatus `json:"status"`
	By     Account     `json:"by"`
}

// Requirement represents a submit requirement.
type Requirement struct {
	FallbackText string `json:"fallbackText"`
	Type         string `json:"type"`
	// TODO(lukegb): data
}

// SubmitRecord represents the current submission state of a change.
type SubmitRecord struct {
	Status       SubmitStatus  `json:"status"`
	Labels       []Label       `json:"labels"`
	Requirements []Requirement `json:"requirements"`
}

// Change represents a Gerrit CL.
type Change struct {
	Project         string         `json:"project"`
	Branch          string         `json:"branch"`
	Topic           string         `json:"topic"`
	ID              string         `json:"id"`
	Number          int            `json:"number"`
	Subject         string         `json:"subject"`
	Owner           Account        `json:"owner"`
	URL             string         `json:"url"`
	CommitMessage   string         `json:"commitMessage"`
	CreatedOn       Time           `json:"createdOn"`
	LastUpdated     *Time          `json:"lastUpdated"`
	Open            bool           `json:"open"`
	Status          ChangeStatus   `json:"status"`
	Private         bool           `json:"private"`
	WIP             bool           `json:"wip"`
	Comments        []Message      `json:"comments"`
	TrackingIDs     []TrackingID   `json:"trackingIds"`
	CurrentPatchSet *PatchSet      `json:"currentPatchSet"`
	PatchSets       []PatchSet     `json:"patchSets"`
	DependsOn       []Dependency   `json:"dependsOn"`
	NeededBy        []Dependency   `json:"neededBy"`
	SubmitRecords   []SubmitRecord `json:"submitRecord"`
	AllReviewers    []Account      `json:"allReviewers"`
}

// RefUpdate represents a change in a ref.
type RefUpdate struct {
	OldRev  string `json:"oldRev"`
	NewRev  string `json:"newRev"`
	RefName string `json:"refName"`
	Project string `json:"project"`
}