Documentation
¶
Overview ¶
Package issues owns the issue + comment + label + milestone domain logic. Web handlers call into this package; the package owns transactions, cross-reference parsing, and event emission.
PR-specific behavior lives in the future internal/pulls/ package (S22) — but PRs reuse the `issues` and `issue_comments` tables, so the queries here are kind-discriminated to keep the surface clean.
Index ¶
- Variables
- func AddComment(ctx context.Context, deps Deps, p CommentCreateParams) (issuesdb.IssueComment, error)
- func ApplyLabels(ctx context.Context, deps Deps, actorUserID, issueID int64, labelIDs []int64) error
- func AssignMilestone(ctx context.Context, deps Deps, actorUserID, issueID, milestoneID int64) error
- func AssignUser(ctx context.Context, deps Deps, actorUserID, issueID, userID int64) error
- func Create(ctx context.Context, deps Deps, p CreateParams) (issuesdb.Issue, error)
- func CreateLabel(ctx context.Context, deps Deps, p LabelCreateParams) (issuesdb.Label, error)
- func CreateMilestone(ctx context.Context, deps Deps, p MilestoneCreateParams) (issuesdb.Milestone, error)
- func DeleteLabel(ctx context.Context, deps Deps, id int64) error
- func DeleteMilestone(ctx context.Context, deps Deps, id int64) error
- func SeedDefaultLabels(ctx context.Context, db issuesdb.DBTX, repoID int64) error
- func SetLock(ctx context.Context, deps Deps, actorUserID, issueID int64, locked bool, ...) error
- func SetMilestoneState(ctx context.Context, deps Deps, id int64, state string) error
- func SetState(ctx context.Context, deps Deps, actorUserID, issueID int64, ...) error
- func SetStateWithComment(ctx context.Context, deps Deps, actorUserID, issueID int64, ...) error
- func UnassignUser(ctx context.Context, deps Deps, actorUserID, issueID, userID int64) error
- func UpdateLabel(ctx context.Context, deps Deps, p LabelUpdateParams) error
- func UpdateMilestone(ctx context.Context, deps Deps, p MilestoneUpdateParams) error
- type CommentCreateParams
- type CreateParams
- type Deps
- type LabelCreateParams
- type LabelSeed
- type LabelUpdateParams
- type MilestoneCreateParams
- type MilestoneUpdateParams
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyTitle = errors.New("issues: title is required") ErrTitleTooLong = errors.New("issues: title too long (max 256)") ErrBodyTooLong = errors.New("issues: body too long") ErrEmptyComment = errors.New("issues: comment body is required") ErrCommentTooLong = errors.New("issues: comment too long") ErrIssueLocked = errors.New("issues: issue is locked") ErrCommentRateLimit = errors.New("issues: comment rate limit exceeded") ErrLabelExists = errors.New("issues: label name already taken on this repo") ErrLabelInvalidColor = errors.New("issues: label color must be 6 hex chars") ErrMilestoneExists = errors.New("issues: milestone title already taken on this repo") ErrIssueNotFound = errors.New("issues: issue not found") )
Errors returned by the orchestrator. Handlers map these to status codes + friendly user-facing messages.
var DefaultLabels = []LabelSeed{
{"bug", "d73a4a", "Something isn't working"},
{"documentation", "0075ca", "Improvements or additions to documentation"},
{"duplicate", "cfd3d7", "This issue or pull request already exists"},
{"enhancement", "a2eeef", "New feature or request"},
{"good first issue", "7057ff", "Good for newcomers"},
{"help wanted", "008672", "Extra attention is needed"},
{"invalid", "e4e669", "This doesn't seem right"},
{"question", "d876e3", "Further information is requested"},
{"wontfix", "ffffff", "This will not be worked on"},
}
DefaultLabels is the seeded set applied to every new repo. Names + colors are GitHub-aligned so users feel at home.
Functions ¶
func AddComment ¶
func AddComment(ctx context.Context, deps Deps, p CommentCreateParams) (issuesdb.IssueComment, error)
AddComment validates, applies the rate limit, inserts the comment, and indexes references. Returns the fresh comment.
func ApplyLabels ¶
func ApplyLabels(ctx context.Context, deps Deps, actorUserID, issueID int64, labelIDs []int64) error
ApplyLabels replaces the issue's label set with `labelIDs`. Emits a `labeled` / `unlabeled` event for each delta. Caller is the actor.
func AssignMilestone ¶
AssignMilestone sets an issue's milestone (or clears with milestoneID==0) and emits a `milestoned`/`demilestoned` event.
func AssignUser ¶
AssignUser adds an assignee + emits an `assigned` event.
func Create ¶
Create validates inputs, allocates a per-repo number atomically, inserts the row, renders the body's markdown, and returns the fresh issue. Default labels live with repo create; per-issue label/assignee/milestone application is a separate call.
Cross-reference indexing fires asynchronously inside the same tx via insertReferencesFromBody — refs to other issues create `issue_references` rows + a `referenced` event on the target.
func CreateLabel ¶
CreateLabel validates and inserts a label. Color must be 6 hex chars.
func CreateMilestone ¶
func DeleteLabel ¶
DeleteLabel removes a label.
func SeedDefaultLabels ¶
SeedDefaultLabels writes the DefaultLabels into the given repo on the supplied DBTX (typically the repo-create transaction). Existing rows are left alone — caller can re-run safely.
func SetLock ¶
func SetLock(ctx context.Context, deps Deps, actorUserID, issueID int64, locked bool, reason string) error
SetLock toggles the locked flag and emits an event.
func SetMilestoneState ¶
func SetState ¶
func SetState(ctx context.Context, deps Deps, actorUserID, issueID int64, newState, reason string) error
SetState closes or reopens an issue and emits an `closed` / `reopened` event.
func SetStateWithComment ¶
func SetStateWithComment(ctx context.Context, deps Deps, actorUserID, issueID int64, newState, reason string, commentID int64) error
SetStateWithComment is used by the issue comment form when the submit button both creates a comment and changes state. The timeline event stores the comment id so the UI can keep the state badge adjacent to the comment that caused it.
func UnassignUser ¶
UnassignUser removes an assignee + emits an `unassigned` event.
func UpdateLabel ¶
func UpdateLabel(ctx context.Context, deps Deps, p LabelUpdateParams) error
func UpdateMilestone ¶
func UpdateMilestone(ctx context.Context, deps Deps, p MilestoneUpdateParams) error
Types ¶
type CommentCreateParams ¶
type CommentCreateParams struct {
IssueID int64
AuthorUserID int64
Body string
// IsCollab signals that the actor's policy.Can role is at least
// triage. Used to bypass the locked-issue gate.
IsCollab bool
}
CommentCreateParams is the input for AddComment.
type CreateParams ¶
type CreateParams struct {
RepoID int64
AuthorUserID int64 // 0 means anonymous (unsupported in S21; handler enforces)
Title string
Body string
// Kind defaults to "issue"; PR creation in S22 passes "pr".
Kind string
}
CreateParams describes a new-issue request.
type Deps ¶
type Deps struct {
Pool *pgxpool.Pool
Limiter *throttle.Limiter
Logger *slog.Logger
// Audit is optional; when non-nil, state-changing orchestrator
// calls (SetState, SetLock, AddComment) record an audit row. The
// repo lifecycle package writes audit rows directly via deps.Audit;
// this field ensures issues/PR mutations are equally traceable
// (S00-S25 audit, M).
Audit *audit.Recorder
}
Deps wires this package against the rest of the runtime. Pool is required; Limiter governs the comment-create rate limit; Logger is optional (falls back to discarding when nil).
type LabelCreateParams ¶
LabelCreateParams is input for CreateLabel.
type LabelUpdateParams ¶
LabelUpdateParams is input for UpdateLabel.
type MilestoneCreateParams ¶
MilestoneCreateParams is input for CreateMilestone.