gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Copyright 2018 Jonas Franz. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package migration
  5. import (
  6. "fmt"
  7. "time"
  8. "code.gitea.io/gitea/modules/git"
  9. )
  10. // PullRequest defines a standard pull request information
  11. type PullRequest struct {
  12. Number int64
  13. Title string
  14. PosterName string `yaml:"poster_name"`
  15. PosterID int64 `yaml:"poster_id"`
  16. PosterEmail string `yaml:"poster_email"`
  17. Content string
  18. Milestone string
  19. State string
  20. Created time.Time
  21. Updated time.Time
  22. Closed *time.Time
  23. Labels []*Label
  24. PatchURL string `yaml:"patch_url"` // SECURITY: This must be safe to download directly from
  25. Merged bool
  26. MergedTime *time.Time `yaml:"merged_time"`
  27. MergeCommitSHA string `yaml:"merge_commit_sha"`
  28. Head PullRequestBranch
  29. Base PullRequestBranch
  30. Assignees []string
  31. IsLocked bool `yaml:"is_locked"`
  32. Reactions []*Reaction
  33. ForeignIndex int64
  34. Context DownloaderContext `yaml:"-"`
  35. EnsuredSafe bool `yaml:"ensured_safe"`
  36. IsDraft bool `yaml:"is_draft"`
  37. }
  38. func (p *PullRequest) GetLocalIndex() int64 { return p.Number }
  39. func (p *PullRequest) GetForeignIndex() int64 { return p.ForeignIndex }
  40. func (p *PullRequest) GetContext() DownloaderContext { return p.Context }
  41. // IsForkPullRequest returns true if the pull request from a forked repository but not the same repository
  42. func (p *PullRequest) IsForkPullRequest() bool {
  43. return p.Head.RepoFullName() != p.Base.RepoFullName()
  44. }
  45. // GetGitHeadRefName returns pull request relative path to head
  46. func (p PullRequest) GetGitHeadRefName() string {
  47. return fmt.Sprintf("%s%d/head", git.PullPrefix, p.Number)
  48. }
  49. // PullRequestBranch represents a pull request branch
  50. type PullRequestBranch struct {
  51. CloneURL string `yaml:"clone_url"` // SECURITY: This must be safe to download from
  52. Ref string // SECURITY: this must be a git.IsValidRefPattern
  53. SHA string // SECURITY: this must be a git.IsValidSHAPattern
  54. RepoName string `yaml:"repo_name"`
  55. OwnerName string `yaml:"owner_name"`
  56. }
  57. // RepoFullName returns pull request repo full name
  58. func (p PullRequestBranch) RepoFullName() string {
  59. return fmt.Sprintf("%s/%s", p.OwnerName, p.RepoName)
  60. }
  61. // GetExternalName ExternalUserMigrated interface
  62. func (p *PullRequest) GetExternalName() string { return p.PosterName }
  63. // ExternalID ExternalUserMigrated interface
  64. func (p *PullRequest) GetExternalID() int64 { return p.PosterID }