issue.go RawHistoryFolder
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain
4
5import (
6 "fmt"
7 "time"
8)
9
10// IssuesMode says who may write issues in a repository.
11type IssuesMode string
12
13// Issues modes.
14const (
15 // IssuesOff turns issues off: the default.
16 IssuesOff IssuesMode = "off"
17 // IssuesOwner lets the owner and tokens with ScopeIssueWrite write issues.
18 IssuesOwner IssuesMode = "owner"
19 // IssuesPublic also opens the repository to submissions from anyone.
20 IssuesPublic IssuesMode = "public"
21)
22
23// IssuesModes returns the three modes in their canonical order.
24func IssuesModes() []IssuesMode { return []IssuesMode{IssuesOff, IssuesOwner, IssuesPublic} }
25
26// ParseIssuesMode parses "off", "owner" or "public".
27func ParseIssuesMode(s string) (IssuesMode, error) {
28 for _, m := range IssuesModes() {
29 if string(m) == s {
30 return m, nil
31 }
32 }
33 return "", fmt.Errorf("%w: issues mode %q (want off, owner or public)", ErrInvalid, s)
34}
35
36// String returns the mode as text.
37func (m IssuesMode) String() string { return string(m) }
38
39// OrDefault returns IssuesOff for the empty mode, else m.
40func (m IssuesMode) OrDefault() IssuesMode {
41 if m == "" {
42 return IssuesOff
43 }
44 return m
45}
46
47// IssueState is where an issue is in its life.
48type IssueState string
49
50// Issue states.
51const (
52 // IssueStateOpen is being worked on.
53 IssueStateOpen IssueState = "open"
54 // IssueStateClosed is done with; it can be reopened.
55 IssueStateClosed IssueState = "closed"
56)
57
58// Issue is a problem or a request about a repository. It shares its number
59// sequence with the merge requests of the repository.
60type Issue struct {
61 Repo RepoName
62 Number int64
63 Title IssueTitle
64 // Body may be empty.
65 Body IssueBody
66 State IssueState
67 // Author is the label of the token that opened it, "root" or "owner".
68 Author string
69 CreatedAt time.Time
70 UpdatedAt time.Time
71 // CommentSeq is the id of the last comment of the issue.
72 CommentSeq int64
73 // External is true for an issue approved from the public form: its text
74 // comes from an anonymous visitor and is rendered as untrusted.
75 External bool
76 // ClosedByMergeRequest is zero unless a merge closed the issue.
77 ClosedByMergeRequest int64
78 // Version is set by the store on read: Update fails with ErrConflict when
79 // the stored issue changed since. Opaque to everyone else.
80 Version uint64
81}
82
83// IssueLink is a merge request naming an issue in the same repository.
84type IssueLink struct {
85 Issue, MergeRequest int64
86 Closes bool
87}
88
89// IsOpen reports whether the issue is open.
90func (i Issue) IsOpen() bool { return i.State == IssueStateOpen }
91
92// IssueComment is a comment on an issue.
93type IssueComment struct {
94 ID int64
95 Author string
96 Text IssueBody
97 CreatedAt time.Time
98 // Version is set by the store on read, like Issue's.
99 Version uint64
100}
101
102// NumberKind says what a number of a repository names. Issues and merge
103// requests share one sequence, so a number names at most one of them.
104type NumberKind int
105
106// Number kinds.
107const (
108 // NumberNone: no issue or merge request has this number.
109 NumberNone NumberKind = iota
110 // NumberIssue: the number names an issue.
111 NumberIssue
112 // NumberMergeRequest: the number names a merge request.
113 NumberMergeRequest
114)