1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package ports
4
5import (
6 "time"
7
8 "bnema.dev/ermite/internal/domain"
9)
10
11// The parameters and results of the use case interfaces (services.go). They
12// live here so that the adapters that call the use cases and the use cases
13// themselves share them without importing each other.
14
15// RepoPage is a page of repositories ordered by name.
16type RepoPage struct {
17 Repos []domain.Repo
18 // NextPageToken is empty on the last page.
19 NextPageToken string
20}
21
22// RepoView is a repository with the Git state that belongs in its summary.
23type RepoView struct {
24 domain.Repo
25 // DefaultBranch is the branch HEAD points to, even when it does not exist
26 // yet; empty when HEAD is detached or the directory is missing.
27 DefaultBranch string
28}
29
30// CreateRepoParams are the settings of a new repository.
31type CreateRepoParams struct {
32 Name domain.RepoName
33 Description string
34 // Visibility defaults to private when empty.
35 Visibility domain.Visibility
36}
37
38// UpdateRepoParams are the changes of Update; a nil field is left alone.
39type UpdateRepoParams struct {
40 Description *string
41 Visibility *domain.Visibility
42 DefaultBranch *string
43 // AllowedMergeModes replaces the allowed merge modes; it must hold at
44 // least one known mode.
45 AllowedMergeModes *[]domain.MergeMode
46 // FailingChecksBlock replaces the setting of that name.
47 FailingChecksBlock *bool
48}
49
50// TokenPage is a page of stored tokens, newest first.
51type TokenPage struct {
52 Tokens []domain.Token
53 // NextPageToken is empty on the last page.
54 NextPageToken string
55}
56
57// CreateTokenParams are the settings of a new token.
58type CreateTokenParams struct {
59 Label string
60 // Scopes must not be empty.
61 Scopes []domain.Scope
62 // Repos limits the token to these repositories; empty means every one.
63 Repos []domain.RepoName
64 // BranchPrefixes limits the token to the branches under these prefixes
65 // (see domain.ParseBranchPrefix); empty means every branch.
66 BranchPrefixes []string
67 // ExpiresAt is the zero time for a token that never expires.
68 ExpiresAt time.Time
69}
70
71// CreatedToken is a new token with its secret, which is shown once and never
72// stored.
73type CreatedToken struct {
74 Token domain.Token
75 Secret string
76}
77
78// ListRefsParams selects the refs to list.
79type ListRefsParams struct {
80 // Kinds restricts the result; empty means every kind.
81 Kinds []domain.RefKind
82 // PageSize is 0 for the default, and lowered to MaxRefPageSize.
83 PageSize int
84 // PageToken is the NextPageToken of the previous page, or empty.
85 PageToken string
86}
87
88// RefPage is a page of refs.
89type RefPage struct {
90 Refs []domain.Ref
91 // NextPageToken is empty on the last page.
92 NextPageToken string
93}
94
95// ListCommitsParams selects a page of history.
96type ListCommitsParams struct {
97 // Revision is where the history starts; the zero value is HEAD. Ignored
98 // when PageToken is set: the token pins the commit the first page started
99 // from, so every page walks the same history even if a branch moves.
100 Revision domain.Revision
101 // Path limits the history to the commits that changed it. It must be the
102 // same on every page of a listing.
103 Path domain.TreePath
104 // PageSize is 0 for the default, and lowered to MaxPageSize.
105 PageSize int
106 // PageToken is the NextPageToken of the previous page, or empty.
107 PageToken string
108}
109
110// HistoryPage is a page of history, newest first.
111type HistoryPage struct {
112 Commits []domain.Commit
113 // NextPageToken is empty on the last page.
114 NextPageToken string
115}
116
117// WatchParams select the events of a watch.
118type WatchParams struct {
119 // Topics are TopicHome or "repo:<name>"; empty means TopicHome.
120 Topics []string
121 // ResumeAfter is the id of the last event the caller saw; empty to
122 // receive only new events.
123 ResumeAfter string
124 // Client identifies where the watch comes from, for the limit per client
125 // (MaxWatchersPerClient): an opaque key such as a normalized address; the
126 // web passes its visitor's. Empty only for callers with no client, which
127 // count against MaxWatchers alone.
128 Client string
129 // Ready, when not nil, is called once the topics are valid and the watch
130 // is registered: events published from then on are not missed. Nothing is
131 // sent before it returns.
132 Ready func()
133}
134
135// WatchEvent is one item of a watch.
136type WatchEvent struct {
137 // ID identifies the event, for resuming. Empty on a gap.
138 ID string
139 // Gap tells that events were lost: the caller must reload what it shows.
140 // Event is nil then.
141 Gap bool
142 // Event is a domain.RepoCreated, RepoUpdated, RepoDeleted, PushEvent,
143 // MergeRequestOpened, MergeRequestMerged, MergeRequestClosed,
144 // MergeRequestReady, CommentAdded, RunUpdated or JobUpdated.
145 Event domain.Event
146 // Repo is the state of the repository at delivery, for RepoCreated and
147 // RepoUpdated.
148 Repo *RepoView
149}
150
151// CreateMergeRequestParams describes the merge request to open.
152type CreateMergeRequestParams struct {
153 Title string
154 Description string
155 // Source is required; Target defaults to the default branch.
156 Source, Target string
157}
158
159// ListMergeRequestsParams selects a page of merge requests.
160type ListMergeRequestsParams struct {
161 // State restricts the result; empty means every state.
162 State domain.MRState
163 // PageSize is 0 for the default, and lowered to MaxPageSize.
164 PageSize int
165 // PageToken is the NextPageToken of the previous page, or empty.
166 PageToken string
167}
168
169// MergeRequestPage is a page of merge requests, highest number first.
170type MergeRequestPage struct {
171 MergeRequests []domain.MergeRequest
172 // NextPageToken is empty on the last page.
173 NextPageToken string
174}
175
176// MergeRequestDetail is a merge request with its review data.
177type MergeRequestDetail struct {
178 MergeRequest domain.MergeRequest
179 // Commits are the commits of the head that the target lacks, newest
180 // first, at most MaxMergeRequestCommits.
181 Commits []domain.Commit
182 CommitsTruncated bool
183 // DiffBaseID is the commit the diff compares from; zero when the source
184 // branch is gone, then the diff is empty.
185 DiffBaseID domain.ObjectID
186 Stats domain.DiffStats
187 Diff domain.Diff
188 // Comments are the comments, oldest first.
189 Comments []domain.Comment
190 // LastReadID is the head recorded by MarkRead; zero when none.
191 LastReadID domain.ObjectID
192 // LastReadLost tells that since-last-read was asked for, a head was
193 // recorded, but that commit is gone: the diff is against the target.
194 LastReadLost bool
195}
196
197// GetMergeRequestOptions say which diff MergeRequestService.Get reads.
198type GetMergeRequestOptions struct {
199 // SinceLastRead compares the head recorded by MarkRead with the head (see Get).
200 SinceLastRead bool
201 // Files, when set, lists every changed file, without the file-count
202 // limit, and reads the hunks of the files in the window only, each within
203 // the per-file and the total limits of domain.DefaultDiffLimits. Unset,
204 // the diff is bounded by domain.DefaultDiffLimits (the API contract).
205 Files *FileWindow
206 // Base and Head, when not zero, are the diff the caller shows: Get
207 // returns domain.ErrConflict when the request's diff base or head differ
208 // (the branch moved, a read was marked).
209 Base, Head domain.ObjectID
210 // DiffOnly skips the commits of the request (Commits stays empty).
211 DiffOnly bool
212}
213
214// FileWindow is the range [From, To) of files whose hunks are read.
215type FileWindow struct{ From, To int }
216
217// AddCommentParams describes the comment to add.
218type AddCommentParams struct {
219 // Path, Line and Side designate a line of the diff; all empty for a
220 // general comment.
221 Path string
222 Line int
223 Side domain.DiffSide
224 Text string
225}
226
227// MergeParams describes the merge to perform.
228type MergeParams struct {
229 // Mode defaults to fast-forward.
230 Mode domain.MergeMode
231 // HeadID is the commit the caller reviewed; the source branch must still
232 // point to it.
233 HeadID domain.ObjectID
234 // DeleteSource deletes the source branch after the merge.
235 DeleteSource bool
236}
237
238// MergeResult is a merged request and what happened to its source branch.
239type MergeResult struct {
240 domain.MergeRequest
241 // SourceDeleted is true when DeleteSource was asked and the branch is
242 // gone.
243 SourceDeleted bool
244}
245
246// LoginLink is a login link as the owner receives it.
247type LoginLink struct {
248 // URL holds the secret: show it once, never log it.
249 URL string
250 ExpiresAt time.Time
251}