Help us shape the future of Go! Take the 2026 Go Developer Survey

issues

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

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

func AssignMilestone(ctx context.Context, deps Deps, actorUserID, issueID, milestoneID int64) error

AssignMilestone sets an issue's milestone (or clears with milestoneID==0) and emits a `milestoned`/`demilestoned` event.

func AssignUser

func AssignUser(ctx context.Context, deps Deps, actorUserID, issueID, userID int64) error

AssignUser adds an assignee + emits an `assigned` event.

func Create

func Create(ctx context.Context, deps Deps, p CreateParams) (issuesdb.Issue, error)

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

func CreateLabel(ctx context.Context, deps Deps, p LabelCreateParams) (issuesdb.Label, error)

CreateLabel validates and inserts a label. Color must be 6 hex chars.

func CreateMilestone

func CreateMilestone(ctx context.Context, deps Deps, p MilestoneCreateParams) (issuesdb.Milestone, error)

func DeleteLabel

func DeleteLabel(ctx context.Context, deps Deps, id int64) error

DeleteLabel removes a label.

func DeleteMilestone

func DeleteMilestone(ctx context.Context, deps Deps, id int64) error

func SeedDefaultLabels

func SeedDefaultLabels(ctx context.Context, db issuesdb.DBTX, repoID int64) error

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 SetMilestoneState(ctx context.Context, deps Deps, id int64, state string) error

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

func UnassignUser(ctx context.Context, deps Deps, actorUserID, issueID, userID int64) error

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

type LabelCreateParams struct {
	RepoID      int64
	Name        string
	Color       string
	Description string
}

LabelCreateParams is input for CreateLabel.

type LabelSeed

type LabelSeed struct{ Name, Color, Description string }

type LabelUpdateParams

type LabelUpdateParams struct {
	ID          int64
	Name        string
	Color       string
	Description string
}

LabelUpdateParams is input for UpdateLabel.

type MilestoneCreateParams

type MilestoneCreateParams struct {
	RepoID      int64
	Title       string
	Description string
	DueOn       *time.Time
}

MilestoneCreateParams is input for CreateMilestone.

type MilestoneUpdateParams

type MilestoneUpdateParams struct {
	ID          int64
	Title       string
	Description string
	DueOn       *time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL