gitbucket-cli 0.6.1

A command-line tool for GitBucket, inspired by GitHub CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# GitBucket CLI

[![Rust](https://github.com/Masahiro-Obuchi/gitbucket-cli-rs/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/Masahiro-Obuchi/gitbucket-cli-rs/actions/workflows/rust.yml)
[![E2E](https://github.com/Masahiro-Obuchi/gitbucket-cli-rs/actions/workflows/e2e.yml/badge.svg?branch=main)](https://github.com/Masahiro-Obuchi/gitbucket-cli-rs/actions/workflows/e2e.yml)

`gb` is a command-line interface for GitBucket.
It is inspired by [GitHub CLI (`gh`)](https://cli.github.com/) and implemented in Rust.
This is an unofficial community project and is not affiliated with the GitBucket project.

```bash
$ gb issue list
#    STATE   TITLE                          AUTHOR   LABELS
#1   OPEN    Fix login page bug             alice    bug
#3   OPEN    Add dark mode support          bob      enhancement

$ gb pr create -t "Add feature X" --head feature/x -B main
✓ Created pull request #5: Add feature X
Head: alice/my-app:feature/x
Base: alice/my-app:main
URL: https://gitbucket.example.com/alice/my-app/pull/5
```

## Installation

### Install with Cargo

```bash
cargo install gitbucket-cli --locked
```

To install a specific version tag:

```bash
cargo install --git https://github.com/Masahiro-Obuchi/gitbucket-cli-rs --tag v0.6.0 --locked
```

### Build from source

```bash
git clone https://github.com/Masahiro-Obuchi/gitbucket-cli-rs.git
cd gitbucket-cli-rs
cargo build --release
cp target/release/gb ~/.local/bin/
```

### Prebuilt binaries

Tagged releases publish prebuilt binaries to GitHub Releases for supported platforms.
See [RELEASE.md](RELEASE.md) for the release process.

**Requirements:** Rust 1.70+ and `git` when installing with Cargo or building from source

## Quick start

### 1) Authenticate

```bash
gb auth login
# GitBucket host or URL: gitbucket.example.com
# Personal access token: ********
# ✓ Logged in to gitbucket.example.com as alice
```

Create a token in **GitBucket → Account Settings → Personal access tokens**.

For subpath deployments, pass the base URL (or host plus path):

```bash
gb auth login -H https://gitbucket.example.com/gitbucket
# or
gb auth login -H gitbucket.example.com/gitbucket --protocol https
```

### 2) Repository operations

```bash
gb repo list
gb repo view alice/my-app
gb repo create my-new-repo
gb repo create my-team-repo --group dev-team
gb repo clone alice/my-app
gb repo fork alice/my-app
```

### 3) Label operations

```bash
gb label list
gb label create bug --color fc2929 --description "Broken behavior"
gb label view bug
gb label edit bug --name defect --color cc0000 --description "Confirmed defect"
gb label delete bug --yes
```

### 4) Milestone operations

```bash
gb milestone list --state all
gb milestone create v1.0 --description "First release" --due-on 2026-04-01
gb milestone view 1
gb milestone edit 1 --state closed
gb milestone delete 1 --yes
```

### 5) Issue operations

```bash
gb issue list --state all
gb issue create -t "Bug report"
gb issue view 1
gb issue view 1 --comments
gb issue view 1 --comments --no-pager
gb issue edit 1 --title "Updated bug report" --add-label urgent
gb issue close 1
gb issue comment 1 -b "Fixed!"
gb issue comment 1 --edit-last -b "Actually fixed!"
```

### 6) Pull request operations

```bash
gb pr list --state closed
gb pr list --state open --json --no-pager
gb pr create
gb pr create -t "From fork" --head feature/x --head-owner alice -B main
gb pr create --head feature/x -B main --detect-existing
gb pr view 5
gb pr view 5 --json --no-pager
gb pr edit 5 --add-assignee bob
gb pr merge 5
gb pr checkout 5
gb pr diff 5 --no-pager
gb pr comment 5 --edit-last -b "Updated note" --json
gb pr comment list 5 --json --no-pager
```

## Command reference

| Command                        | Description                          |
| ------------------------------ | ------------------------------------ |
| `gb auth login`                | Authenticate to a GitBucket instance |
| `gb auth logout`               | Remove auth for a host               |
| `gb auth status [--json]`      | Show current auth status             |
| `gb auth token`                | Print access token                   |
| `gb config`                    | Manage local CLI configuration       |
| `gb completion <SHELL>`        | Generate shell completion scripts    |
| `gb api <ENDPOINT>`            | Call the GitBucket REST API directly |
| `gb repo list [OWNER]`         | List repositories                    |
| `gb repo view [OWNER/REPO]`    | Show repository details              |
| `gb repo create [NAME]`        | Create a repository                  |
| `gb repo clone <REPO>`         | Clone a repository                   |
| `gb repo delete [OWNER/REPO]`  | Delete a repository                  |
| `gb repo fork [OWNER/REPO]`    | Fork a repository                    |
| `gb label list`                | List labels                          |
| `gb label view <NAME>`         | Show label details                   |
| `gb label create [NAME]`       | Create a label                       |
| `gb label edit <NAME>`         | Edit a label                         |
| `gb label delete <NAME>`       | Delete a label                       |
| `gb milestone list`            | List milestones                      |
| `gb milestone view <NUMBER>`   | Show milestone details               |
| `gb milestone create [TITLE]`  | Create a milestone                   |
| `gb milestone edit <NUMBER>`   | Edit a milestone                     |
| `gb milestone delete <NUMBER>` | Delete a milestone                   |
| `gb issue list`                | List issues                          |
| `gb issue view <NUMBER>`       | Show issue details                   |
| `gb issue create`              | Create an issue                      |
| `gb issue edit <NUMBER>`       | Edit an issue                        |
| `gb issue close <NUMBER>`      | Close an issue                       |
| `gb issue reopen <NUMBER>`     | Reopen an issue                      |
| `gb issue comment <NUMBER>`    | Add or edit an issue comment         |
| `gb pr list`                   | List pull requests                   |
| `gb pr view <NUMBER>`          | Show PR details                      |
| `gb pr create`                 | Create a pull request                |
| `gb pr edit <NUMBER>`          | Edit a pull request                  |
| `gb pr close <NUMBER>`         | Close a pull request                 |
| `gb pr merge <NUMBER>`         | Merge a pull request                 |
| `gb pr checkout <NUMBER>`      | Checkout a PR branch                 |
| `gb pr diff <NUMBER>`          | Show PR diff                         |
| `gb pr comment <NUMBER>`       | Add or edit a PR comment             |
| `gb pr comment list <NUMBER>`  | List PR comments                     |
| `gb browse`                    | Open repository in browser           |

## Global options

```text
-H, --hostname <HOST>    GitBucket host or base URL
-R, --repo <OWNER/REPO>  Target repository
    --profile <NAME>     Configuration profile
    --json-errors        Print failures as structured JSON on stderr
-h, --help               Show help
-V, --version            Show version
```

## Repository auto-resolution

If `-R/--repo` is omitted, `gb` tries to detect `OWNER/REPO` from `git remote get-url origin`. For `gb repo view`, `gb repo delete`, and `gb repo fork`, you can pass `OWNER/REPO` positionally after the subcommand or pass `-R/--repo` at the subcommand.

```bash
cd ~/projects/my-app
gb issue list
```

Supported remote URL formats include:

- `https://gitbucket.example.com/alice/my-app.git`
- `https://gitbucket.example.com/git/alice/my-app.git`
- `https://gitbucket.example.com/gitbucket/alice/my-app.git`
- `https://gitbucket.example.com/gitbucket/git/alice/my-app.git`
- `git@gitbucket.example.com:alice/my-app.git`

## Output formats

```bash
gb issue list
gb issue list --json --no-pager
gb issue view 1 --web
```

## Skill Sample

This repository includes a sample Skill for AI agents that need to operate GitBucket with `gb`:

```text
skills/gitbucket-cli/
```

The skill keeps agent-facing workflow guidance separate from the full user documentation in this README and `SPEC.md`.

## State Filters

`gb issue list`, `gb pr list`, and `gb milestone list` support `--state open`, `--state closed`, and `--state all`.
Invalid values are rejected before the API call is made.

## GitBucket Web Fallbacks

Some GitBucket actions are only exposed through the web UI, not the REST API.
When `gb repo delete`, `gb repo fork`, `gb issue close`, `gb issue reopen`, or issue metadata updates hit that case, `gb` falls back to a short web sign-in flow and may prompt for your password.
`gb pr edit` is automation-safe by default: if REST PR edit is unavailable it fails non-interactively, and uses the web fallback only when `--web` is passed.
When a web fallback is used, `gb` writes a `Notice:` line to stderr so scripts can distinguish REST-only success from fallback success.
For `gb issue edit`, the web fallback currently covers title/body/assignee/milestone/state updates. Label edits still require REST issue edit support from the target GitBucket.
Use `GB_USER` and `GB_PASSWORD` to preseed those prompts when needed.

Issue label and assignee options can be repeated or comma-separated:

```bash
gb issue create -t "Bug report" --label bug,urgent --assignee alice
gb issue edit 1 --add-label needs-review --remove-assignee bob
gb pr edit 5 --add-assignee alice,bob --remove-assignee carol
```

`gb pr create --head` accepts a branch name for same-repository PRs. For cross-repository PRs, pass `OWNER:BRANCH` or use `--head-owner OWNER --head BRANCH`; after creation, the CLI prints the resolved `Head:` and `Base:` repositories and refs. Use `gb pr create --detect-existing` to return an existing open PR for the same head/base instead of creating a duplicate, including PRs that need to be recovered from GitBucket's issue listing. `gb pr create --json` and `gb pr view --json` print the API payload for automation; `gb pr view --comments --json` also includes a top-level `comments` array. `gb pr list --state open --json` fetches each open PR detail before printing JSON so fork head/base repository information matches `gb pr view --json` more closely.
`gb pr comment --json` prints the created or edited comment object; normal text output includes the comment ID and URL when GitBucket returns one. Use `gb pr comment list <NUMBER> --json` to inspect existing PR comments before retrying a comment mutation. `gb issue list`, `gb issue view`, `gb pr list`, `gb pr view`, and `gb pr comment list` accept `--no-pager` to force direct stdout output.

## Pull Request Checkout And Diff

`gb pr checkout` and `gb pr diff` work with same-repository PRs and fork-based PRs.
When a closed PR's diff cannot be reconstructed from fetched refs, `gb pr diff` tries the saved PR diff URL before failing. If no saved diff can be fetched, it exits non-zero and reports whether the live diff was unavailable because a ref was missing, a base/head fetch failed, or the fetched refs had no diff.
When the PR head repository is available from the API response, `gb` fetches from that repository's clone URL and operates on `FETCH_HEAD`.

For automation, pass global `--json-errors` or set `GB_JSON_ERRORS=true` to get a single JSON error object on stderr, including fields such as `error.code`, `error.cause`, `error.status`, and `error.exit_code`.

## Environment variables

| Variable        | Description                                               |
| --------------- | --------------------------------------------------------- |
| `GB_TOKEN`      | Access token (takes precedence over file config for auth) |
| `GB_HOST`       | Default GitBucket host or base URL                        |
| `GB_REPO`       | Default repository (`OWNER/REPO`)                         |
| `GB_PROFILE`    | Default configuration profile                             |
| `GB_CONFIG_DIR` | Config directory path (default: `~/.config/gb/`)          |
| `GB_PROTOCOL`   | Protocol override when using `GB_TOKEN` with a plain host |
| `GB_USER`       | Username for GitBucket web-session fallbacks              |
| `GB_PASSWORD`   | Password for GitBucket web-session fallbacks              |
| `GB_JSON_ERRORS` | Print failures as structured JSON on stderr              |
| `NO_COLOR`      | Disable colored output                                    |

## Configuration file

Credentials are stored in `~/.config/gb/config.toml` (or under `GB_CONFIG_DIR`).
On Unix-like systems, the file is written with `0600` permissions.

```toml
default_host = "https://gitbucket.example.com/gitbucket"

[hosts."https://gitbucket.example.com/gitbucket"]
token = "your-personal-access-token"
user = "alice"
protocol = "https"
```

Plain host keys also work:

```toml
[hosts."gitbucket.example.com"]
token = "your-personal-access-token"
user = "alice"
protocol = "https"
```

Profiles can select host and repository defaults, and can optionally carry credentials scoped to that profile:

```toml
default_profile = "work"

[profiles.work]
default_host = "gitbucket.example.com"
default_repo = "alice/project"

[profiles.work.hosts."gitbucket.example.com"]
token = "your-work-token"
user = "alice"
protocol = "https"
```

`--hostname` / `GB_HOST` and `--repo` / `GB_REPO` override profile defaults. Profile-scoped credentials are tried before global `[hosts]` credentials for the same host.

The same GitBucket host can be used with multiple accounts by storing credentials under different profiles:

```sh
gb auth login --profile work -H gitbucket.example.com -t "$WORK_TOKEN"
gb auth login --profile personal -H gitbucket.example.com -t "$PERSONAL_TOKEN"

gb auth status --profile work
gb auth status --profile personal --json
gb issue list --profile work -R alice/project
```

`gb auth status --profile <name>` prints only that profile and shows its effective actor, including whether credentials came from the profile, global host entry, or environment token. `gb auth status --json` exposes the same information in `effective_actor` for scripts.

When `GB_TOKEN` is set, protocol selection uses this order:

1. URL scheme from `--hostname` or `GB_HOST` when present
2. `GB_PROTOCOL`
3. Matching stored host configuration
4. Default `https`

## Roadmap

Current priority is to harden CI and Docker-backed verification around the existing command set before adding larger new areas.

Near term:

- Keep strengthening test and Docker-backed E2E coverage
- Keep `cargo clippy --all-targets --all-features -- -D warnings` green in CI

After that:

- Richer issue/PR metadata handling

Lower priority / re-evaluate later:

- Webhook and collaborator operations
- Admin-oriented user management flows

## Configuration commands

```bash
gb config path
gb config list
gb config get default-host
gb config get default-profile
gb config get host --host gitbucket.example.com/gitbucket --field protocol
gb config get profile work --json
gb config set host --host gitbucket.example.com/gitbucket --protocol http --default
gb config set profile work --default-host gitbucket.example.com --default-repo alice/project
gb config set default-profile work
gb config unset default-host
gb config unset default-profile
```

`gb config` manages the local `config.toml` file. It currently supports:

- printing the config file path
- listing saved hosts, profiles, and stored defaults
- reading saved host `user` / `protocol` / `has-token` values
- updating saved host `user` / `protocol` values
- creating or updating profile defaults
- setting or clearing `default_host` and `default_profile`

Token creation and token printing remain under `gb auth`.

## API command

```bash
gb api user
gb api /api/v3/user
gb api repos/alice/my-app/issues --input body.json
echo '{"state":"closed"}' | gb api repos/alice/my-app/issues/1 -X PATCH --input -
```

`gb api` calls the GitBucket REST API directly using the configured host and token.
It accepts endpoint paths relative to `/api/v3`, full API paths such as `/api/v3/user`, or absolute URLs under the configured GitBucket API base.
When `--input` is given and `-X/--method` is omitted, `gb api` defaults to `POST`.
JSON responses are pretty-printed, and empty success responses print `null`.

## Completion command

```bash
gb completion bash > ~/.local/share/bash-completion/completions/gb
gb completion zsh > ~/.zfunc/_gb
gb completion fish > ~/.config/fish/completions/gb.fish
gb completion powershell > gb.ps1
```

`gb completion` prints shell completion scripts to stdout.
It currently supports `bash`, `zsh`, `fish`, and `powershell`.
The command does not install the scripts for you; redirect the output to the appropriate location for your shell.

## Label commands

```bash
gb label list
gb label list --json
gb label view bug
gb label create needs-review --color abcdef --description "Needs extra review"
gb label edit needs-review --color 123abc --remove-description
gb label delete needs-review --yes
```

`gb label` manages repository label definitions through the GitBucket REST API.
It currently supports listing, viewing, creating, editing, and deleting labels in the target repository.
Colors accept 6-digit hex values with or without a leading `#`.

## Milestone commands

```bash
gb milestone list
gb milestone list --state all --json
gb milestone view 7
gb milestone create v1.0 --description "First release" --due-on 2026-04-01
gb milestone edit 7 --title v1.0.1 --state closed
gb milestone delete 7 --yes
```

`gb milestone` manages repository milestones.
It currently supports listing, viewing, creating, editing, and deleting milestones in the target repository.
`--due-on` accepts `YYYY-MM-DD` or RFC3339. When GitBucket returns `404` for milestone create or edit over REST, `gb` falls back to the GitBucket web UI flow and may prompt for `GB_USER` / `GB_PASSWORD`.

## Testing

For the current automated test layout, release checks, and Docker-backed E2E workflow, see [TESTING.md](./TESTING.md).

## Acknowledgements

This project exists thanks to [GitBucket](https://gitbucket.github.io/) and the community around it. Thank you for building and maintaining the software that made this CLI worth creating.

## License

MIT