1
// Copyright 2019 The Gitea Authors. All rights reserved.
2
// Copyright 2018 Jonas Franz. All rights reserved.
3
// SPDX-License-Identifier: MIT
11
"code.gitea.io/gitea/modules/git"
14
// PullRequest defines a standard pull request information
15
type PullRequest struct {
18
PosterName string `yaml:"poster_name"`
19
PosterID int64 `yaml:"poster_id"`
20
PosterEmail string `yaml:"poster_email"`
28
PatchURL string `yaml:"patch_url"` // SECURITY: This must be safe to download directly from
30
MergedTime *time.Time `yaml:"merged_time"`
31
MergeCommitSHA string `yaml:"merge_commit_sha"`
32
Head PullRequestBranch
33
Base PullRequestBranch
35
IsLocked bool `yaml:"is_locked"`
38
Context DownloaderContext `yaml:"-"`
39
EnsuredSafe bool `yaml:"ensured_safe"`
42
func (p *PullRequest) GetLocalIndex() int64 { return p.Number }
43
func (p *PullRequest) GetForeignIndex() int64 { return p.ForeignIndex }
44
func (p *PullRequest) GetContext() DownloaderContext { return p.Context }
46
// IsForkPullRequest returns true if the pull request from a forked repository but not the same repository
47
func (p *PullRequest) IsForkPullRequest() bool {
48
return p.Head.RepoPath() != p.Base.RepoPath()
51
// GetGitRefName returns pull request relative path to head
52
func (p PullRequest) GetGitRefName() string {
53
return fmt.Sprintf("%s%d/head", git.PullPrefix, p.Number)
56
// PullRequestBranch represents a pull request branch
57
type PullRequestBranch struct {
58
CloneURL string `yaml:"clone_url"` // SECURITY: This must be safe to download from
59
Ref string // SECURITY: this must be a git.IsValidRefPattern
60
SHA string // SECURITY: this must be a git.IsValidSHAPattern
61
RepoName string `yaml:"repo_name"`
62
OwnerName string `yaml:"owner_name"`
65
// RepoPath returns pull request repo path
66
func (p PullRequestBranch) RepoPath() string {
67
return fmt.Sprintf("%s/%s", p.OwnerName, p.RepoName)
70
// GetExternalName ExternalUserMigrated interface
71
func (p *PullRequest) GetExternalName() string { return p.PosterName }
73
// ExternalID ExternalUserMigrated interface
74
func (p *PullRequest) GetExternalID() int64 { return p.PosterID }