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