2016-11-07 14:53:13 +01:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2016-11-07 14:53:13 +01:00
|
|
|
|
2019-05-11 18:21:34 +08:00
|
|
|
package structs
|
2016-11-07 14:53:13 +01:00
|
|
|
|
|
|
|
|
import (
|
2022-11-19 23:22:15 +08:00
|
|
|
"fmt"
|
2022-11-16 19:14:58 +08:00
|
|
|
"path"
|
2024-03-04 01:37:00 +01:00
|
|
|
"slices"
|
2022-11-19 23:22:15 +08:00
|
|
|
"strings"
|
2016-11-07 14:53:13 +01:00
|
|
|
"time"
|
2022-11-19 23:22:15 +08:00
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
2016-11-07 14:53:13 +01:00
|
|
|
)
|
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// StateType issue state type
|
2026-03-29 20:28:48 -04:00
|
|
|
//
|
|
|
|
|
// swagger:enum StateType
|
2016-11-07 14:53:13 +01:00
|
|
|
type StateType string
|
|
|
|
|
|
|
|
|
|
const (
|
2025-09-13 10:34:43 -04:00
|
|
|
// StateOpen pr is opened
|
2016-11-29 09:09:17 +01:00
|
|
|
StateOpen StateType = "open"
|
|
|
|
|
// StateClosed pr is closed
|
|
|
|
|
StateClosed StateType = "closed"
|
2016-11-07 14:53:13 +01:00
|
|
|
)
|
|
|
|
|
|
2026-03-29 20:28:48 -04:00
|
|
|
// StateAll is a query parameter filter value, not a valid object state.
|
|
|
|
|
const StateAll = "all"
|
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// PullRequestMeta PR info if an issue is a PR
|
2016-11-07 14:53:13 +01:00
|
|
|
type PullRequestMeta struct {
|
2024-02-04 23:37:45 +01:00
|
|
|
HasMerged bool `json:"merged"`
|
|
|
|
|
Merged *time.Time `json:"merged_at"`
|
|
|
|
|
IsWorkInProgress bool `json:"draft"`
|
2024-05-26 06:08:13 +02:00
|
|
|
HTMLURL string `json:"html_url"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-31 00:06:10 -05:00
|
|
|
// RepositoryMeta basic repository information
|
|
|
|
|
type RepositoryMeta struct {
|
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
2020-02-04 06:05:17 +01:00
|
|
|
Owner string `json:"owner"`
|
2019-10-31 00:06:10 -05:00
|
|
|
FullName string `json:"full_name"`
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-12 23:02:25 -08:00
|
|
|
// Issue represents an issue in a repository
|
|
|
|
|
// swagger:model
|
2016-11-07 14:53:13 +01:00
|
|
|
type Issue struct {
|
2022-12-09 07:35:56 +01:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
|
URL string `json:"url"`
|
|
|
|
|
HTMLURL string `json:"html_url"`
|
|
|
|
|
Index int64 `json:"number"`
|
|
|
|
|
Poster *User `json:"user"`
|
|
|
|
|
OriginalAuthor string `json:"original_author"`
|
|
|
|
|
OriginalAuthorID int64 `json:"original_author_id"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Body string `json:"body"`
|
|
|
|
|
Ref string `json:"ref"`
|
|
|
|
|
Attachments []*Attachment `json:"assets"`
|
|
|
|
|
Labels []*Label `json:"labels"`
|
|
|
|
|
Milestone *Milestone `json:"milestone"`
|
2020-12-15 18:38:10 +00:00
|
|
|
// deprecated
|
2026-03-29 20:28:48 -04:00
|
|
|
Assignee *User `json:"assignee"`
|
|
|
|
|
Assignees []*User `json:"assignees"`
|
|
|
|
|
State StateType `json:"state"`
|
|
|
|
|
IsLocked bool `json:"is_locked"`
|
|
|
|
|
Comments int `json:"comments"`
|
2017-11-12 23:02:25 -08:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 02:22:16 +01:00
|
|
|
Created time.Time `json:"created_at"`
|
2017-11-12 23:02:25 -08:00
|
|
|
// swagger:strfmt date-time
|
2018-03-06 02:22:16 +01:00
|
|
|
Updated time.Time `json:"updated_at"`
|
2018-05-01 21:05:28 +02:00
|
|
|
// swagger:strfmt date-time
|
|
|
|
|
Closed *time.Time `json:"closed_at"`
|
|
|
|
|
// swagger:strfmt date-time
|
|
|
|
|
Deadline *time.Time `json:"due_date"`
|
2016-11-07 14:53:13 +01:00
|
|
|
|
2025-09-16 10:02:03 +05:30
|
|
|
TimeEstimate int64 `json:"time_estimate"`
|
|
|
|
|
|
2016-11-07 14:53:13 +01:00
|
|
|
PullRequest *PullRequestMeta `json:"pull_request"`
|
2019-10-31 00:06:10 -05:00
|
|
|
Repo *RepositoryMeta `json:"repository"`
|
2023-05-25 15:17:19 +02:00
|
|
|
|
2026-03-31 01:28:45 +08:00
|
|
|
PinOrder int `json:"pin_order"`
|
|
|
|
|
// The version of the issue content for optimistic locking
|
2026-03-30 09:44:32 -04:00
|
|
|
ContentVersion int `json:"content_version"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-29 09:09:17 +01:00
|
|
|
// CreateIssueOption options to create one issue
|
2016-11-07 14:53:13 +01:00
|
|
|
type CreateIssueOption struct {
|
2017-11-12 23:02:25 -08:00
|
|
|
// required:true
|
2018-03-06 02:22:16 +01:00
|
|
|
Title string `json:"title" binding:"Required"`
|
|
|
|
|
Body string `json:"body"`
|
2020-12-15 18:38:10 +00:00
|
|
|
Ref string `json:"ref"`
|
|
|
|
|
// deprecated
|
2018-05-01 21:05:28 +02:00
|
|
|
Assignee string `json:"assignee"`
|
|
|
|
|
Assignees []string `json:"assignees"`
|
|
|
|
|
// swagger:strfmt date-time
|
|
|
|
|
Deadline *time.Time `json:"due_date"`
|
2017-11-12 23:02:25 -08:00
|
|
|
// milestone id
|
2018-03-06 02:22:16 +01:00
|
|
|
Milestone int64 `json:"milestone"`
|
2017-11-12 23:02:25 -08:00
|
|
|
// list of label ids
|
2018-03-06 02:22:16 +01:00
|
|
|
Labels []int64 `json:"labels"`
|
|
|
|
|
Closed bool `json:"closed"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
2017-11-12 23:02:25 -08:00
|
|
|
// EditIssueOption options for editing an issue
|
2016-11-07 14:53:13 +01:00
|
|
|
type EditIssueOption struct {
|
2020-12-15 18:38:10 +00:00
|
|
|
Title string `json:"title"`
|
|
|
|
|
Body *string `json:"body"`
|
|
|
|
|
Ref *string `json:"ref"`
|
|
|
|
|
// deprecated
|
2018-05-16 22:01:55 +08:00
|
|
|
Assignee *string `json:"assignee"`
|
|
|
|
|
Assignees []string `json:"assignees"`
|
|
|
|
|
Milestone *int64 `json:"milestone"`
|
|
|
|
|
State *string `json:"state"`
|
2018-05-01 21:05:28 +02:00
|
|
|
// swagger:strfmt date-time
|
2019-11-03 15:46:32 +01:00
|
|
|
Deadline *time.Time `json:"due_date"`
|
|
|
|
|
RemoveDeadline *bool `json:"unset_due_date"`
|
2026-03-31 01:28:45 +08:00
|
|
|
// The current version of the issue content to detect conflicts during editing
|
|
|
|
|
ContentVersion *int `json:"content_version"`
|
2016-11-07 14:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-16 22:01:55 +08:00
|
|
|
// EditDeadlineOption options for creating a deadline
|
|
|
|
|
type EditDeadlineOption struct {
|
|
|
|
|
// required:true
|
|
|
|
|
// swagger:strfmt date-time
|
|
|
|
|
Deadline *time.Time `json:"due_date"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IssueDeadline represents an issue deadline
|
|
|
|
|
// swagger:model
|
|
|
|
|
type IssueDeadline struct {
|
|
|
|
|
// swagger:strfmt date-time
|
|
|
|
|
Deadline *time.Time `json:"due_date"`
|
|
|
|
|
}
|
2020-09-11 09:48:39 -05:00
|
|
|
|
2022-09-02 15:58:49 +08:00
|
|
|
// IssueFormFieldType defines issue form field type, can be "markdown", "textarea", "input", "dropdown" or "checkboxes"
|
2026-03-29 20:28:48 -04:00
|
|
|
//
|
|
|
|
|
// swagger:enum IssueFormFieldType
|
2022-09-02 15:58:49 +08:00
|
|
|
type IssueFormFieldType string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
IssueFormFieldTypeMarkdown IssueFormFieldType = "markdown"
|
|
|
|
|
IssueFormFieldTypeTextarea IssueFormFieldType = "textarea"
|
|
|
|
|
IssueFormFieldTypeInput IssueFormFieldType = "input"
|
|
|
|
|
IssueFormFieldTypeDropdown IssueFormFieldType = "dropdown"
|
|
|
|
|
IssueFormFieldTypeCheckboxes IssueFormFieldType = "checkboxes"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// IssueFormField represents a form field
|
|
|
|
|
// swagger:model
|
|
|
|
|
type IssueFormField struct {
|
2024-03-04 01:37:00 +01:00
|
|
|
Type IssueFormFieldType `json:"type" yaml:"type"`
|
|
|
|
|
ID string `json:"id" yaml:"id"`
|
|
|
|
|
Attributes map[string]any `json:"attributes" yaml:"attributes"`
|
|
|
|
|
Validations map[string]any `json:"validations" yaml:"validations"`
|
|
|
|
|
Visible []IssueFormFieldVisible `json:"visible,omitempty"`
|
2022-09-02 15:58:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-04 01:37:00 +01:00
|
|
|
func (iff IssueFormField) VisibleOnForm() bool {
|
|
|
|
|
if len(iff.Visible) == 0 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return slices.Contains(iff.Visible, IssueFormFieldVisibleForm)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (iff IssueFormField) VisibleInContent() bool {
|
|
|
|
|
if len(iff.Visible) == 0 {
|
|
|
|
|
// we have our markdown exception
|
|
|
|
|
return iff.Type != IssueFormFieldTypeMarkdown
|
|
|
|
|
}
|
|
|
|
|
return slices.Contains(iff.Visible, IssueFormFieldVisibleContent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IssueFormFieldVisible defines issue form field visible
|
2026-03-29 20:28:48 -04:00
|
|
|
//
|
|
|
|
|
// swagger:enum IssueFormFieldVisible
|
2024-03-04 01:37:00 +01:00
|
|
|
type IssueFormFieldVisible string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
IssueFormFieldVisibleForm IssueFormFieldVisible = "form"
|
|
|
|
|
IssueFormFieldVisibleContent IssueFormFieldVisible = "content"
|
|
|
|
|
)
|
|
|
|
|
|
2020-09-11 09:48:39 -05:00
|
|
|
// IssueTemplate represents an issue template for a repository
|
|
|
|
|
// swagger:model
|
|
|
|
|
type IssueTemplate struct {
|
2024-08-12 16:00:40 +08:00
|
|
|
Name string `json:"name" yaml:"name"`
|
|
|
|
|
Title string `json:"title" yaml:"title"`
|
|
|
|
|
About string `json:"about" yaml:"about"` // Using "description" in a template file is compatible
|
|
|
|
|
Labels IssueTemplateStringSlice `json:"labels" yaml:"labels"`
|
|
|
|
|
Assignees IssueTemplateStringSlice `json:"assignees" yaml:"assignees"`
|
|
|
|
|
Ref string `json:"ref" yaml:"ref"`
|
|
|
|
|
Content string `json:"content" yaml:"-"`
|
|
|
|
|
Fields []*IssueFormField `json:"body" yaml:"body"`
|
|
|
|
|
FileName string `json:"file_name" yaml:"-"`
|
2022-11-19 23:22:15 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-12 16:00:40 +08:00
|
|
|
type IssueTemplateStringSlice []string
|
2022-11-19 23:22:15 +08:00
|
|
|
|
2024-08-12 16:00:40 +08:00
|
|
|
func (l *IssueTemplateStringSlice) UnmarshalYAML(value *yaml.Node) error {
|
2022-11-19 23:22:15 +08:00
|
|
|
var labels []string
|
|
|
|
|
if value.IsZero() {
|
|
|
|
|
*l = labels
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
switch value.Kind {
|
|
|
|
|
case yaml.ScalarNode:
|
|
|
|
|
str := ""
|
|
|
|
|
err := value.Decode(&str)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2025-06-18 03:48:09 +02:00
|
|
|
for v := range strings.SplitSeq(str, ",") {
|
2022-11-19 23:22:15 +08:00
|
|
|
if v = strings.TrimSpace(v); v == "" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
labels = append(labels, v)
|
|
|
|
|
}
|
|
|
|
|
*l = labels
|
|
|
|
|
return nil
|
|
|
|
|
case yaml.SequenceNode:
|
|
|
|
|
if err := value.Decode(&labels); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
*l = labels
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-08-12 16:00:40 +08:00
|
|
|
return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateStringSlice", value.Line, value.ShortTag())
|
2020-09-11 09:48:39 -05:00
|
|
|
}
|
|
|
|
|
|
2023-03-28 20:22:07 +02:00
|
|
|
type IssueConfigContactLink struct {
|
|
|
|
|
Name string `json:"name" yaml:"name"`
|
|
|
|
|
URL string `json:"url" yaml:"url"`
|
|
|
|
|
About string `json:"about" yaml:"about"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type IssueConfig struct {
|
|
|
|
|
BlankIssuesEnabled bool `json:"blank_issues_enabled" yaml:"blank_issues_enabled"`
|
|
|
|
|
ContactLinks []IssueConfigContactLink `json:"contact_links" yaml:"contact_links"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type IssueConfigValidation struct {
|
|
|
|
|
Valid bool `json:"valid"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 15:58:49 +08:00
|
|
|
// IssueTemplateType defines issue template type
|
|
|
|
|
type IssueTemplateType string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
IssueTemplateTypeMarkdown IssueTemplateType = "md"
|
|
|
|
|
IssueTemplateTypeYaml IssueTemplateType = "yaml"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Type returns the type of IssueTemplate, can be "md", "yaml" or empty for known
|
|
|
|
|
func (it IssueTemplate) Type() IssueTemplateType {
|
2022-11-16 19:14:58 +08:00
|
|
|
if base := path.Base(it.FileName); base == "config.yaml" || base == "config.yml" {
|
2022-09-02 15:58:49 +08:00
|
|
|
// ignore config.yaml which is a special configuration file
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2022-11-16 19:14:58 +08:00
|
|
|
if ext := path.Ext(it.FileName); ext == ".md" {
|
2022-09-02 15:58:49 +08:00
|
|
|
return IssueTemplateTypeMarkdown
|
|
|
|
|
} else if ext == ".yaml" || ext == ".yml" {
|
2022-10-31 23:10:33 +08:00
|
|
|
return IssueTemplateTypeYaml
|
2022-09-02 15:58:49 +08:00
|
|
|
}
|
2022-10-31 23:10:33 +08:00
|
|
|
return ""
|
2020-09-11 09:48:39 -05:00
|
|
|
}
|
2023-03-28 19:23:25 +02:00
|
|
|
|
|
|
|
|
// IssueMeta basic issue information
|
|
|
|
|
// swagger:model
|
|
|
|
|
type IssueMeta struct {
|
2025-07-23 08:44:34 +02:00
|
|
|
Index int64 `json:"index"`
|
|
|
|
|
// owner of the issue's repo
|
2023-03-28 19:23:25 +02:00
|
|
|
Owner string `json:"owner"`
|
|
|
|
|
Name string `json:"repo"`
|
|
|
|
|
}
|
2025-04-21 02:43:43 +02:00
|
|
|
|
|
|
|
|
// LockIssueOption options to lock an issue
|
|
|
|
|
type LockIssueOption struct {
|
|
|
|
|
Reason string `json:"lock_reason"`
|
|
|
|
|
}
|