Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add release command #10

Merged
merged 3 commits into from
Mar 6, 2024
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
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ An fzf wrapper around the GitHub CLI.
- [`pr`](#pr)
- [`run`](#run)
- [`repo`](#repo)
- [`release`](#release)
- [Configuration](#configuration)
- [Related projects](#related-projects)

Expand Down Expand Up @@ -216,6 +217,28 @@ that can be used with any `gh fzf` command:
gh fzf repo google --archived --language typescript
```

### `release`

- **Usage**: `gh fzf release [flags]`
- **Aliases**: `releases`, `--release`, `--releases`
- **Flags**: See `gh release list --help` for available options
- **Keybindings**:
- `enter`: Download the assets for the selected release
(see `gh release download --help`)
- `alt-X`: Delete the selected release
(see `gh release delete --help`)
- `alt-s`: Filter the list, showing stable releases
(i.e. excluding pre-releases)
- `alt-p`: Filter the list, showing published releases
(i.e. excluding drafts)
- `alt-a`: Filter the list, showing releases in ascending order by release date
(defaults to descending order)
- **Examples**:
- Filter the initial list to exclude drafts and pre-releases:
```sh
gh fzf release --exclude-drafts --exclude-pre-releases
```

## Configuration

Environment variables are used to configure different options in `gh-fzf`.
Expand Down Expand Up @@ -251,8 +274,9 @@ aliases:

When adding or modifying fzf keybindings:

- use `{1}` in place of the `<number>` for the `issue` and `pr` commands.
- use `{-1}` in place of the `<run-id>` for the `run` command.
- Use `{1}` in place of the `<number>` for the `issue`/`pr` commands and in
place of the `<tag-name>` for the `release` command.
- Use `{-1}` in place of the `<run-id>` for the `run` command.

For a list of the fzf options shared by all `gh-fzf` commands, see the
[source code](https://github.com/benelan/gh-fzf/blob/c455e3034f49da1ae81c26779de2419fda87e4a8/gh-fzf#L145-L165).
Expand Down
64 changes: 63 additions & 1 deletion gh-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Core Commands:
pr Search for and interact with GitHub pull requests.
run Search for and interact with GitHub Action runs.
repo Search for and interact with GitHub repos.
release Search for and interact with GitHub releases.

See \`gh <command> list --help\` for the flag options.

Expand Down Expand Up @@ -126,7 +127,7 @@ FZF_DEFAULT_OPTS='
# --------------------------------------------------------------------- {|}

default_cmd() {
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n' 'issue' 'pr' 'run' 'repo'" \
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n' 'issue' 'pr' 'run' 'repo' 'release'" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh help {}' \
--preview-window='right:75%,wrap' \
Expand Down Expand Up @@ -408,6 +409,66 @@ Filters > (alt-c: private) (alt-o: public) (alt-s: source) (alt-f: forks)
--bind='alt-f:reload(eval "$FZF_DEFAULT_COMMAND --fork")'
}

# --------------------------------------------------------------------- }}}
# Command > release {{{
# --------------------------------------------------------------------- {|}

release_cmd() {
release_template='\
--json "publishedAt,isDraft,isLatest,isPrerelease,name,tagName" \
--template '\''
{{- $headerColor := "blue+b" -}}
{{- tablerow
("TAG" | autocolor $headerColor)
("PUBLISHED" | autocolor $headerColor)
("TITLE" | autocolor $headerColor)
("TYPE" | autocolor $headerColor)
-}}

{{- range . -}}
{{- $type := "" -}}
{{- $typeColor := "white+d" -}}
{{- if eq .isLatest true -}}
{{- $type = "Latest" -}}
{{- $typeColor = "green" -}}
{{- else if eq .isPrerelease true -}}
{{- $type = "Pre-release" -}}
{{- $typeColor = "yellow" -}}
{{- else if eq .isDraft true -}}
{{- $type = "Draft" -}}
{{- end -}}
{{- tablerow
(.tagName | autocolor "white+h")
(printf "%s (%s)"
(timefmt "2006-01-02" .publishedAt)
(timeago .publishedAt)
| autocolor "white+d")
(.name | autocolor "white+h")
($type | autocolor $typeColor)
-}}
{{- end -}}
'\'''

release_header='Actions > (enter: download) (alt-X: delete)
> (ctrl-o: open url) (ctrl-y: copy url) (ctrl-r: reload)
Filters > (alt-s: stable) (alt-p: published) (alt-a: ascending)

'

FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh release $release_template list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh release view {1}' \
--header="$release_header" \
--bind="start:$on_start" \
--bind='ctrl-o:execute-silent(gh release view --web {1})' \
--bind="ctrl-y:execute-silent(gh release view {1} --json 'url' -q '.url' | $GH_FZF_COPY_CMD)" \
--bind="alt-enter:execute(gh release download {1})" \
--bind="alt-X:execute(gh release delete {1})" \
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --exclude-pre-releases")' \
--bind='alt-p:reload(eval "$FZF_DEFAULT_COMMAND --exclude-drafts")' \
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --order asc")'
}

# --------------------------------------------------------------------- }}}
# Parse arguments {{{
# --------------------------------------------------------------------- {|}
Expand Down Expand Up @@ -445,6 +506,7 @@ main() {
p | -p | pr | prs | --pr | --prs) pr_cmd "$@" ;;
r | -r | run | runs | --run | --runs) run_cmd "$@" ;;
repo | repos | --repo | --repos) repo_cmd "$@" ;;
release | releases | --release | --releases) release_cmd "$@" ;;
v | V | -v | -V | version | --version) printf "%s\n" "$GH_FZF_VERSION" ;;
*) error "invalid command: \"$command\"" ;;
esac
Expand Down