/
accessor.go
228 lines (186 loc) · 7.09 KB
/
accessor.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
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
222
223
224
225
226
227
228
// Copyright 2020 Steve Jefferson. All rights reserved.
// Use of this source code is governed by a GPL-style
// license that can be found in the LICENSE file.
package trac
// Label describes a Trac "label" - a generalisation of a component, priority, resolution, severity, type and version
type Label struct {
Name string
Description string
}
// Milestone describes a Trac milestone.
type Milestone struct {
Name string
Description string
Due int64
Completed int64
}
const (
// TicketStatusClosed indicates a closed Trac ticket
TicketStatusClosed string = "closed"
// TicketStatusReopened indicates a reopened Trac ticket
TicketStatusReopened string = "reopened"
)
// Ticket describes a Trac milestone.
type Ticket struct {
TicketID int64
Summary string
Description string
Owner string
Reporter string
MilestoneName string
ComponentName string
PriorityName string
ResolutionName string
SeverityName string
TypeName string
VersionName string
Status string
Created int64
Updated int64
}
// TicketChangeType enumerates the types of ticket change we handle.
type TicketChangeType string
const (
// TicketCommentChange denotes a ticket comment change.
TicketCommentChange TicketChangeType = "comment"
// TicketComponentChange denotes a ticket component change.
TicketComponentChange TicketChangeType = "component"
// TicketMilestoneChange denotes a ticket milestone change.
TicketMilestoneChange TicketChangeType = "milestone"
// TicketOwnerChange denotes a ticket ownership change.
TicketOwnerChange TicketChangeType = "owner"
// TicketPriorityChange denotes a ticket resolution change.
TicketPriorityChange TicketChangeType = "priority"
// TicketResolutionChange denotes a ticket resolution change.
TicketResolutionChange TicketChangeType = "resolution"
// TicketSeverityChange denotes a ticket severity change.
TicketSeverityChange TicketChangeType = "severity"
// TicketStatusChange denotes a ticket status change.
TicketStatusChange TicketChangeType = "status"
// TicketSummaryChange denotes a ticket summary change.
TicketSummaryChange TicketChangeType = "summary"
// TicketTypeChange denotes a ticket type change.
TicketTypeChange TicketChangeType = "type"
// TicketVersionChange denotes a ticket type change.
TicketVersionChange TicketChangeType = "version"
)
// TicketChange describes a change to a Trac ticket.
type TicketChange struct {
TicketID int64
ChangeType TicketChangeType
Author string
OldValue string
NewValue string
Time int64
}
// TicketAttachment describes an attachment to a Trac ticket.
type TicketAttachment struct {
TicketID int64
Time int64
Size int64
Author string
FileName string
Description string
}
// WikiPage describes a Trac wiki page.
type WikiPage struct {
Name string
Text string
Author string
Comment string
Version int64
UpdateTime int64
}
// WikiAttachment describes an attachment to a Trac wiki page.
type WikiAttachment struct {
PageName string
FileName string
}
// NullID id used for Trac lookup failures
// The Trac schema does not seem to use foreign key references so there is no specific null Trac id value
// The value chosen here is therefore just one that will not occur in reality and is also simultaneously different from the Gitea one
// so we are more likely to detect mis-assignments.
const NullID = int64(-1)
// Accessor is the interface through which we access all Trac data.
type Accessor interface {
/*
* Components
*/
// GetComponents retrieves all Trac components, passing each one to the provided "handler" function.
GetComponents(handlerFn func(component *Label) error) error
/*
* Configuration
*/
// GetStringConfig retrieves a value from the Trac config as a string.
GetStringConfig(sectionName string, configName string) string
/*
* Milestones
*/
// GetMilestones retrieves all Trac milestones, passing data from each one to the provided "handler" function.
GetMilestones(handlerFn func(milestone *Milestone) error) error
/*
* Paths
*/
// GetFullPath retrieves the absolute path of a path relative to the root of the Trac installation.
GetFullPath(element ...string) string
/*
* Priorities
*/
// GetPriorities retrieves all priorities used in Trac tickets, passing each one to the provided "handler" function.
GetPriorities(handlerFn func(priority *Label) error) error
/*
* Resolutions
*/
// GetResolutions retrieves all resolutions used in Trac tickets, passing each one to the provided "handler" function.
GetResolutions(handlerFn func(resolution *Label) error) error
/*
* Severities
*/
// GetSeverities retrieves all severities used in Trac tickets, passing each one to the provided "handler" function.
GetSeverities(handlerFn func(severity *Label) error) error
/*
* Tickets
*/
// GetTickets retrieves all Trac tickets, passing data from each one to the provided "handler" function.
GetTickets(handlerFn func(ticket *Ticket) error) error
/*
* Ticket Changes
*/
// GetTicketChanges retrieves all changes on a given Trac ticket in ascending time order, passing data from each one to the provided "handler" function.
GetTicketChanges(ticketID int64, handlerFn func(change *TicketChange) error) error
// GetTicketCommentTime retrieves the timestamp for a given comment for a given Trac ticket
GetTicketCommentTime(ticketID int64, changeNum int64) (int64, error)
/*
* Ticket Attachments
*/
// GetTicketAttachmentPath retrieves the path to a named attachment to a Trac ticket.
GetTicketAttachmentPath(attachment *TicketAttachment) string
// GetTicketAttachments retrieves all attachments for a given Trac ticket, passing data from each one to the provided "handler" function.
GetTicketAttachments(ticketID int64, handlerFn func(attachment *TicketAttachment) error) error
/*
* Types
*/
// GetTypes retrieves all types used in Trac tickets, passing each one to the provided "handler" function.
GetTypes(handlerFn func(tracType *Label) error) error
/*
* Users
*/
// GetUserNames retrieves the names of all users mentioned in Trac tickets, wiki pages etc., passing each one to the provided "handler" function.
GetUserNames(handlerFn func(userName string) error) error
/*
* Versions
*/
// GetVersions retrieves all versions used in Trac, passing each one to the provided "handler" function.
GetVersions(handlerFn func(version *Label) error) error
/*
* Wiki
*/
// GetWikiPages retrieves all Trac wiki pages, passing data from each one to the provided "handler" function.
GetWikiPages(handlerFn func(page *WikiPage) error) error
// GetWikiAttachmentPath retrieves the path to a named attachment to a Trac wiki page.
GetWikiAttachmentPath(attachment *WikiAttachment) string
// GetWikiAttachments retrieves all Trac wiki page attachments, passing data from each one to the provided "handler" function.
GetWikiAttachments(handlerFn func(attachment *WikiAttachment) error) error
// IsPredefinedPage returns true if the provided page name is one of Trac's predefined ones - by default we ignore these
IsPredefinedPage(pageName string) bool
}