PullMerge: use enum for MergeStyle (#328)

Its already Breaking ... make struct look nice

Signed-off-by: 6543 <6543@obermui.de>

PullMerge: use enum for MergeStyle

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/328
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
This commit is contained in:
6543 2020-05-20 22:41:21 +00:00 committed by lafriks
parent 2cc36f912f
commit b4696d5416
2 changed files with 24 additions and 12 deletions

View file

@ -66,6 +66,20 @@ type ListPullRequestsOptions struct {
Milestone int64
}
// MergeStyle is used specify how a pull is merged
type MergeStyle string
const (
// MergeStyleMerge merge pull as usual
MergeStyleMerge MergeStyle = "merge"
// MergeStyleRebase rebase pull
MergeStyleRebase MergeStyle = "rebase"
// MergeStyleRebaseMerge rebase and merge pull
MergeStyleRebaseMerge MergeStyle = "rebase-merge"
// MergeStyleSquash squash and merge pull
MergeStyleSquash MergeStyle = "squash"
)
// QueryEncode turns options into querystring argument
func (opt *ListPullRequestsOptions) QueryEncode() string {
query := opt.getURLQuery()
@ -146,16 +160,14 @@ func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRe
// MergePullRequestOption options when merging a pull request
type MergePullRequestOption struct {
// required: true
// enum: merge,rebase,rebase-merge,squash
Do string `json:"Do" binding:"Required;In(merge,rebase,rebase-merge,squash)"`
MergeTitleField string `json:"MergeTitleField"`
MergeMessageField string `json:"MergeMessageField"`
Style MergeStyle `json:"Do"`
Title string `json:"MergeTitleField"`
Message string `json:"MergeMessageField"`
}
// MergePullRequest merge a PR to repository by PR id
func (c *Client) MergePullRequest(owner, repo string, index int64, opt MergePullRequestOption) (bool, error) {
if opt.Do == "squash" {
if opt.Style == MergeStyleSquash {
if err := c.CheckServerVersionConstraint(">=1.11.5"); err != nil {
return false, err
}

View file

@ -62,9 +62,9 @@ func TestPull(t *testing.T) {
assert.False(t, pullUpdateFile.HasMerged)
assert.True(t, pullUpdateFile.Mergeable)
merged, err := c.MergePullRequest(user.UserName, repoName, pullUpdateFile.Index, MergePullRequestOption{
Do: "squash",
MergeTitleField: pullUpdateFile.Title,
MergeMessageField: "squash: " + pullUpdateFile.Title,
Style: MergeStyleSquash,
Title: pullUpdateFile.Title,
Message: "squash: " + pullUpdateFile.Title,
})
assert.NoError(t, err)
assert.True(t, merged)
@ -85,9 +85,9 @@ func TestPull(t *testing.T) {
assert.False(t, pullConflict.HasMerged)
assert.False(t, pullConflict.Mergeable)
merged, err = c.MergePullRequest(user.UserName, repoName, pullConflict.Index, MergePullRequestOption{
Do: "merge",
MergeTitleField: "pullConflict",
MergeMessageField: "pullConflict Msg",
Style: MergeStyleMerge,
Title: "pullConflict",
Message: "pullConflict Msg",
})
assert.NoError(t, err)
assert.False(t, merged)