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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Copyright 2018 Jonas Franz. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package migration
  6. import (
  7. "fmt"
  8. "time"
  9. "code.gitea.io/gitea/modules/git"
  10. )
  11. // PullRequest defines a standard pull request information
  12. type PullRequest struct {
  13. Number int64
  14. Title string
  15. PosterName string `yaml:"poster_name"`
  16. PosterID int64 `yaml:"poster_id"`
  17. PosterEmail string `yaml:"poster_email"`
  18. Content string
  19. Milestone string
  20. State string
  21. Created time.Time
  22. Updated time.Time
  23. Closed *time.Time
  24. Labels []*Label
  25. PatchURL string `yaml:"patch_url"`
  26. Merged bool
  27. MergedTime *time.Time `yaml:"merged_time"`
  28. MergeCommitSHA string `yaml:"merge_commit_sha"`
  29. Head PullRequestBranch
  30. Base PullRequestBranch
  31. Assignees []string
  32. IsLocked bool `yaml:"is_locked"`
  33. Reactions []*Reaction
  34. Context IssueContext `yaml:"-"`
  35. }
  36. // IsForkPullRequest returns true if the pull request from a forked repository but not the same repository
  37. func (p *PullRequest) IsForkPullRequest() bool {
  38. return p.Head.RepoPath() != p.Base.RepoPath()
  39. }
  40. // GetGitRefName returns pull request relative path to head
  41. func (p PullRequest) GetGitRefName() string {
  42. return fmt.Sprintf("%s%d/head", git.PullPrefix, p.Number)
  43. }
  44. // PullRequestBranch represents a pull request branch
  45. type PullRequestBranch struct {
  46. CloneURL string `yaml:"clone_url"`
  47. Ref string
  48. SHA string
  49. RepoName string `yaml:"repo_name"`
  50. OwnerName string `yaml:"owner_name"`
  51. }
  52. // RepoPath returns pull request repo path
  53. func (p PullRequestBranch) RepoPath() string {
  54. return fmt.Sprintf("%s/%s", p.OwnerName, p.RepoName)
  55. }