You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue.go 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package structs
  4. import (
  5. "fmt"
  6. "path"
  7. "strings"
  8. "time"
  9. "gopkg.in/yaml.v3"
  10. )
  11. // StateType issue state type
  12. type StateType string
  13. const (
  14. // StateOpen pr is opend
  15. StateOpen StateType = "open"
  16. // StateClosed pr is closed
  17. StateClosed StateType = "closed"
  18. // StateAll is all
  19. StateAll StateType = "all"
  20. )
  21. // PullRequestMeta PR info if an issue is a PR
  22. type PullRequestMeta struct {
  23. HasMerged bool `json:"merged"`
  24. Merged *time.Time `json:"merged_at"`
  25. }
  26. // RepositoryMeta basic repository information
  27. type RepositoryMeta struct {
  28. ID int64 `json:"id"`
  29. Name string `json:"name"`
  30. Owner string `json:"owner"`
  31. FullName string `json:"full_name"`
  32. }
  33. // Issue represents an issue in a repository
  34. // swagger:model
  35. type Issue struct {
  36. ID int64 `json:"id"`
  37. URL string `json:"url"`
  38. HTMLURL string `json:"html_url"`
  39. Index int64 `json:"number"`
  40. Poster *User `json:"user"`
  41. OriginalAuthor string `json:"original_author"`
  42. OriginalAuthorID int64 `json:"original_author_id"`
  43. Title string `json:"title"`
  44. Body string `json:"body"`
  45. Ref string `json:"ref"`
  46. Attachments []*Attachment `json:"assets"`
  47. Labels []*Label `json:"labels"`
  48. Milestone *Milestone `json:"milestone"`
  49. // deprecated
  50. Assignee *User `json:"assignee"`
  51. Assignees []*User `json:"assignees"`
  52. // Whether the issue is open or closed
  53. //
  54. // type: string
  55. // enum: open,closed
  56. State StateType `json:"state"`
  57. IsLocked bool `json:"is_locked"`
  58. Comments int `json:"comments"`
  59. // swagger:strfmt date-time
  60. Created time.Time `json:"created_at"`
  61. // swagger:strfmt date-time
  62. Updated time.Time `json:"updated_at"`
  63. // swagger:strfmt date-time
  64. Closed *time.Time `json:"closed_at"`
  65. // swagger:strfmt date-time
  66. Deadline *time.Time `json:"due_date"`
  67. PullRequest *PullRequestMeta `json:"pull_request"`
  68. Repo *RepositoryMeta `json:"repository"`
  69. PinOrder int `json:"pin_order"`
  70. }
  71. // CreateIssueOption options to create one issue
  72. type CreateIssueOption struct {
  73. // required:true
  74. Title string `json:"title" binding:"Required"`
  75. Body string `json:"body"`
  76. Ref string `json:"ref"`
  77. // deprecated
  78. Assignee string `json:"assignee"`
  79. Assignees []string `json:"assignees"`
  80. // swagger:strfmt date-time
  81. Deadline *time.Time `json:"due_date"`
  82. // milestone id
  83. Milestone int64 `json:"milestone"`
  84. // list of label ids
  85. Labels []int64 `json:"labels"`
  86. Closed bool `json:"closed"`
  87. }
  88. // EditIssueOption options for editing an issue
  89. type EditIssueOption struct {
  90. Title string `json:"title"`
  91. Body *string `json:"body"`
  92. Ref *string `json:"ref"`
  93. // deprecated
  94. Assignee *string `json:"assignee"`
  95. Assignees []string `json:"assignees"`
  96. Milestone *int64 `json:"milestone"`
  97. State *string `json:"state"`
  98. // swagger:strfmt date-time
  99. Deadline *time.Time `json:"due_date"`
  100. RemoveDeadline *bool `json:"unset_due_date"`
  101. }
  102. // EditDeadlineOption options for creating a deadline
  103. type EditDeadlineOption struct {
  104. // required:true
  105. // swagger:strfmt date-time
  106. Deadline *time.Time `json:"due_date"`
  107. }
  108. // IssueDeadline represents an issue deadline
  109. // swagger:model
  110. type IssueDeadline struct {
  111. // swagger:strfmt date-time
  112. Deadline *time.Time `json:"due_date"`
  113. }
  114. // IssueFormFieldType defines issue form field type, can be "markdown", "textarea", "input", "dropdown" or "checkboxes"
  115. type IssueFormFieldType string
  116. const (
  117. IssueFormFieldTypeMarkdown IssueFormFieldType = "markdown"
  118. IssueFormFieldTypeTextarea IssueFormFieldType = "textarea"
  119. IssueFormFieldTypeInput IssueFormFieldType = "input"
  120. IssueFormFieldTypeDropdown IssueFormFieldType = "dropdown"
  121. IssueFormFieldTypeCheckboxes IssueFormFieldType = "checkboxes"
  122. )
  123. // IssueFormField represents a form field
  124. // swagger:model
  125. type IssueFormField struct {
  126. Type IssueFormFieldType `json:"type" yaml:"type"`
  127. ID string `json:"id" yaml:"id"`
  128. Attributes map[string]any `json:"attributes" yaml:"attributes"`
  129. Validations map[string]any `json:"validations" yaml:"validations"`
  130. }
  131. // IssueTemplate represents an issue template for a repository
  132. // swagger:model
  133. type IssueTemplate struct {
  134. Name string `json:"name" yaml:"name"`
  135. Title string `json:"title" yaml:"title"`
  136. About string `json:"about" yaml:"about"` // Using "description" in a template file is compatible
  137. Labels IssueTemplateLabels `json:"labels" yaml:"labels"`
  138. Ref string `json:"ref" yaml:"ref"`
  139. Content string `json:"content" yaml:"-"`
  140. Fields []*IssueFormField `json:"body" yaml:"body"`
  141. FileName string `json:"file_name" yaml:"-"`
  142. }
  143. type IssueTemplateLabels []string
  144. func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error {
  145. var labels []string
  146. if value.IsZero() {
  147. *l = labels
  148. return nil
  149. }
  150. switch value.Kind {
  151. case yaml.ScalarNode:
  152. str := ""
  153. err := value.Decode(&str)
  154. if err != nil {
  155. return err
  156. }
  157. for _, v := range strings.Split(str, ",") {
  158. if v = strings.TrimSpace(v); v == "" {
  159. continue
  160. }
  161. labels = append(labels, v)
  162. }
  163. *l = labels
  164. return nil
  165. case yaml.SequenceNode:
  166. if err := value.Decode(&labels); err != nil {
  167. return err
  168. }
  169. *l = labels
  170. return nil
  171. }
  172. return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateLabels", value.Line, value.ShortTag())
  173. }
  174. type IssueConfigContactLink struct {
  175. Name string `json:"name" yaml:"name"`
  176. URL string `json:"url" yaml:"url"`
  177. About string `json:"about" yaml:"about"`
  178. }
  179. type IssueConfig struct {
  180. BlankIssuesEnabled bool `json:"blank_issues_enabled" yaml:"blank_issues_enabled"`
  181. ContactLinks []IssueConfigContactLink `json:"contact_links" yaml:"contact_links"`
  182. }
  183. type IssueConfigValidation struct {
  184. Valid bool `json:"valid"`
  185. Message string `json:"message"`
  186. }
  187. // IssueTemplateType defines issue template type
  188. type IssueTemplateType string
  189. const (
  190. IssueTemplateTypeMarkdown IssueTemplateType = "md"
  191. IssueTemplateTypeYaml IssueTemplateType = "yaml"
  192. )
  193. // Type returns the type of IssueTemplate, can be "md", "yaml" or empty for known
  194. func (it IssueTemplate) Type() IssueTemplateType {
  195. if base := path.Base(it.FileName); base == "config.yaml" || base == "config.yml" {
  196. // ignore config.yaml which is a special configuration file
  197. return ""
  198. }
  199. if ext := path.Ext(it.FileName); ext == ".md" {
  200. return IssueTemplateTypeMarkdown
  201. } else if ext == ".yaml" || ext == ".yml" {
  202. return IssueTemplateTypeYaml
  203. }
  204. return ""
  205. }
  206. // IssueMeta basic issue information
  207. // swagger:model
  208. type IssueMeta struct {
  209. Index int64 `json:"index"`
  210. Owner string `json:"owner"`
  211. Name string `json:"repo"`
  212. }