Skip to content

Commit

Permalink
refactor: internally use the positive flags (#93)
Browse files Browse the repository at this point in the history
While the flags are --no-fetch/--no-push, internally use the positive
flags because it's hard to read.
  • Loading branch information
draftcode authored May 2, 2023
1 parent ff95f57 commit 122d97a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions cmd/av/stack_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"golang.org/x/exp/slices"
"io/ioutil"
"os"
"path"
"strings"

"golang.org/x/exp/slices"

"emperror.dev/errors"
"github.com/aviator-co/av/internal/actions"
"github.com/aviator-co/av/internal/config"
Expand Down Expand Up @@ -290,8 +291,8 @@ base branch.
state.CurrentBranch = currentBranch
res, err := actions.SyncBranch(ctx, repo, client, repoMeta, actions.SyncBranchOpts{
Branch: currentBranch,
NoFetch: state.Config.NoFetch,
NoPush: state.Config.NoPush,
Fetch: !state.Config.NoFetch,
Push: !state.Config.NoPush,
Continuation: state.Continuation,
ToTrunk: state.Config.Trunk,
})
Expand Down
10 changes: 5 additions & 5 deletions internal/actions/sync_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

type SyncBranchOpts struct {
Branch string
NoFetch bool
NoPush bool
Fetch bool
Push bool
// If specified, synchronize the branch against the latest version of the
// trunk branch. This value is ignored if the branch is not a stack root.
ToTrunk bool
Expand Down Expand Up @@ -71,7 +71,7 @@ func SyncBranch(
return nil, err
}
} else {
if !opts.NoFetch {
if opts.Fetch {
update, err := UpdatePullRequestState(ctx, repo, client, repoMeta, branch.Name)
if err != nil {
_, _ = fmt.Fprint(os.Stderr, colors.Failure(" - error: ", err.Error()), "\n")
Expand Down Expand Up @@ -115,7 +115,7 @@ func SyncBranch(
return res, nil
}

if !opts.NoPush {
if opts.Push {
if err := syncBranchPushAndUpdatePullRequest(ctx, repo, client, branch, pull); err != nil {
return nil, err
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func syncBranchRebase(
" - rebasing ", colors.UserInput(branch.Name),
" on top of merge commit ", colors.UserInput(short), "\n",
)
if !opts.NoFetch {
if opts.Fetch {
if _, err := repo.Git("fetch", "origin", branch.MergeCommit); err != nil {
return nil, errors.WrapIff(err, "failed to fetch merge commit %q from origin", short)
}
Expand Down

0 comments on commit 122d97a

Please sign in to comment.