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 66 67 68 69 70 71 72 73 74
|
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package f3
import (
"context"
"time"
)
type PullRequestFetchFunc func(ctx context.Context, url, ref string)
const (
PullRequestStateOpen = "open"
PullRequestStateClosed = "closed"
)
type PullRequest struct {
Common
PosterID *Reference `json:"poster_id"`
Title string `json:"title"`
Content string `json:"content"`
Attachments []*Attachment `json:"attachments"`
Milestone *Reference `json:"milestone"`
State string `json:"state"` // open, closed
IsLocked bool `json:"is_locked"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Closed *time.Time `json:"closed"`
Merged bool `json:"merged"`
MergedTime *time.Time `json:"merged_time"`
MergeCommitSHA string `json:"merged_commit_sha"`
Head PullRequestBranch `json:"head"`
Base PullRequestBranch `json:"base"`
FetchFunc PullRequestFetchFunc `json:"-"`
}
func (o PullRequest) Equal(other PullRequest) bool {
return o.Common.Equal(other.Common) &&
nilOrEqual(o.PosterID, other.PosterID) &&
o.Title == other.Title &&
o.Content == other.Content &&
arrayEqual(o.Attachments, other.Attachments) &&
nilOrEqual(o.Milestone, other.Milestone) &&
o.State == other.State &&
o.IsLocked == other.IsLocked &&
o.Merged == other.Merged &&
nilOrEqual(o.MergedTime, other.MergedTime) &&
o.MergeCommitSHA == other.MergeCommitSHA &&
o.Head.Equal(other.Head) &&
o.Base.Equal(other.Base)
}
func (o *PullRequest) GetReferences() References {
references := o.Common.GetReferences()
if !o.Milestone.IsNil() {
references = append(references, o.Milestone)
}
references = append(references, o.Base.GetReferences()...)
references = append(references, o.Head.GetReferences()...)
return append(references, o.PosterID)
}
func (o *PullRequest) IsForkPullRequest() bool {
return o.Head.Repository != o.Base.Repository
}
func (o *PullRequest) Clone() Interface {
clone := &PullRequest{}
*clone = *o
return clone
}
|