Skip to content

Commit

Permalink
fix --draft flag when creating a PR with rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ClairePhi committed Nov 22, 2024
1 parent be847f9 commit e13720d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cmd/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ func (c *create) RebasePrCommits(ctx context.Context, previousArgs *args) (*args
headCommit, core.GetRemoteName(), core.GetBaseBranch(),
), 1)
}
return &args{
AncestorBranch: ancestor,
Commits: commits,
Detached: previousArgs.Detached,
InitialBranch: previousArgs.InitialBranch,
NeedsRebase: false,
CheckoutPr: true,
Extract: previousArgs.Extract,
}, nil

// make a deep copy of previous args
newArgs := *previousArgs
newArgs.AncestorBranch = ancestor
newArgs.Commits = commits
newArgs.NeedsRebase = false
newArgs.CheckoutPr = true

return &newArgs, nil
}

func (c *create) Create(ctx context.Context, in io.Reader, args *args) (*core.LocalPr, error) {
Expand Down Expand Up @@ -417,6 +417,7 @@ func (c *create) createOnce(
if err != nil {
return 0, err
}

pull := github.NewPullRequest{
Title: &title,
Head: &remote,
Expand Down
29 changes: 29 additions & 0 deletions cmd/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cupcicm/opp/core"
"github.com/cupcicm/opp/core/tests"
"github.com/google/go-github/v56/github"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -74,3 +75,31 @@ func TestCanSetAncestor(t *testing.T) {
assert.Equal(t, "pr/2", ancestor.LocalName())
}
}

func TestCanSetAncestorWithDraft(t *testing.T) {
r := tests.NewTestRepo(t)

r.CreatePr(t, "HEAD^", 2)

draft := true
remote := "cupcicm/pr/3"
base := "cupcicm/pr/2"
title := "4"
body := ""

prDetails := github.NewPullRequest{
Title: &title,
Head: &remote,
Base: &base,
Body: &body,
Draft: &draft,
}

rebasedOnMaster := r.CreatePrAssertPrDetails(t, "HEAD", 3, prDetails, "--base", "2", "--draft")

assert.True(t, rebasedOnMaster.StateIsLoaded())
ancestor, err := rebasedOnMaster.GetAncestor()
if assert.Nil(t, err) {
assert.Equal(t, "pr/2", ancestor.LocalName())
}
}

0 comments on commit e13720d

Please sign in to comment.