Skip to content

Commit

Permalink
adding sync command
Browse files Browse the repository at this point in the history
  • Loading branch information
tulioz committed Nov 26, 2024
1 parent eee2f73 commit 12a40a1
Show file tree
Hide file tree
Showing 24 changed files with 837 additions and 733 deletions.
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ automatically update the dependent PR when the base PR is updated. Read more at
PRs](https://www.aviator.co/blog/rethinking-code-reviews-with-stacked-prs/).

# Community

Join our discord community: [https://discord.gg/TFgtZtN8](https://discord.gg/NFsYWNzXcH)

# Features
Expand Down Expand Up @@ -82,7 +83,7 @@ $ gh pr merge feature-1
Sync the stack:

```sh
$ av stack sync
$ av sync

✓ GitHub fetch is done
✓ Restack is done
Expand Down Expand Up @@ -142,21 +143,26 @@ Add Aviator to your APT repositories.
echo "deb [trusted=yes] https://apt.fury.io/aviator/ /" > \
/etc/apt/sources.list.d/fury.list
```

And then apt install.

```sh
sudo apt update
sudo apt install av
```

### Alternatively

If you'd prefer you can download the `.deb` file from the [releases page](https://github.com/aviator-co/av/releases).

```sh
apt install ./av_$VERSION_linux_$ARCH.deb
```

## RPM-based systems

Add the following file `/etc/yum.repos.d/fury.repo`.

```conf
[fury]
name=Gemfury Private Repo
Expand All @@ -166,16 +172,19 @@ gpgcheck=0
```

Run the following command to confirm the configuration is working.

```sh
yum --disablerepo=* --enablerepo=fury list available
```

And then run yum install.

```sh
sudo yum install av
```

### Alternatively

If you'd prefer you can download the `.rpm` file from the [releases page](https://github.com/aviator-co/av/releases).

```sh
Expand Down Expand Up @@ -215,19 +224,19 @@ Download the binary from the [releases page](https://github.com/aviator-co/av/re

# Example commands

| Command | Description |
| --------------------- | ---------------------------------------------------------- |
| `av stack branch` | Create a new child branch from the current branch. |
| `av stack restack` | Rebase the branches to their parents. |
| `av pr create` | Create or update a PR. |
| `av stack tree` | Visualize the PRs. |
| `av stack sync --all` | Fetch and rebase all branches. |
| `av stack adopt` | Adopt a branch that is not created from `av stack branch`. |
| `av stack reparent` | Change the parent of the current branch. |
| `av stack switch` | Check out branches interactively. |
| `av stack reorder` | Reorder the branches. |
| `av commit amend` | Amend the last commit and rebase the children. |
| `av commit split` | Split the last commit. |
| Command | Description |
| ------------------- | ---------------------------------------------------------- |
| `av stack branch` | Create a new child branch from the current branch. |
| `av stack restack` | Rebase the branches to their parents. |
| `av pr create` | Create or update a PR. |
| `av stack tree` | Visualize the PRs. |
| `av sync --all` | Fetch and rebase all branches. |
| `av stack adopt` | Adopt a branch that is not created from `av stack branch`. |
| `av stack reparent` | Change the parent of the current branch. |
| `av stack switch` | Check out branches interactively. |
| `av stack reorder` | Reorder the branches. |
| `av commit amend` | Amend the last commit and rebase the children. |
| `av commit split` | Split the last commit. |

# How it works

Expand All @@ -238,6 +247,6 @@ new base branch using the remembered starting point as the merge base.

# Learn more

* [Rethinking code reviews with stacked PRs](https://www.aviator.co/blog/rethinking-code-reviews-with-stacked-prs/)
* [Issue Tracker](https://github.com/aviator-co/av/issues)
* [Changelog](https://github.com/aviator-co/av/releases)
- [Rethinking code reviews with stacked PRs](https://www.aviator.co/blog/rethinking-code-reviews-with-stacked-prs/)
- [Issue Tracker](https://github.com/aviator-co/av/issues)
- [Changelog](https://github.com/aviator-co/av/releases)
69 changes: 67 additions & 2 deletions cmd/av/auth.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,77 @@
package main

import (
"context"
"fmt"
"os"

"emperror.dev/errors"
"github.com/aviator-co/av/internal/gh"

"github.com/aviator-co/av/internal/avgql"
"github.com/aviator-co/av/internal/utils/colors"
"github.com/spf13/cobra"
)

var authCmd = &cobra.Command{
Use: "auth",
Short: "Manage authentication",
Use: "auth",
Short: "Check user authentication status",
SilenceUsage: true,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
if err := checkAviatorAuthStatus(); err != nil {
fmt.Fprintln(os.Stderr, colors.Warning(err.Error()))
}
if err := checkGitHubAuthStatus(); err != nil {
fmt.Fprintln(os.Stderr, colors.Failure(err.Error()))
}
},
}

func checkAviatorAuthStatus() error {
avClient, err := avgql.NewClient()
if err != nil {
return err
}

var query struct{ avgql.ViewerSubquery }
if err := avClient.Query(context.Background(), &query, nil); err != nil {
return err
}
if err := query.CheckViewer(); err != nil {
return err
}

fmt.Fprint(os.Stderr,
"Logged in to Aviator as ", colors.UserInput(query.Viewer.FullName),
" (", colors.UserInput(query.Viewer.Email), ").\n",
)
return nil
}

func checkGitHubAuthStatus() error {
ghClient, err := getGitHubClient()
if err != nil {
return err
}

viewer, err := ghClient.Viewer(context.Background())
if err != nil {
// GitHub API returns 401 Unauthorized if the token is invalid or
// expired.
if gh.IsHTTPUnauthorized(err) {
return errors.New(
"You are not logged in to GitHub. Please verify that your API token is correct.",
)
}
return errors.Wrap(err, "Failed to query GitHub")
}

fmt.Fprint(os.Stderr,
"Logged in to GitHub as ", colors.UserInput(viewer.Name),
" (", colors.UserInput(viewer.Login), ").\n",
)
return nil
}

func init() {
Expand Down
79 changes: 7 additions & 72 deletions cmd/av/auth_status.go
Original file line number Diff line number Diff line change
@@ -1,83 +1,18 @@
package main

import (
"context"
"fmt"
"os"

"emperror.dev/errors"
"github.com/aviator-co/av/internal/actions"
"github.com/aviator-co/av/internal/gh"

"github.com/aviator-co/av/internal/avgql"
"github.com/aviator-co/av/internal/utils/colors"
"github.com/spf13/cobra"
)

var authStatusCmd = &cobra.Command{
Use: "status",
Short: "Show info about the logged in user",
SilenceUsage: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
exitCode := 0
if err := checkAviatorAuthStatus(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, colors.Failure(err.Error()))
exitCode = 1
}
if err := checkGitHubAuthStatus(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, colors.Failure(err.Error()))
exitCode = 1
}
if exitCode != 0 {
return actions.ErrExitSilently{ExitCode: exitCode}
}
return nil
Use: "status",
Short: "Deprecated: Show info about the logged in user (use 'av auth' instead)",
Hidden: true,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("'av auth status' is deprecated. Please use 'av auth' instead.")
authCmd.Run(cmd, args)
},
}

func checkAviatorAuthStatus() error {
avClient, err := avgql.NewClient()
if err != nil {
return err
}

var query struct{ avgql.ViewerSubquery }
if err := avClient.Query(context.Background(), &query, nil); err != nil {
return err
}
if err := query.CheckViewer(); err != nil {
return err
}

_, _ = fmt.Fprint(os.Stderr,
"Logged in to Aviator as ", colors.UserInput(query.Viewer.FullName),
" (", colors.UserInput(query.Viewer.Email), ").\n",
)
return nil
}

func checkGitHubAuthStatus() error {
ghClient, err := getGitHubClient()
if err != nil {
return err
}

viewer, err := ghClient.Viewer(context.Background())
if err != nil {
// GitHub API returns 401 Unauthorized if the token is invalid or
// expired.
if gh.IsHTTPUnauthorized(err) {
return errors.New(
"You are not logged in to GitHub. Please verify that your API token is correct.",
)
}
return errors.Wrap(err, "Failed to query GitHub")
}

_, _ = fmt.Fprint(os.Stderr,
"Logged in to GitHub as ", colors.UserInput(viewer.Name),
" (", colors.UserInput(viewer.Login), ").\n",
)
return nil
}
2 changes: 1 addition & 1 deletion cmd/av/commit_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func splitCommit(repo *git.Repo, currentBranchName, currentCommitOID string) err
// TODO: We should rebase the stacks after split.
_, _ = fmt.Fprint(
os.Stderr,
"Run `av stack sync` to sync your stack if necessary.",
"Run 'av sync' to sync your stack if necessary.",
)

}
Expand Down
1 change: 1 addition & 0 deletions cmd/av/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func init() {
stackCmd,
versionCmd,
authCmd,
syncCmd,
)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/av/stack_adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func init() {
"dry-run adoption",
)

_ = stackSyncCmd.RegisterFlagCompletionFunc(
_ = stackAdoptCmd.RegisterFlagCompletionFunc(
"parent",
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
branches, _ := allBranches()
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/stack_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Generates the diff between the working tree and the parent branch
colors.Warning("\nWARNING: Branch "), colors.UserInput(currentBranchName),
colors.Warning(" is not up to date with parent branch "),
colors.UserInput(branch.Parent.Name), colors.Warning(". Run "),
colors.CliCmd("av stack sync"), colors.Warning(" to synchronize the branch.\n"),
colors.CliCmd("av sync"), colors.Warning(" to synchronize the branch.\n"),
)
return actions.ErrExitSilently{ExitCode: 1}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/stack_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (vm stackSwitchViewModel) View() string {
return ret
}

func (_ stackSwitchViewModel) renderBranchInfo(
func (stackSwitchViewModel) renderBranchInfo(
stbi *stackTreeBranchInfo,
currentBranchName string,
branchName string,
Expand Down
Loading

0 comments on commit 12a40a1

Please sign in to comment.