Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
- name: tmux, for e2e/tui
if: runner.os == 'Linux'
run: command -v tmux || (sudo apt-get update && sudo apt-get install -y tmux)
- name: jj, for the jj repository tests
if: runner.os == 'Linux'
run: |
curl -fsSL https://github.com/jj-vcs/jj/releases/download/v0.46.0/jj-v0.46.0-x86_64-unknown-linux-musl.tar.gz | sudo tar xz -C /usr/local/bin ./jj
jj --version
- run: go build ./...
- run: go vet ./...
- run: go test -race ./...
Expand Down
4 changes: 2 additions & 2 deletions completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var commandFlags = map[string][]string{
"create": {"-config", "-site", "-format", "-project", "-type", "-summary", "-description"},
"move": {"-config", "-site"},
"prompt": {"-config", "-site", "-format"},
"hook": {"-config", "-site", "-strict", "-force"},
"hook": {"-config", "-site", "-strict", "-force", "-fix"},
"rules": {"-config", "-site", "-on", "-key", "-summary", "-type", "-status", "-from-status", "-assignee", "-priority", "-points", "-watch", "-by-me"},
"setup": {"-config", "-site"},
"login": {"-config", "-site", "-device"},
Expand All @@ -62,7 +62,7 @@ var commandFlags = map[string][]string{
}

var commandArgs = map[string][]string{
"hook": {"install"},
"hook": {"install", "check"},
"index": {"clear"},
"rules": {"list", "test", "watch"},
"token": {"list", "create", "revoke", "revoke-all"},
Expand Down
7 changes: 7 additions & 0 deletions docs/guide/06-work-on-an-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ refuses the commit; merges, reverts and fixups pass. `-strict` also
refuses keys Jira doesn't know. Checking out an issue's branch while it's
still to do asks `move ABC-12 (To Do) to In Progress? [y/N]`.

jj runs no git hooks: there, `laneway hook check -fix` before you push puts
the bookmark's key in front of your branch's changes that name no issue.

## Start work with an agent: `S`

With [herdr](https://herdr.dev) running, `S` on an issue starts work: the
Expand Down Expand Up @@ -127,6 +130,10 @@ search `pr:open` finds the ones with an open one.
Once it's merged, *Remove its worktree* in the same actions removes the
checkout. Uncommitted changes keep it; the branch stays.

In a [jj](https://jj-vcs.github.io/jj/) repository the worktree is a jj
workspace and the branch a bookmark; [jj in the config
reference](../reference/config.md#jj) has the details.

## Review a merge request

The merge requests waiting on you on every GitLab you're signed in to
Expand Down
9 changes: 9 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ it names the server's own page, which can.
| `laneway prompt [-format TEMPLATE]` | the git branch's issue, its status, the timer and the inbox count: `ABC-12 · In review · ⏱ 1h 20m · ✉ 3`. Reads the state file only, never Jira; a Go template over `.Key .Status .TimerKey .Timer .Inbox` |
| `laneway completion bash\|zsh\|fish` | a completion script: commands, flags, site names and, for `view` and `move`, the keys on the boards last loaded |
| `laneway hook install [-strict] [-force]` | git hooks in this repository, see below |
| `laneway hook check [-fix] [-strict]` | in a jj repository: the issue keys of your branch's changes, see below |
| `laneway index [clear]` | what the local index holds; `clear` drops it |

```sh
Expand Down Expand Up @@ -110,6 +111,14 @@ set -g status-right '#(laneway prompt -format "{{.Key}} {{.Timer}}")'
A hook that isn't laneway's is kept unless `-force`; the hooks do nothing
where laneway isn't installed.

[jj](https://jj-vcs.github.io/jj/) runs no git hooks, so in a jj repository
`install` says so and installs nothing. `laneway hook check` does
`commit-msg`'s work there, for the changes of your branch (trunk to `@`) at
once, before you push: it lists those whose description names no issue and
fails, `-fix` puts the bookmark's key in front of them (`jj describe`), and
`-strict` refuses keys Jira doesn't know. Changes without a description are
left alone; jj won't push them anyway.

## Rules

| Command | |
Expand Down
25 changes: 24 additions & 1 deletion docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ ui:
| `work_args` | | its arguments before the prompt; `{key}` is replaced |
| `work_create` | | the command that makes a missing worktree (`{branch} {base} {key}`); unset: herdr |
| `agent_view` | `fullscreen` | `panel` attaches an agent in the panel. Terminal |
| `multiplexer` | herdr | another multiplexer speaking herdr's socket API and CLI: `command` (its CLI), `socket` (its API socket), `inside_env` (the variable it sets in its panes) |
| `multiplexer` | herdr | another multiplexer speaking herdr's socket API and CLI: `command` (its CLI), `socket` (its API socket), `inside_env` (the variable it sets in its panes), `jj_workspaces: true` when its worktree calls make and remove jj workspaces itself ([drover](#jj)) |
| `llm` | `claude -p` when on the PATH | the ask command: the question last, the issue on stdin (`llm`, `ollama run llama3`) |
| `actions` | | your own commands on an issue, see [Actions](#actions) |

Expand All @@ -219,6 +219,29 @@ ui:
work_create: [wt, switch, --create, "{branch}", --base, "{base}", --no-cd]
```

#### jj

A repository with a `.jj` (colocated with git or not) is read through jj:
bookmarks are its branches, workspaces its worktrees, `trunk()`'s remote
bookmark (`main@origin`) the base. The branch you're on is the bookmark on
`@` or its nearest ancestor, trunk's not counting. Start work makes a jj
workspace beside the repository (`../repo.issue-ABC-1-fix`) with a
bookmark at the base when the branch is new, and opens it as a plain
workspace; herdr's own worktrees are git's. `work_create` is a git command
and isn't run there. A multiplexer that does jj workspaces itself takes over
with `jj_workspaces`:

```yaml
ui:
multiplexer: {command: drover, jj_workspaces: true}
```

Removing a done issue's workspace keeps it while its working copy has
changes or any change in it isn't in the base, a commit past the bookmark
too. A pull request pushes the bookmark where it is
(`jj git push -b`): move it onto your work first. Time proposals take
jj's record of your edits per change instead of git's branch switches.

### Planning, roadmap and charts

| Option | Default | |
Expand Down
69 changes: 68 additions & 1 deletion hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cornedor/laneway/internal/i18n"
"github.com/cornedor/laneway/internal/jira"
"github.com/cornedor/laneway/internal/ui"
"github.com/cornedor/laneway/internal/vcs"
)

var hookUsage = i18n.N(`usage: laneway hook install [-strict] [-force]
Expand All @@ -29,7 +30,15 @@ Installs two git hooks in the repository you are in:
keys Jira doesn't know.
post-checkout checking out an issue's branch while the issue is still to
do asks to move it in progress.
An existing hook that isn't laneway's is kept unless -force.`)
An existing hook that isn't laneway's is kept unless -force.

jj runs no git hooks. In a jj repository install says so, and

laneway hook check [-fix] [-strict]

does commit-msg's work for the changes of your branch (trunk to @) at
once, before you push: it lists those whose description names no issue
key, and -fix puts the bookmark's key in front of them.`)

// hookMark tells laneway's hooks from others.
const hookMark = "# laneway hook"
Expand All @@ -50,12 +59,19 @@ func hookCmd(args []string, out, errOut io.Writer) int {
site := fs.String("site", "", i18n.T("Jira site from the config's sites:"))
strict := fs.Bool("strict", false, i18n.T("commit-msg: refuse keys Jira doesn't know"))
force := fs.Bool("force", false, i18n.T("install: replace hooks that aren't laneway's"))
fix := fs.Bool("fix", false, i18n.T("check: put the bookmark's key in front of the changes without one"))
if err := fs.Parse(args[1:]); err != nil {
return 2
}
switch args[0] {
case "install":
if vcs.IsJJ(".") {
fmt.Fprintln(errOut, "laneway hook install:", i18n.T("jj runs no git hooks: run laneway hook check (-fix) before you push"))
return 1
}
return hookInstall(*strict, *force, *cfgPath, *site, out, errOut)
case "check":
return hookCheck(*fix, *strict, *cfgPath, *site, out, errOut)
case "commit-msg":
if fs.NArg() != 1 {
fmt.Fprintln(errOut, "laneway hook commit-msg:", i18n.T("the message file, as git passes it"))
Expand Down Expand Up @@ -224,6 +240,57 @@ func siteClient(cfgPath, site string) (*jira.Client, error) {
return jira.New(jira.Config{BaseURL: cfg.Jira.BaseURL, Email: cfg.Jira.Email, APIToken: cfg.Jira.APIToken, SignIn: cfg.Jira.Credentials(), Timeout: 10 * time.Second}), nil
}

// hookCheck is commit-msg for a jj branch's changes: those without an
// issue key get the bookmark's with fix, else they are listed and it
// fails. strict also refuses keys Jira doesn't know.
func hookCheck(fix, strict bool, cfgPath, site string, out, errOut io.Writer) int {
if !vcs.IsJJ(".") {
fmt.Fprintln(errOut, "laneway hook check:", i18n.T("not in a jj repository: in git, laneway hook install checks every commit"))
return 1
}
ctx := context.Background()
changes, err := vcs.BranchChanges(ctx, ".")
if err != nil {
fmt.Fprintln(errOut, "laneway hook check:", err)
return 1
}
branchKey, code := ui.BranchIssue(), 0
var keys []string
for _, c := range changes {
if strings.TrimSpace(c.Description) == "" {
continue // jj won't push it before you describe it
}
if fix {
msg, err := keyedMessage(c.Description, branchKey)
if err == nil && msg != c.Description {
if err = vcs.Describe(ctx, ".", c.ID, msg); err == nil {
fmt.Fprintln(out, i18n.Tf("%s: added %s", c.ID, branchKey))
c.Description = msg
}
}
if err != nil {
fmt.Fprintln(errOut, "laneway:", c.ID+":", err)
code = 1
continue
}
}
k := messageKeys(c.Description)
if len(k) == 0 {
first, _, _ := strings.Cut(c.Description, "\n")
fmt.Fprintln(errOut, i18n.Tf("%s has no issue key: %s", c.ID, first))
code = 1
}
keys = append(keys, k...)
}
if strict && len(keys) > 0 {
if err := checkKeys(cfgPath, site, slices.Compact(slices.Sorted(slices.Values(keys)))); err != nil {
fmt.Fprintln(errOut, "laneway:", err)
return 1
}
}
return code
}

// hookPostCheckout offers to move the branch's issue in progress while it
// is still to do. Without a terminal to ask on it says nothing; it never
// fails the checkout.
Expand Down
36 changes: 36 additions & 0 deletions hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"

"github.com/cornedor/laneway/internal/jira"
"github.com/cornedor/laneway/internal/vcs/vcstest"
)

func TestKeyedMessage(t *testing.T) {
Expand Down Expand Up @@ -105,3 +106,38 @@ func TestOfferStart(t *testing.T) {
t.Error("enter alone should leave it")
}
}

// jj runs no hooks: install says so, and check does commit-msg's work for
// the branch's changes.
func TestHookCheckJJ(t *testing.T) {
repo, _, jj := vcstest.JJRepo(t)
t.Chdir(repo)
var out, errOut strings.Builder
if code := hookCmd([]string{"install"}, &out, &errOut); code != 1 || !strings.Contains(errOut.String(), "jj runs no git hooks") {
t.Errorf("install = %d %q", code, errOut.String())
}
jj(repo, "new", "main", "-m", "fix the login")
if err := os.WriteFile("b", []byte("b"), 0o600); err != nil {
t.Fatal(err)
}
jj(repo, "bookmark", "create", "issue/ABC-1-login", "-r", "@")
jj(repo, "new", "-m", "ABC-2 also this")
if err := os.WriteFile("c", []byte("c"), 0o600); err != nil {
t.Fatal(err)
}

errOut.Reset()
if code := hookCmd([]string{"check"}, &out, &errOut); code != 1 || !strings.Contains(errOut.String(), "has no issue key: fix the login") || strings.Contains(errOut.String(), "also this") {
t.Errorf("check = %d %q", code, errOut.String())
}
errOut.Reset()
if code := hookCmd([]string{"check", "-fix"}, &out, &errOut); code != 0 || errOut.Len() > 0 {
t.Errorf("check -fix = %d %q", code, errOut.String())
}
if got := jj(repo, "log", "--no-graph", "-r", "issue/ABC-1-login", "-T", "description"); got != "ABC-1 fix the login" {
t.Errorf("fixed description %q", got)
}
if code := hookCmd([]string{"check"}, &out, &errOut); code != 0 {
t.Errorf("check after fix = %d %q", code, errOut.String())
}
}
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ type MultiplexerConfig struct {
// InsideEnv is the environment variable it sets in its panes, telling
// laneway it runs inside it ("HERDR_ENV").
InsideEnv string `yaml:"inside_env"`
// JJWorkspaces says it makes, finds and removes jj workspaces itself
// (drover does). Without it laneway makes them in a jj repo and opens
// them as plain workspaces.
JJWorkspaces bool `yaml:"jj_workspaces,omitempty"`
}

// UIConfig tunes the app; every field is optional and "" / 0 keeps the
Expand Down
46 changes: 45 additions & 1 deletion internal/herdr/herdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ func IsCode(err error, code string) bool {
}

// Client addresses one herdr server by its socket path.
type Client struct{ path string }
type Client struct {
path string
// JJWorkspaces: the multiplexer makes, finds and removes a jj repo's
// workspaces through its worktree calls itself (drover). herdr makes git
// worktrees there, so laneway makes jj's.
JJWorkspaces bool
}

// Default finds the socket the herdr CLI would use: HERDR_SOCKET_PATH, then
// HERDR_SESSION's, then the default session's. Nil when there is none.
Expand Down Expand Up @@ -318,6 +324,44 @@ func (c *Client) CreateWorktree(ctx context.Context, repo, branch, base string)
return res.worktree(), err
}

// OpenDir opens dir as a workspace labelled label, or finds the one open
// with that label: for checkouts the multiplexer doesn't know, a jj
// workspace laneway made. An open one without an agent gets a new tab to
// start one in.
func (c *Client) OpenDir(ctx context.Context, label, dir string) (Worktree, error) {
wss, err := c.Workspaces(ctx)
if err != nil {
return Worktree{}, err
}
for _, ws := range wss {
if ws.Label != label {
continue
}
wt := Worktree{Path: dir, Workspace: ws.ID, AlreadyOpen: true}
agents, err := c.Agents(ctx)
if err != nil {
return wt, err
}
for _, a := range agents {
if a.WorkspaceID == ws.ID && a.Agent != "" {
return wt, nil
}
}
wt.Tab, wt.Pane, err = c.NewTab(ctx, ws.ID, label, dir, nil)
return wt, err
}
var res worktreeResult
err = c.call(ctx, "workspace.create", map[string]any{"label": label, "cwd": dir}, &res)
wt := res.worktree()
wt.Path = dir
return wt, err
}

// CloseWorkspace closes the workspace and its tabs.
func (c *Client) CloseWorkspace(ctx context.Context, workspace string) error {
return c.call(ctx, "workspace.close", map[string]any{"workspace_id": workspace}, nil)
}

// RemoveWorktree runs git worktree remove on the linked checkout open as
// workspace, closing it. The branch stays.
func (c *Client) RemoveWorktree(ctx context.Context, workspace string) error {
Expand Down
Loading
Loading