Skip to content

Commit

Permalink
refactor: rename gh-actions.nvim to pipeline.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
topaxi committed Nov 20, 2024
1 parent e6b066f commit 5af0209
Show file tree
Hide file tree
Showing 43 changed files with 363 additions and 349 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lua/gh_actions_native/deps
lua/gh_actions_native/yaml.so
lua/pipeline_native/deps
lua/pipeline_native/yaml.so

target

Expand Down
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = 'gh-actions-rust'
name = 'pipeline_native'
version = '0.0.1'
edition = '2021'

[lib]
crate-type = ["cdylib"]

[dependencies]
mlua = {version = "0.10", features = ["luajit", "module", "serialize"]}
mlua = { version = "0.10", features = ["luajit", "module", "serialize"] }
serde = "1.0"
serde_yaml = "0.9"
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
all: build copy

clean:
rm -rf ./lua/gh_actions_native/yaml.so ./lua/gh_actions_native/deps
rm -rf ./lua/pipeline_native/yaml.so ./lua/pipeline_native/deps

depsdir:
mkdir -p ./lua/gh_actions_native/deps
mkdir -p ./lua/pipeline_native/deps

build:
cargo build --release

copy: clean depsdir
cp ./target/release/libgh_actions_rust.dylib ./lua/gh_actions_native/yaml.so || true
cp ./target/release/libgh_actions_rust.so ./lua/gh_actions_native/yaml.so || true
cp ./target/release/deps/*.rlib ./lua/gh_actions_native/deps/
cp ./target/release/libpipeline_rust.dylib ./lua/pipeline_native/yaml.so || true
cp ./target/release/libpipeline_rust.so ./lua/pipeline_native/yaml.so || true
cp ./target/release/deps/*.rlib ./lua/pipeline_native/deps/

plugin_dir := ./.tests/site/pack/deps/start
plugins := $(plugin_dir)/plenary.nvim $(plugin_dir)/nui.nvim
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The pipeline.nvim plugin for Neovim allows developers to easily manage and dispatch their CI/CD Pipelines, like GitHub Actions or Gitlab CI, directly from within the editor.

<p align="center">
<img src="https://user-images.githubusercontent.com/213788/234685256-e915dc9c-1d79-4d64-b771-be1f736a203b.png" alt="Screenshot of gh-actions">
<img src="https://user-images.githubusercontent.com/213788/234685256-e915dc9c-1d79-4d64-b771-be1f736a203b.png" alt="Screenshot of pipeline.nvim">
</p>

## Features
Expand Down Expand Up @@ -61,23 +61,23 @@ The plugin interacts with Gitlab via the `glab` cli, all that is needed is being

### Commands

- `:Pipeline` or `:Pipeline toggle` toggles the `gh-actions` split
- `:Pipeline open` opens the `gh-actions` split
- `:Pipeline close` closes the `gh-actions` split
- `:Pipeline` or `:Pipeline toggle` toggles the `pipeline.nvim` split
- `:Pipeline open` opens the `pipeline.nvim` split
- `:Pipeline close` closes the `pipeline.nvim` split

### Keybindings

The following keybindings are provided by the plugin:

- `q` - closes the `gh-actions` the split
- `q` - closes the `pipeline.nvim` the split
- `gp` - open the pipeline below the cursor on GitHub
- `gr` - open the run below the cursor on GitHub
- `gj` - open the job of the workflow run below the cursor on GitHub
- `d` - dispatch a new run for the workflow below the cursor on GitHub

### Options

The default options (as defined in [lua/config.lua](./blob/main/lua/gh-actions/config.lua))
The default options (as defined in [lua/config.lua](./blob/main/lua/pipeline/config.lua))

```lua
{
Expand Down
9 changes: 0 additions & 9 deletions TODO.md

This file was deleted.

9 changes: 6 additions & 3 deletions lazy.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
return {
{ 'nvim-lua/plenary.nvim', lazy = true },
{ 'MunifTanjim/nui.nvim', lazy = true },
{ 'MunifTanjim/nui.nvim', lazy = true },
{
'topaxi/gh-actions.nvim',
cmd = 'GhActions',
'topaxi/pipeline.nvim',
cmd = { 'Pipeline', 'GhActions' },
lazy = true,
dependencies = { 'nvim-lua/plenary.nvim', 'MunifTanjim/nui.nvim' },
opts = {},
config = function(_, opts)
require('pipeline').setup(opts)
end,
},
}
32 changes: 0 additions & 32 deletions lua/gh-actions/command.lua

This file was deleted.

162 changes: 9 additions & 153 deletions lua/gh-actions/init.lua
Original file line number Diff line number Diff line change
@@ -1,157 +1,13 @@
local M = {
init_root = '',
}
local gha = setmetatable({}, { __index = require('pipeline') })

---@param opts? pipeline.Config
function M.setup(opts)
opts = opts or {}
---@override
function gha.setup(...)
vim.notify_once(
'topaxi/gh-actions.nvim is deprecated, use topaxi/pipeline.nvim instead',
vim.log.levels.WARN
)

M.init_root = vim.fn.getcwd()

require('gh-actions.config').setup(opts)
require('gh-actions.ui').setup()
require('gh-actions.command').setup()

M.setup_provider()
end

function M.setup_provider()
if M.pipeline then
return
end

local config = require('gh-actions.config')
local store = require('gh-actions.store')

M.pipeline =
require('gh-actions.providers.provider'):new(config.options, store)
for provider, provider_options in pairs(config.options.providers) do
local Provider = require('gh-actions.providers')[provider]

if Provider.detect() then
M.pipeline = Provider:new(config.options, store, provider_options)
end
end
end

function M.start_polling()
M.pipeline:listen()
end

function M.stop_polling()
M.pipeline:close()
end

local function now()
return os.time()
end

local WORKFLOW_CONFIG_CACHE_TTL_S = 10

---TODO We should run this after fetching the workflows instead of within the state update event
---@param state GhActionsState
function M.update_workflow_configs(state)
local gh_utils = require('gh-actions.providers.github.utils')
local n = now()

for _, pipeline in ipairs(state.pipelines) do
if
not state.workflow_configs[pipeline.pipeline_id]
or (n - state.workflow_configs[pipeline.pipeline_id].last_read)
> WORKFLOW_CONFIG_CACHE_TTL_S
then
state.workflow_configs[pipeline.pipeline_id] = {
last_read = n,
config = gh_utils.get_workflow_config(pipeline.meta.workflow_path),
}
end
end
end

---@param pipeline_object pipeline.PipelineObject|nil
local function open_pipeline_url(pipeline_object)
if not pipeline_object then
return
end

if type(pipeline_object.url) ~= 'string' or pipeline_object.url == '' then
return
end

require('gh-actions.utils').open(pipeline_object.url)
end

function M.open()
local ui = require('gh-actions.ui')
local store = require('gh-actions.store')

ui.open()
ui.split:map('n', 'q', M.close, { noremap = true })

ui.split:map('n', 'gp', function()
open_pipeline_url(ui.get_pipeline())
end, { noremap = true, desc = 'Open pipeline URL' })

ui.split:map('n', 'gw', function()
vim.notify(
'Keybind gw to jump to workflow is deprecated, use gp instead',
vim.log.levels.WARN
)

open_pipeline_url(ui.get_pipeline())
end, { noremap = true, desc = 'Open pipeline URL (deprecated)' })

ui.split:map('n', 'gr', function()
open_pipeline_url(ui.get_run())
end, { noremap = true, desc = 'Open pipeline run URL' })

ui.split:map('n', 'gj', function()
open_pipeline_url(ui.get_job())
end, { noremap = true, desc = 'Open pipeline job URL' })

ui.split:map('n', 'gs', function()
open_pipeline_url(ui.get_step())
end, { noremap = true, desc = 'Open pipeline step URL' })

ui.split:map('n', 'd', function()
M.pipeline:dispatch(ui.get_pipeline())
end, { noremap = true, desc = 'Dispatch pipeline run' })

ui.split:map('n', 'rr', function()
M.pipeline:retry(ui.get_run())
end, { noremap = true, desc = 'Retry pipeline run' })

ui.split:map('n', 'rj', function()
M.pipeline:retry(ui.get_job())
end, { noremap = true, desc = 'Retry pipeline job' })

ui.split:map('n', 'rs', function()
M.pipeline:retry(ui.get_step())
end, { noremap = true, desc = 'Retry pipeline step' })

M.start_polling()

--TODO: This might get called after rendering..
store.on_update(M.update_workflow_configs)
end

function M.close()
local ui = require('gh-actions.ui')
local store = require('gh-actions.store')

ui.close()
M.stop_polling()
store.off_update(M.update_workflow_configs)
end

function M.toggle()
local ui = require('gh-actions.ui')

if ui.split.winid then
return M.close()
else
return M.open()
end
require('pipeline').setup(...)
end

return M
return gha
12 changes: 6 additions & 6 deletions lua/lualine/components/pipeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local Component = require('lualine.component'):extend()
local default_options = {
icon = '',
---@param component pipeline.lualine.Component
---@param state GhActionsState
---@param state pipeline.State
---@return string
format = function(component, state)
local latest_run = state.latest_run
Expand All @@ -21,7 +21,7 @@ local default_options = {
end,

on_click = function()
require('gh-actions').toggle()
require('pipeline').toggle()
end,
}

Expand All @@ -32,16 +32,16 @@ function Component:init(options)

Component.super.init(self, self.options)

self.store = require('gh-actions.store')
self.icons = require('gh-actions.utils.icons')
self.store = require('pipeline.store')
self.icons = require('pipeline.utils.icons')

local server, repo = require('gh-actions.git').get_current_repository()
local server, repo = require('pipeline.git').get_current_repository()

if not server or not repo then
return
end

require('gh-actions').start_polling()
require('pipeline').start_polling()

self.store.on_update(function()
require('lualine').refresh()
Expand Down
Loading

0 comments on commit 5af0209

Please sign in to comment.