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.

pullrequest.go 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  37. func (p *PullRequest) GetLocalIndex() int64 { return p.Number }
  38. func (p *PullRequest) GetForeignIndex() int64 { return p.ForeignIndex }
  39. func (p *PullRequest) GetContext() DownloaderContext { return p.Context }
  40. // IsForkPullRequest returns true if the pull request from a forked repository but not the same repository
  41. func (p *PullRequest) IsForkPullRequest() bool {
  42. return p.Head.RepoPath() != p.Base.RepoPath()
  43. }
  44. // GetGitRefName returns pull request relative path to head
  45. func (p PullRequest) GetGitRefName() string {
  46. return fmt.Sprintf("%s%d/head", git.PullPrefix, p.Number)
  47. }
  48. // PullRequestBranch represents a pull request branch
  49. type PullRequestBranch struct {
  50. CloneURL string `yaml:"clone_url"` // SECURITY: This must be safe to download from
  51. Ref string // SECURITY: this must be a git.IsValidRefPattern
  52. SHA string // SECURITY: this must be a git.IsValidSHAPattern
  53. RepoName string `yaml:"repo_name"`
  54. OwnerName string `yaml:"owner_name"`
  55. }
  56. // RepoPath returns pull request repo path
  57. func (p PullRequestBranch) RepoPath() string {
  58. return fmt.Sprintf("%s/%s", p.OwnerName, p.RepoName)
  59. }
  60. // GetExternalName ExternalUserMigrated interface
  61. func (p *PullRequest) GetExternalName() string { return p.PosterName }
  62. // ExternalID ExternalUserMigrated interface
  63. func (p *PullRequest) GetExternalID() int64 { return p.PosterID }