Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

issue.go 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "io"
  10. "io/ioutil"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/Unknwon/com"
  15. "github.com/Unknwon/paginater"
  16. "code.gitea.io/git"
  17. "code.gitea.io/gitea/models"
  18. "code.gitea.io/gitea/modules/auth"
  19. "code.gitea.io/gitea/modules/base"
  20. "code.gitea.io/gitea/modules/context"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/markdown"
  23. "code.gitea.io/gitea/modules/notification"
  24. "code.gitea.io/gitea/modules/setting"
  25. "code.gitea.io/gitea/modules/util"
  26. )
  27. const (
  28. tplIssues base.TplName = "repo/issue/list"
  29. tplIssueNew base.TplName = "repo/issue/new"
  30. tplIssueView base.TplName = "repo/issue/view"
  31. tplMilestone base.TplName = "repo/issue/milestones"
  32. tplMilestoneNew base.TplName = "repo/issue/milestone_new"
  33. tplMilestoneEdit base.TplName = "repo/issue/milestone_edit"
  34. issueTemplateKey = "IssueTemplate"
  35. )
  36. var (
  37. // ErrFileTypeForbidden not allowed file type error
  38. ErrFileTypeForbidden = errors.New("File type is not allowed")
  39. // ErrTooManyFiles upload too many files
  40. ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded")
  41. // IssueTemplateCandidates issue templates
  42. IssueTemplateCandidates = []string{
  43. "ISSUE_TEMPLATE.md",
  44. "issue_template.md",
  45. ".gitea/ISSUE_TEMPLATE.md",
  46. ".gitea/issue_template.md",
  47. ".github/ISSUE_TEMPLATE.md",
  48. ".github/issue_template.md",
  49. }
  50. )
  51. // MustEnableIssues check if repository enable internal issues
  52. func MustEnableIssues(ctx *context.Context) {
  53. if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) &&
  54. !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) {
  55. ctx.Handle(404, "MustEnableIssues", nil)
  56. return
  57. }
  58. unit, err := ctx.Repo.Repository.GetUnit(models.UnitTypeExternalTracker)
  59. if err == nil {
  60. ctx.Redirect(unit.ExternalTrackerConfig().ExternalTrackerURL)
  61. return
  62. }
  63. }
  64. // MustAllowPulls check if repository enable pull requests
  65. func MustAllowPulls(ctx *context.Context) {
  66. if !ctx.Repo.Repository.AllowsPulls() {
  67. ctx.Handle(404, "MustAllowPulls", nil)
  68. return
  69. }
  70. // User can send pull request if owns a forked repository.
  71. if ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) {
  72. ctx.Repo.PullRequest.Allowed = true
  73. ctx.Repo.PullRequest.HeadInfo = ctx.User.Name + ":" + ctx.Repo.BranchName
  74. }
  75. }
  76. // Issues render issues page
  77. func Issues(ctx *context.Context) {
  78. isPullList := ctx.Params(":type") == "pulls"
  79. if isPullList {
  80. MustAllowPulls(ctx)
  81. if ctx.Written() {
  82. return
  83. }
  84. ctx.Data["Title"] = ctx.Tr("repo.pulls")
  85. ctx.Data["PageIsPullList"] = true
  86. } else {
  87. MustEnableIssues(ctx)
  88. if ctx.Written() {
  89. return
  90. }
  91. ctx.Data["Title"] = ctx.Tr("repo.issues")
  92. ctx.Data["PageIsIssueList"] = true
  93. }
  94. viewType := ctx.Query("type")
  95. sortType := ctx.Query("sort")
  96. types := []string{"all", "assigned", "created_by", "mentioned"}
  97. if !com.IsSliceContainsStr(types, viewType) {
  98. viewType = "all"
  99. }
  100. var (
  101. assigneeID = ctx.QueryInt64("assignee")
  102. posterID int64
  103. mentionedID int64
  104. forceEmpty bool
  105. )
  106. if ctx.IsSigned {
  107. switch viewType {
  108. case "created_by":
  109. posterID = ctx.User.ID
  110. case "mentioned":
  111. mentionedID = ctx.User.ID
  112. }
  113. }
  114. repo := ctx.Repo.Repository
  115. selectLabels := ctx.Query("labels")
  116. milestoneID := ctx.QueryInt64("milestone")
  117. isShowClosed := ctx.Query("state") == "closed"
  118. keyword := strings.Trim(ctx.Query("q"), " ")
  119. if bytes.Contains([]byte(keyword), []byte{0x00}) {
  120. keyword = ""
  121. }
  122. var issueIDs []int64
  123. var err error
  124. if len(keyword) > 0 {
  125. issueIDs, err = models.SearchIssuesByKeyword(repo.ID, keyword)
  126. if len(issueIDs) == 0 {
  127. forceEmpty = true
  128. }
  129. }
  130. var issueStats *models.IssueStats
  131. if forceEmpty {
  132. issueStats = &models.IssueStats{}
  133. } else {
  134. var err error
  135. issueStats, err = models.GetIssueStats(&models.IssueStatsOptions{
  136. RepoID: repo.ID,
  137. Labels: selectLabels,
  138. MilestoneID: milestoneID,
  139. AssigneeID: assigneeID,
  140. MentionedID: mentionedID,
  141. PosterID: posterID,
  142. IsPull: isPullList,
  143. IssueIDs: issueIDs,
  144. })
  145. if err != nil {
  146. ctx.Handle(500, "GetIssueStats", err)
  147. return
  148. }
  149. }
  150. page := ctx.QueryInt("page")
  151. if page <= 1 {
  152. page = 1
  153. }
  154. var total int
  155. if !isShowClosed {
  156. total = int(issueStats.OpenCount)
  157. } else {
  158. total = int(issueStats.ClosedCount)
  159. }
  160. pager := paginater.New(total, setting.UI.IssuePagingNum, page, 5)
  161. ctx.Data["Page"] = pager
  162. var issues []*models.Issue
  163. if forceEmpty {
  164. issues = []*models.Issue{}
  165. } else {
  166. issues, err = models.Issues(&models.IssuesOptions{
  167. AssigneeID: assigneeID,
  168. RepoID: repo.ID,
  169. PosterID: posterID,
  170. MentionedID: mentionedID,
  171. MilestoneID: milestoneID,
  172. Page: pager.Current(),
  173. PageSize: setting.UI.IssuePagingNum,
  174. IsClosed: util.OptionalBoolOf(isShowClosed),
  175. IsPull: util.OptionalBoolOf(isPullList),
  176. Labels: selectLabels,
  177. SortType: sortType,
  178. IssueIDs: issueIDs,
  179. })
  180. if err != nil {
  181. ctx.Handle(500, "Issues", err)
  182. return
  183. }
  184. }
  185. // Get posters.
  186. for i := range issues {
  187. // Check read status
  188. if !ctx.IsSigned {
  189. issues[i].IsRead = true
  190. } else if err = issues[i].GetIsRead(ctx.User.ID); err != nil {
  191. ctx.Handle(500, "GetIsRead", err)
  192. return
  193. }
  194. }
  195. ctx.Data["Issues"] = issues
  196. // Get milestones.
  197. ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID)
  198. if err != nil {
  199. ctx.Handle(500, "GetAllRepoMilestones", err)
  200. return
  201. }
  202. // Get assignees.
  203. ctx.Data["Assignees"], err = repo.GetAssignees()
  204. if err != nil {
  205. ctx.Handle(500, "GetAssignees", err)
  206. return
  207. }
  208. if ctx.QueryInt64("assignee") == 0 {
  209. assigneeID = 0 // Reset ID to prevent unexpected selection of assignee.
  210. }
  211. ctx.Data["IssueStats"] = issueStats
  212. ctx.Data["SelectLabels"] = com.StrTo(selectLabels).MustInt64()
  213. ctx.Data["ViewType"] = viewType
  214. ctx.Data["SortType"] = sortType
  215. ctx.Data["MilestoneID"] = milestoneID
  216. ctx.Data["AssigneeID"] = assigneeID
  217. ctx.Data["IsShowClosed"] = isShowClosed
  218. ctx.Data["Keyword"] = keyword
  219. if isShowClosed {
  220. ctx.Data["State"] = "closed"
  221. } else {
  222. ctx.Data["State"] = "open"
  223. }
  224. ctx.HTML(200, tplIssues)
  225. }
  226. // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
  227. func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
  228. var err error
  229. ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "")
  230. if err != nil {
  231. ctx.Handle(500, "GetMilestones", err)
  232. return
  233. }
  234. ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "")
  235. if err != nil {
  236. ctx.Handle(500, "GetMilestones", err)
  237. return
  238. }
  239. ctx.Data["Assignees"], err = repo.GetAssignees()
  240. if err != nil {
  241. ctx.Handle(500, "GetAssignees", err)
  242. return
  243. }
  244. }
  245. // RetrieveRepoMetas find all the meta information of a repository
  246. func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.Label {
  247. if !ctx.Repo.IsWriter() {
  248. return nil
  249. }
  250. labels, err := models.GetLabelsByRepoID(repo.ID, "")
  251. if err != nil {
  252. ctx.Handle(500, "GetLabelsByRepoID", err)
  253. return nil
  254. }
  255. ctx.Data["Labels"] = labels
  256. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  257. if ctx.Written() {
  258. return nil
  259. }
  260. brs, err := ctx.Repo.GitRepo.GetBranches()
  261. if err != nil {
  262. ctx.Handle(500, "GetBranches", err)
  263. return nil
  264. }
  265. ctx.Data["Branches"] = brs
  266. return labels
  267. }
  268. func getFileContentFromDefaultBranch(ctx *context.Context, filename string) (string, bool) {
  269. var r io.Reader
  270. var bytes []byte
  271. if ctx.Repo.Commit == nil {
  272. var err error
  273. ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
  274. if err != nil {
  275. return "", false
  276. }
  277. }
  278. entry, err := ctx.Repo.Commit.GetTreeEntryByPath(filename)
  279. if err != nil {
  280. return "", false
  281. }
  282. r, err = entry.Blob().Data()
  283. if err != nil {
  284. return "", false
  285. }
  286. bytes, err = ioutil.ReadAll(r)
  287. if err != nil {
  288. return "", false
  289. }
  290. return string(bytes), true
  291. }
  292. func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles []string) {
  293. for _, filename := range possibleFiles {
  294. content, found := getFileContentFromDefaultBranch(ctx, filename)
  295. if found {
  296. ctx.Data[ctxDataKey] = content
  297. return
  298. }
  299. }
  300. }
  301. // NewIssue render createing issue page
  302. func NewIssue(ctx *context.Context) {
  303. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  304. ctx.Data["PageIsIssueList"] = true
  305. ctx.Data["RequireHighlightJS"] = true
  306. ctx.Data["RequireSimpleMDE"] = true
  307. setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
  308. renderAttachmentSettings(ctx)
  309. RetrieveRepoMetas(ctx, ctx.Repo.Repository)
  310. if ctx.Written() {
  311. return
  312. }
  313. ctx.HTML(200, tplIssueNew)
  314. }
  315. // ValidateRepoMetas check and returns repository's meta informations
  316. func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64, int64, int64) {
  317. var (
  318. repo = ctx.Repo.Repository
  319. err error
  320. )
  321. labels := RetrieveRepoMetas(ctx, ctx.Repo.Repository)
  322. if ctx.Written() {
  323. return nil, 0, 0
  324. }
  325. if !ctx.Repo.IsWriter() {
  326. return nil, 0, 0
  327. }
  328. var labelIDs []int64
  329. hasSelected := false
  330. // Check labels.
  331. if len(form.LabelIDs) > 0 {
  332. labelIDs, err = base.StringsToInt64s(strings.Split(form.LabelIDs, ","))
  333. if err != nil {
  334. return nil, 0, 0
  335. }
  336. labelIDMark := base.Int64sToMap(labelIDs)
  337. for i := range labels {
  338. if labelIDMark[labels[i].ID] {
  339. labels[i].IsChecked = true
  340. hasSelected = true
  341. }
  342. }
  343. }
  344. ctx.Data["Labels"] = labels
  345. ctx.Data["HasSelectedLabel"] = hasSelected
  346. ctx.Data["label_ids"] = form.LabelIDs
  347. // Check milestone.
  348. milestoneID := form.MilestoneID
  349. if milestoneID > 0 {
  350. ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID)
  351. if err != nil {
  352. ctx.Handle(500, "GetMilestoneByID", err)
  353. return nil, 0, 0
  354. }
  355. ctx.Data["milestone_id"] = milestoneID
  356. }
  357. // Check assignee.
  358. assigneeID := form.AssigneeID
  359. if assigneeID > 0 {
  360. ctx.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID)
  361. if err != nil {
  362. ctx.Handle(500, "GetAssigneeByID", err)
  363. return nil, 0, 0
  364. }
  365. ctx.Data["assignee_id"] = assigneeID
  366. }
  367. return labelIDs, milestoneID, assigneeID
  368. }
  369. // NewIssuePost response for creating new issue
  370. func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
  371. ctx.Data["Title"] = ctx.Tr("repo.issues.new")
  372. ctx.Data["PageIsIssueList"] = true
  373. ctx.Data["RequireHighlightJS"] = true
  374. ctx.Data["RequireSimpleMDE"] = true
  375. ctx.Data["ReadOnly"] = false
  376. renderAttachmentSettings(ctx)
  377. var (
  378. repo = ctx.Repo.Repository
  379. attachments []string
  380. )
  381. labelIDs, milestoneID, assigneeID := ValidateRepoMetas(ctx, form)
  382. if ctx.Written() {
  383. return
  384. }
  385. if setting.AttachmentEnabled {
  386. attachments = form.Files
  387. }
  388. if ctx.HasError() {
  389. ctx.HTML(200, tplIssueNew)
  390. return
  391. }
  392. issue := &models.Issue{
  393. RepoID: repo.ID,
  394. Title: form.Title,
  395. PosterID: ctx.User.ID,
  396. Poster: ctx.User,
  397. MilestoneID: milestoneID,
  398. AssigneeID: assigneeID,
  399. Content: form.Content,
  400. Ref: form.Ref,
  401. }
  402. if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil {
  403. ctx.Handle(500, "NewIssue", err)
  404. return
  405. }
  406. notification.Service.NotifyIssue(issue, ctx.User.ID)
  407. log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
  408. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  409. }
  410. // ViewIssue render issue view page
  411. func ViewIssue(ctx *context.Context) {
  412. ctx.Data["RequireHighlightJS"] = true
  413. ctx.Data["RequireDropzone"] = true
  414. renderAttachmentSettings(ctx)
  415. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  416. if err != nil {
  417. if models.IsErrIssueNotExist(err) {
  418. ctx.Handle(404, "GetIssueByIndex", err)
  419. } else {
  420. ctx.Handle(500, "GetIssueByIndex", err)
  421. }
  422. return
  423. }
  424. ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
  425. var iw *models.IssueWatch
  426. var exists bool
  427. if ctx.User != nil {
  428. iw, exists, err = models.GetIssueWatch(ctx.User.ID, issue.ID)
  429. if err != nil {
  430. ctx.Handle(500, "GetIssueWatch", err)
  431. return
  432. }
  433. if !exists {
  434. iw = &models.IssueWatch{
  435. UserID: ctx.User.ID,
  436. IssueID: issue.ID,
  437. IsWatching: models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID),
  438. }
  439. }
  440. }
  441. ctx.Data["IssueWatch"] = iw
  442. // Make sure type and URL matches.
  443. if ctx.Params(":type") == "issues" && issue.IsPull {
  444. ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
  445. return
  446. } else if ctx.Params(":type") == "pulls" && !issue.IsPull {
  447. ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
  448. return
  449. }
  450. if issue.IsPull {
  451. MustAllowPulls(ctx)
  452. if ctx.Written() {
  453. return
  454. }
  455. ctx.Data["PageIsPullList"] = true
  456. ctx.Data["PageIsPullConversation"] = true
  457. } else {
  458. MustEnableIssues(ctx)
  459. if ctx.Written() {
  460. return
  461. }
  462. ctx.Data["PageIsIssueList"] = true
  463. }
  464. issue.RenderedContent = string(markdown.Render([]byte(issue.Content), ctx.Repo.RepoLink,
  465. ctx.Repo.Repository.ComposeMetas()))
  466. repo := ctx.Repo.Repository
  467. // Get more information if it's a pull request.
  468. if issue.IsPull {
  469. if issue.PullRequest.HasMerged {
  470. ctx.Data["DisableStatusChange"] = issue.PullRequest.HasMerged
  471. PrepareMergedViewPullInfo(ctx, issue)
  472. } else {
  473. PrepareViewPullInfo(ctx, issue)
  474. }
  475. if ctx.Written() {
  476. return
  477. }
  478. }
  479. // Metas.
  480. // Check labels.
  481. labelIDMark := make(map[int64]bool)
  482. for i := range issue.Labels {
  483. labelIDMark[issue.Labels[i].ID] = true
  484. }
  485. labels, err := models.GetLabelsByRepoID(repo.ID, "")
  486. if err != nil {
  487. ctx.Handle(500, "GetLabelsByRepoID", err)
  488. return
  489. }
  490. hasSelected := false
  491. for i := range labels {
  492. if labelIDMark[labels[i].ID] {
  493. labels[i].IsChecked = true
  494. hasSelected = true
  495. }
  496. }
  497. ctx.Data["HasSelectedLabel"] = hasSelected
  498. ctx.Data["Labels"] = labels
  499. // Check milestone and assignee.
  500. if ctx.Repo.IsWriter() {
  501. RetrieveRepoMilestonesAndAssignees(ctx, repo)
  502. if ctx.Written() {
  503. return
  504. }
  505. }
  506. if ctx.IsSigned {
  507. // Update issue-user.
  508. if err = issue.ReadBy(ctx.User.ID); err != nil {
  509. ctx.Handle(500, "ReadBy", err)
  510. return
  511. }
  512. }
  513. var (
  514. tag models.CommentTag
  515. ok bool
  516. marked = make(map[int64]models.CommentTag)
  517. comment *models.Comment
  518. participants = make([]*models.User, 1, 10)
  519. )
  520. if ctx.Repo.Repository.IsTimetrackerEnabled() {
  521. if ctx.IsSigned {
  522. // Deal with the stopwatch
  523. ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.User.ID, issue.ID)
  524. if !ctx.Data["IsStopwatchRunning"].(bool) {
  525. var exists bool
  526. var sw *models.Stopwatch
  527. if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil {
  528. ctx.Handle(500, "HasUserStopwatch", err)
  529. return
  530. }
  531. ctx.Data["HasUserStopwatch"] = exists
  532. if exists {
  533. // Add warning if the user has already a stopwatch
  534. var otherIssue *models.Issue
  535. if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil {
  536. ctx.Handle(500, "GetIssueByID", err)
  537. return
  538. }
  539. // Add link to the issue of the already running stopwatch
  540. ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
  541. }
  542. }
  543. ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.User)
  544. } else {
  545. ctx.Data["CanUseTimetracker"] = false
  546. }
  547. if ctx.Data["WorkingUsers"], err = models.TotalTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
  548. ctx.Handle(500, "TotalTimes", err)
  549. return
  550. }
  551. }
  552. // Render comments and and fetch participants.
  553. participants[0] = issue.Poster
  554. for _, comment = range issue.Comments {
  555. if comment.Type == models.CommentTypeComment {
  556. comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink,
  557. ctx.Repo.Repository.ComposeMetas()))
  558. // Check tag.
  559. tag, ok = marked[comment.PosterID]
  560. if ok {
  561. comment.ShowTag = tag
  562. continue
  563. }
  564. if repo.IsOwnedBy(comment.PosterID) ||
  565. (repo.Owner.IsOrganization() && repo.Owner.IsOwnedBy(comment.PosterID)) {
  566. comment.ShowTag = models.CommentTagOwner
  567. } else if comment.Poster.IsWriterOfRepo(repo) {
  568. comment.ShowTag = models.CommentTagWriter
  569. } else if comment.PosterID == issue.PosterID {
  570. comment.ShowTag = models.CommentTagPoster
  571. }
  572. marked[comment.PosterID] = comment.ShowTag
  573. isAdded := false
  574. for j := range participants {
  575. if comment.Poster == participants[j] {
  576. isAdded = true
  577. break
  578. }
  579. }
  580. if !isAdded && !issue.IsPoster(comment.Poster.ID) {
  581. participants = append(participants, comment.Poster)
  582. }
  583. } else if comment.Type == models.CommentTypeLabel {
  584. if err = comment.LoadLabel(); err != nil {
  585. ctx.Handle(500, "LoadLabel", err)
  586. return
  587. }
  588. } else if comment.Type == models.CommentTypeMilestone {
  589. if err = comment.LoadMilestone(); err != nil {
  590. ctx.Handle(500, "LoadMilestone", err)
  591. return
  592. }
  593. ghostMilestone := &models.Milestone{
  594. ID: -1,
  595. Name: ctx.Tr("repo.issues.deleted_milestone"),
  596. }
  597. if comment.OldMilestoneID > 0 && comment.OldMilestone == nil {
  598. comment.OldMilestone = ghostMilestone
  599. }
  600. if comment.MilestoneID > 0 && comment.Milestone == nil {
  601. comment.Milestone = ghostMilestone
  602. }
  603. } else if comment.Type == models.CommentTypeAssignees {
  604. if err = comment.LoadAssignees(); err != nil {
  605. ctx.Handle(500, "LoadAssignees", err)
  606. return
  607. }
  608. }
  609. }
  610. if issue.IsPull {
  611. pull := issue.PullRequest
  612. canDelete := false
  613. if ctx.IsSigned {
  614. if err := pull.GetHeadRepo(); err != nil {
  615. log.Error(4, "GetHeadRepo: %v", err)
  616. } else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch && ctx.User.IsWriterOfRepo(pull.HeadRepo) {
  617. // Check if branch is not protected
  618. if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch); err != nil {
  619. log.Error(4, "IsProtectedBranch: %v", err)
  620. } else if !protected {
  621. canDelete = true
  622. ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index) + "/cleanup"
  623. }
  624. }
  625. }
  626. ctx.Data["IsPullBranchDeletable"] = canDelete && pull.HeadRepo != nil && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)
  627. }
  628. ctx.Data["Participants"] = participants
  629. ctx.Data["NumParticipants"] = len(participants)
  630. ctx.Data["Issue"] = issue
  631. ctx.Data["ReadOnly"] = true
  632. ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))
  633. ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
  634. ctx.HTML(200, tplIssueView)
  635. }
  636. // GetActionIssue will return the issue which is used in the context.
  637. func GetActionIssue(ctx *context.Context) *models.Issue {
  638. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  639. if err != nil {
  640. if models.IsErrIssueNotExist(err) {
  641. ctx.Error(404, "GetIssueByIndex")
  642. } else {
  643. ctx.Handle(500, "GetIssueByIndex", err)
  644. }
  645. return nil
  646. }
  647. return issue
  648. }
  649. func getActionIssues(ctx *context.Context) []*models.Issue {
  650. commaSeparatedIssueIDs := ctx.Query("issue_ids")
  651. if len(commaSeparatedIssueIDs) == 0 {
  652. return nil
  653. }
  654. issueIDs := make([]int64, 0, 10)
  655. for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") {
  656. issueID, err := strconv.ParseInt(stringIssueID, 10, 64)
  657. if err != nil {
  658. ctx.Handle(500, "ParseInt", err)
  659. return nil
  660. }
  661. issueIDs = append(issueIDs, issueID)
  662. }
  663. issues, err := models.GetIssuesByIDs(issueIDs)
  664. if err != nil {
  665. ctx.Handle(500, "GetIssuesByIDs", err)
  666. return nil
  667. }
  668. return issues
  669. }
  670. // UpdateIssueTitle change issue's title
  671. func UpdateIssueTitle(ctx *context.Context) {
  672. issue := GetActionIssue(ctx)
  673. if ctx.Written() {
  674. return
  675. }
  676. if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter()) {
  677. ctx.Error(403)
  678. return
  679. }
  680. title := ctx.QueryTrim("title")
  681. if len(title) == 0 {
  682. ctx.Error(204)
  683. return
  684. }
  685. if err := issue.ChangeTitle(ctx.User, title); err != nil {
  686. ctx.Handle(500, "ChangeTitle", err)
  687. return
  688. }
  689. ctx.JSON(200, map[string]interface{}{
  690. "title": issue.Title,
  691. })
  692. }
  693. // UpdateIssueContent change issue's content
  694. func UpdateIssueContent(ctx *context.Context) {
  695. issue := GetActionIssue(ctx)
  696. if ctx.Written() {
  697. return
  698. }
  699. if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.IsWriter()) {
  700. ctx.Error(403)
  701. return
  702. }
  703. content := ctx.Query("content")
  704. if err := issue.ChangeContent(ctx.User, content); err != nil {
  705. ctx.Handle(500, "ChangeContent", err)
  706. return
  707. }
  708. ctx.JSON(200, map[string]interface{}{
  709. "content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  710. })
  711. }
  712. // UpdateIssueMilestone change issue's milestone
  713. func UpdateIssueMilestone(ctx *context.Context) {
  714. issues := getActionIssues(ctx)
  715. if ctx.Written() {
  716. return
  717. }
  718. milestoneID := ctx.QueryInt64("id")
  719. for _, issue := range issues {
  720. oldMilestoneID := issue.MilestoneID
  721. if oldMilestoneID == milestoneID {
  722. continue
  723. }
  724. issue.MilestoneID = milestoneID
  725. if err := models.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
  726. ctx.Handle(500, "ChangeMilestoneAssign", err)
  727. return
  728. }
  729. }
  730. ctx.JSON(200, map[string]interface{}{
  731. "ok": true,
  732. })
  733. }
  734. // UpdateIssueAssignee change issue's assignee
  735. func UpdateIssueAssignee(ctx *context.Context) {
  736. issues := getActionIssues(ctx)
  737. if ctx.Written() {
  738. return
  739. }
  740. assigneeID := ctx.QueryInt64("id")
  741. for _, issue := range issues {
  742. if issue.AssigneeID == assigneeID {
  743. continue
  744. }
  745. if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil {
  746. ctx.Handle(500, "ChangeAssignee", err)
  747. return
  748. }
  749. }
  750. ctx.JSON(200, map[string]interface{}{
  751. "ok": true,
  752. })
  753. }
  754. // UpdateIssueStatus change issue's status
  755. func UpdateIssueStatus(ctx *context.Context) {
  756. issues := getActionIssues(ctx)
  757. if ctx.Written() {
  758. return
  759. }
  760. var isClosed bool
  761. switch action := ctx.Query("action"); action {
  762. case "open":
  763. isClosed = false
  764. case "close":
  765. isClosed = true
  766. default:
  767. log.Warn("Unrecognized action: %s", action)
  768. }
  769. if _, err := models.IssueList(issues).LoadRepositories(); err != nil {
  770. ctx.Handle(500, "LoadRepositories", err)
  771. return
  772. }
  773. for _, issue := range issues {
  774. if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil {
  775. ctx.Handle(500, "ChangeStatus", err)
  776. return
  777. }
  778. }
  779. ctx.JSON(200, map[string]interface{}{
  780. "ok": true,
  781. })
  782. }
  783. // NewComment create a comment for issue
  784. func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
  785. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  786. if err != nil {
  787. ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
  788. return
  789. }
  790. var attachments []string
  791. if setting.AttachmentEnabled {
  792. attachments = form.Files
  793. }
  794. if ctx.HasError() {
  795. ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
  796. ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
  797. return
  798. }
  799. var comment *models.Comment
  800. defer func() {
  801. // Check if issue admin/poster changes the status of issue.
  802. if (ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))) &&
  803. (form.Status == "reopen" || form.Status == "close") &&
  804. !(issue.IsPull && issue.PullRequest.HasMerged) {
  805. // Duplication and conflict check should apply to reopen pull request.
  806. var pr *models.PullRequest
  807. if form.Status == "reopen" && issue.IsPull {
  808. pull := issue.PullRequest
  809. pr, err = models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
  810. if err != nil {
  811. if !models.IsErrPullRequestNotExist(err) {
  812. ctx.Handle(500, "GetUnmergedPullRequest", err)
  813. return
  814. }
  815. }
  816. // Regenerate patch and test conflict.
  817. if pr == nil {
  818. if err = issue.PullRequest.UpdatePatch(); err != nil {
  819. ctx.Handle(500, "UpdatePatch", err)
  820. return
  821. }
  822. issue.PullRequest.AddToTaskQueue()
  823. }
  824. }
  825. if pr != nil {
  826. ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
  827. } else {
  828. if err = issue.ChangeStatus(ctx.User, ctx.Repo.Repository, form.Status == "close"); err != nil {
  829. log.Error(4, "ChangeStatus: %v", err)
  830. } else {
  831. log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
  832. notification.Service.NotifyIssue(issue, ctx.User.ID)
  833. }
  834. }
  835. }
  836. // Redirect to comment hashtag if there is any actual content.
  837. typeName := "issues"
  838. if issue.IsPull {
  839. typeName = "pulls"
  840. }
  841. if comment != nil {
  842. ctx.Redirect(fmt.Sprintf("%s/%s/%d#%s", ctx.Repo.RepoLink, typeName, issue.Index, comment.HashTag()))
  843. } else {
  844. ctx.Redirect(fmt.Sprintf("%s/%s/%d", ctx.Repo.RepoLink, typeName, issue.Index))
  845. }
  846. }()
  847. // Fix #321: Allow empty comments, as long as we have attachments.
  848. if len(form.Content) == 0 && len(attachments) == 0 {
  849. return
  850. }
  851. comment, err = models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
  852. if err != nil {
  853. ctx.Handle(500, "CreateIssueComment", err)
  854. return
  855. }
  856. notification.Service.NotifyIssue(issue, ctx.User.ID)
  857. log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
  858. }
  859. // UpdateCommentContent change comment of issue's content
  860. func UpdateCommentContent(ctx *context.Context) {
  861. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  862. if err != nil {
  863. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  864. return
  865. }
  866. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
  867. ctx.Error(403)
  868. return
  869. } else if comment.Type != models.CommentTypeComment {
  870. ctx.Error(204)
  871. return
  872. }
  873. comment.Content = ctx.Query("content")
  874. if len(comment.Content) == 0 {
  875. ctx.JSON(200, map[string]interface{}{
  876. "content": "",
  877. })
  878. return
  879. }
  880. if err = models.UpdateComment(comment); err != nil {
  881. ctx.Handle(500, "UpdateComment", err)
  882. return
  883. }
  884. ctx.JSON(200, map[string]interface{}{
  885. "content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
  886. })
  887. }
  888. // DeleteComment delete comment of issue
  889. func DeleteComment(ctx *context.Context) {
  890. comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
  891. if err != nil {
  892. ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
  893. return
  894. }
  895. if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
  896. ctx.Error(403)
  897. return
  898. } else if comment.Type != models.CommentTypeComment {
  899. ctx.Error(204)
  900. return
  901. }
  902. if err = models.DeleteComment(comment); err != nil {
  903. ctx.Handle(500, "DeleteCommentByID", err)
  904. return
  905. }
  906. ctx.Status(200)
  907. }
  908. // Milestones render milestones page
  909. func Milestones(ctx *context.Context) {
  910. MustEnableIssues(ctx)
  911. if ctx.Written() {
  912. return
  913. }
  914. ctx.Data["Title"] = ctx.Tr("repo.milestones")
  915. ctx.Data["PageIsIssueList"] = true
  916. ctx.Data["PageIsMilestones"] = true
  917. isShowClosed := ctx.Query("state") == "closed"
  918. openCount, closedCount := models.MilestoneStats(ctx.Repo.Repository.ID)
  919. ctx.Data["OpenCount"] = openCount
  920. ctx.Data["ClosedCount"] = closedCount
  921. sortType := ctx.Query("sort")
  922. page := ctx.QueryInt("page")
  923. if page <= 1 {
  924. page = 1
  925. }
  926. var total int
  927. if !isShowClosed {
  928. total = int(openCount)
  929. } else {
  930. total = int(closedCount)
  931. }
  932. ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5)
  933. miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType)
  934. if err != nil {
  935. ctx.Handle(500, "GetMilestones", err)
  936. return
  937. }
  938. for _, m := range miles {
  939. m.RenderedContent = string(markdown.Render([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
  940. }
  941. ctx.Data["Milestones"] = miles
  942. if isShowClosed {
  943. ctx.Data["State"] = "closed"
  944. } else {
  945. ctx.Data["State"] = "open"
  946. }
  947. ctx.Data["SortType"] = sortType
  948. ctx.Data["IsShowClosed"] = isShowClosed
  949. ctx.HTML(200, tplMilestone)
  950. }
  951. // NewMilestone render creating milestone page
  952. func NewMilestone(ctx *context.Context) {
  953. ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
  954. ctx.Data["PageIsIssueList"] = true
  955. ctx.Data["PageIsMilestones"] = true
  956. ctx.Data["RequireDatetimepicker"] = true
  957. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  958. ctx.HTML(200, tplMilestoneNew)
  959. }
  960. // NewMilestonePost response for creating milestone
  961. func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
  962. ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
  963. ctx.Data["PageIsIssueList"] = true
  964. ctx.Data["PageIsMilestones"] = true
  965. ctx.Data["RequireDatetimepicker"] = true
  966. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  967. if ctx.HasError() {
  968. ctx.HTML(200, tplMilestoneNew)
  969. return
  970. }
  971. if len(form.Deadline) == 0 {
  972. form.Deadline = "9999-12-31"
  973. }
  974. deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
  975. if err != nil {
  976. ctx.Data["Err_Deadline"] = true
  977. ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
  978. return
  979. }
  980. if err = models.NewMilestone(&models.Milestone{
  981. RepoID: ctx.Repo.Repository.ID,
  982. Name: form.Title,
  983. Content: form.Content,
  984. Deadline: deadline,
  985. }); err != nil {
  986. ctx.Handle(500, "NewMilestone", err)
  987. return
  988. }
  989. ctx.Flash.Success(ctx.Tr("repo.milestones.create_success", form.Title))
  990. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  991. }
  992. // EditMilestone render edting milestone page
  993. func EditMilestone(ctx *context.Context) {
  994. ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
  995. ctx.Data["PageIsMilestones"] = true
  996. ctx.Data["PageIsEditMilestone"] = true
  997. ctx.Data["RequireDatetimepicker"] = true
  998. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  999. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1000. if err != nil {
  1001. if models.IsErrMilestoneNotExist(err) {
  1002. ctx.Handle(404, "", nil)
  1003. } else {
  1004. ctx.Handle(500, "GetMilestoneByRepoID", err)
  1005. }
  1006. return
  1007. }
  1008. ctx.Data["title"] = m.Name
  1009. ctx.Data["content"] = m.Content
  1010. if len(m.DeadlineString) > 0 {
  1011. ctx.Data["deadline"] = m.DeadlineString
  1012. }
  1013. ctx.HTML(200, tplMilestoneNew)
  1014. }
  1015. // EditMilestonePost response for edting milestone
  1016. func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
  1017. ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
  1018. ctx.Data["PageIsMilestones"] = true
  1019. ctx.Data["PageIsEditMilestone"] = true
  1020. ctx.Data["RequireDatetimepicker"] = true
  1021. ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
  1022. if ctx.HasError() {
  1023. ctx.HTML(200, tplMilestoneNew)
  1024. return
  1025. }
  1026. if len(form.Deadline) == 0 {
  1027. form.Deadline = "9999-12-31"
  1028. }
  1029. deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
  1030. if err != nil {
  1031. ctx.Data["Err_Deadline"] = true
  1032. ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
  1033. return
  1034. }
  1035. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1036. if err != nil {
  1037. if models.IsErrMilestoneNotExist(err) {
  1038. ctx.Handle(404, "", nil)
  1039. } else {
  1040. ctx.Handle(500, "GetMilestoneByRepoID", err)
  1041. }
  1042. return
  1043. }
  1044. m.Name = form.Title
  1045. m.Content = form.Content
  1046. m.Deadline = deadline
  1047. if err = models.UpdateMilestone(m); err != nil {
  1048. ctx.Handle(500, "UpdateMilestone", err)
  1049. return
  1050. }
  1051. ctx.Flash.Success(ctx.Tr("repo.milestones.edit_success", m.Name))
  1052. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  1053. }
  1054. // ChangeMilestonStatus response for change a milestone's status
  1055. func ChangeMilestonStatus(ctx *context.Context) {
  1056. m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  1057. if err != nil {
  1058. if models.IsErrMilestoneNotExist(err) {
  1059. ctx.Handle(404, "", err)
  1060. } else {
  1061. ctx.Handle(500, "GetMilestoneByRepoID", err)
  1062. }
  1063. return
  1064. }
  1065. switch ctx.Params(":action") {
  1066. case "open":
  1067. if m.IsClosed {
  1068. if err = models.ChangeMilestoneStatus(m, false); err != nil {
  1069. ctx.Handle(500, "ChangeMilestoneStatus", err)
  1070. return
  1071. }
  1072. }
  1073. ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=open")
  1074. case "close":
  1075. if !m.IsClosed {
  1076. m.ClosedDate = time.Now()
  1077. if err = models.ChangeMilestoneStatus(m, true); err != nil {
  1078. ctx.Handle(500, "ChangeMilestoneStatus", err)
  1079. return
  1080. }
  1081. }
  1082. ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=closed")
  1083. default:
  1084. ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
  1085. }
  1086. }
  1087. // DeleteMilestone delete a milestone
  1088. func DeleteMilestone(ctx *context.Context) {
  1089. if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
  1090. ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
  1091. } else {
  1092. ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
  1093. }
  1094. ctx.JSON(200, map[string]interface{}{
  1095. "redirect": ctx.Repo.RepoLink + "/milestones",
  1096. })
  1097. }