Skip to content

Commit

Permalink
feat: add workflow command (#13)
Browse files Browse the repository at this point in the history
Add a command for finding and viewing Github Action workflows.

  For more info, see `gh workflow list --help` and the readme:
  https://github.com/benelan/gh-fzf#workflow
  • Loading branch information
benelan committed Mar 7, 2024
1 parent e1f69fb commit 09e402b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 26 deletions.
72 changes: 48 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ An fzf wrapper around the GitHub CLI.
- [`issue`](#issue)
- [`pr`](#pr)
- [`run`](#run)
- [`repo`](#repo)
- [`workflow`](#workflow)
- [`release`](#release)
- [`repo`](#repo)
- [`gist`](#gist)
- [Configuration](#configuration)
- [Related projects](#related-projects)
Expand Down Expand Up @@ -170,7 +171,8 @@ that can be used with any `gh fzf` command:
(see `gh run rerun --help`)
- `alt-x`: Cancel the selected run
(see `gh run cancel --help`)
- `alt-p`: Open `gh fzf pr` filtered for the run's branch as head
- `alt-p`: Open `gh fzf pr` filtered for the selected run's branch as head
(see [`pr`](#pr))
- `alt-b`: Filter the list, showing runs from the current branch
- `alt-u`: Filter the list, showing runs triggered by you
- `alt-f`: Filter the list, showing failed runs
Expand All @@ -184,6 +186,49 @@ that can be used with any `gh fzf` command:
gh fzf r -b main -s failure
```

### `workflow`

- **Usage**: `gh fzf workflow [flags]`
- **Aliases**: `workflows`, `--workflow`, `--workflows`
- **Flags**: See `gh workflow list --help` for available options
- **Keybindings**:
- `enter`: Open `gh fzf run` filtered for the selected workflow
(see [`run`](#run))
- `alt-d`: Create a `workflow_dispatch` event for the selected workflow
(see `gh workflow run --help`)
- `alt-X`: Disable the selected workflow
(see `gh workflow disable --help`)
- `alt-E`: Enable the selected workflow
(see `gh workflow enable --help`)
- `alt-a`: Filter the list, showing all workflows (including disabled ones)
- **Examples**:
- Filter the initial list to show all workflows:
```sh
gh fzf workflow --all
```

### `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
```

### `repo`

- **Usage**: `gh fzf repo [flags]`
Expand Down Expand Up @@ -218,28 +263,6 @@ 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
```

### `gist`

- **Usage**: `gh fzf gist [flags]`
Expand Down Expand Up @@ -301,6 +324,7 @@ When adding or modifying fzf keybindings:
- the `<id>` for the `gist` command
- Use `{-1}` in place of:
- the `<run-id>` for the `run` command
- the `<workflow-id>` for the `workflow` 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
30 changes: 28 additions & 2 deletions gh-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ Core Commands:
issue Search for and interact with GitHub issues.
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.
workflow Search for and interact with GitHub Action workflows.
release Search for and interact with GitHub releases.
repo Search for and interact with GitHub repos.
gist Search for and interact with GitHub gists.
See \`gh <command> list --help\` for the flag options.
Expand Down Expand Up @@ -128,7 +129,7 @@ FZF_DEFAULT_OPTS='
# --------------------------------------------------------------------- {|}

default_cmd() {
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n%s\n' 'issue' 'pr' 'run' 'repo' 'release' 'gist'" \
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' issue pr run workflow release repo gist" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh help {}' \
--preview-window='right:75%,wrap' \
Expand Down Expand Up @@ -495,6 +496,30 @@ Filters > (alt-p: public) (alt-s: secret)
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --secret")'
}

# --------------------------------------------------------------------- }}}
# Command > workflow {{{
# --------------------------------------------------------------------- {|}

workflow_cmd() {
workflow_header='Actions > (enter: runs) (alt-d: dispatch) (alt-X: disable) (alt-E: enable)
> (ctrl-o: open url) (ctrl-r: reload)
Filters > (alt-a: all)
'

FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh workflow list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh workflow view --yaml {-1}' \
--header="$workflow_header" \
--bind="start:$on_start" \
--bind='ctrl-o:execute-silent(gh workflow view --web {-1})' \
--bind='enter:execute(gh fzf run --workflow {-1})' \
--bind='alt-d:execute(gh workflow run {-1})' \
--bind='alt-E:execute(gh workflow enable {-1})' \
--bind="alt-X:execute(gh workflow disable {-1})" \
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --all")'
}

# --------------------------------------------------------------------- }}}
# Parse arguments {{{
# --------------------------------------------------------------------- {|}
Expand Down Expand Up @@ -534,6 +559,7 @@ main() {
repo | repos | --repo | --repos) repo_cmd "$@" ;;
release | releases | --release | --releases) release_cmd "$@" ;;
gist | gists | --gist | --gists) gist_cmd "$@" ;;
workflow | workflows | --workflow | --workflows) workflow_cmd "$@" ;;
v | V | -v | -V | version | --version) printf "%s\n" "$GH_FZF_VERSION" ;;
*) error "invalid command: \"$command\"" ;;
esac
Expand Down

0 comments on commit 09e402b

Please sign in to comment.