-
Notifications
You must be signed in to change notification settings - Fork 785
/
pullref.go
65 lines (55 loc) · 1.7 KB
/
pullref.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package metapipeline
import "fmt"
// PullRef defines all required information for checking out the source in the required state for the pipeline execution
type PullRef struct {
sourceURL string
baseBranch string
baseSHA string
pullRequests []PullRequestRef
}
// PullRequestRef defines a pull request which needs to be merged.
type PullRequestRef struct {
ID string
MergeSHA string
}
// NewPullRef creates a pull ref for a master/feature build with no pull requests.
func NewPullRef(sourceURL string, baseBranch string, baseSHA string) PullRef {
return PullRef{
sourceURL: sourceURL,
baseBranch: baseBranch,
baseSHA: baseSHA,
}
}
// NewPullRefWithPullRequest creates a pull ref for a pull request.
func NewPullRefWithPullRequest(sourceURL string, baseBranch string, baseSHA string, prRef ...PullRequestRef) PullRef {
return PullRef{
sourceURL: sourceURL,
baseBranch: baseBranch,
baseSHA: baseSHA,
pullRequests: prRef,
}
}
// SourceURL returns the source URL of this pull ref
func (p *PullRef) SourceURL() string {
return p.sourceURL
}
// BaseBranch returns the base branch of this pull ref.
func (p *PullRef) BaseBranch() string {
return p.baseBranch
}
// BaseSHA returns the base sha of this pull ref.
func (p *PullRef) BaseSHA() string {
return p.baseSHA
}
// PullRequests returns the pull request for this pull ref.
func (p *PullRef) PullRequests() []PullRequestRef {
return p.pullRequests
}
// String returns a string representation of this pull ref in Prow PullRef format.
func (p *PullRef) String() string {
s := fmt.Sprintf("%s:%s", p.baseBranch, p.baseSHA)
for _, pr := range p.pullRequests {
s = fmt.Sprintf("%s,%s:%s", s, pr.ID, pr.MergeSHA)
}
return s
}