github.com/jenkins-x/jx/v2@v2.1.155/pkg/tekton/metapipeline/pullref.go (about)

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