diff --git a/.gitignore b/.gitignore index e62860e..c1be013 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Cargo.lock b/Cargo.lock index 758ef55..a4cab52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,15 +61,6 @@ dependencies = [ "typeid", ] -[[package]] -name = "gh-actions-rust" -version = "0.0.1" -dependencies = [ - "mlua", - "serde", - "serde_yaml", -] - [[package]] name = "hashbrown" version = "0.15.1" @@ -195,6 +186,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "pipeline_native" +version = "0.0.1" +dependencies = [ + "mlua", + "serde", + "serde_yaml", +] + [[package]] name = "pkg-config" version = "0.3.31" diff --git a/Cargo.toml b/Cargo.toml index 95f33b0..fc14f74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = 'gh-actions-rust' +name = 'pipeline_native' version = '0.0.1' edition = '2021' @@ -7,6 +7,6 @@ edition = '2021' 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" diff --git a/Makefile b/Makefile index 8e343ec..7dd872d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 8a37910..e8940ad 100644 --- a/README.md +++ b/README.md @@ -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.

- Screenshot of gh-actions + Screenshot of pipeline.nvim

## Features @@ -61,15 +61,15 @@ 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 @@ -77,7 +77,7 @@ The following keybindings are provided by the plugin: ### 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 { diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 5c8d9e0..0000000 --- a/TODO.md +++ /dev/null @@ -1,9 +0,0 @@ -# TODO - -1. ~Map github responses to internal data structures~ -2. ~Update render to use the new data structures~ -3. Move highlight and icon mapping into provider -4. ~Move github specific code from `init.lua` into provider~ -5. Implement Gitlab Provider -6. Rename anything gh-actions related to pipeline.nvim -7. Rename types from GhActions to pipeline.\* diff --git a/lazy.lua b/lazy.lua index c9e575b..d76df74 100644 --- a/lazy.lua +++ b/lazy.lua @@ -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, }, } diff --git a/lua/gh-actions/command.lua b/lua/gh-actions/command.lua deleted file mode 100644 index 1291750..0000000 --- a/lua/gh-actions/command.lua +++ /dev/null @@ -1,32 +0,0 @@ -local M = {} - -local function handle_gh_actions_command(a) - local gha = require('gh-actions') - - local action = a.fargs[1] or 'toggle' - - if action == 'open' then - return gha.open() - elseif action == 'close' then - return gha.close() - elseif action == 'toggle' then - return gha.toggle() - end -end - -local function completion_customlist() - return { - 'open', - 'close', - 'toggle', - } -end - -function M.setup() - vim.api.nvim_create_user_command('GhActions', handle_gh_actions_command, { - nargs = '?', - complete = completion_customlist, - }) -end - -return M diff --git a/lua/gh-actions/init.lua b/lua/gh-actions/init.lua index 9437e66..7ae8fae 100644 --- a/lua/gh-actions/init.lua +++ b/lua/gh-actions/init.lua @@ -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 diff --git a/lua/lualine/components/pipeline.lua b/lua/lualine/components/pipeline.lua index 4b29190..49d6343 100644 --- a/lua/lualine/components/pipeline.lua +++ b/lua/lualine/components/pipeline.lua @@ -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 @@ -21,7 +21,7 @@ local default_options = { end, on_click = function() - require('gh-actions').toggle() + require('pipeline').toggle() end, } @@ -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() diff --git a/lua/pipeline/command.lua b/lua/pipeline/command.lua new file mode 100644 index 0000000..81ac07a --- /dev/null +++ b/lua/pipeline/command.lua @@ -0,0 +1,43 @@ +local M = {} + +local function handle_pipeline_command(a) + local pipeline = require('pipeline') + + if a.name == 'GhActions' then + vim.notify_once( + 'GhActions command is deprecated, use Pipeline instead', + vim.log.levels.WARN + ) + end + + local action = a.fargs[1] or 'toggle' + + if action == 'open' then + return pipeline.open() + elseif action == 'close' then + return pipeline.close() + elseif action == 'toggle' then + return pipeline.toggle() + end +end + +local function completion_customlist() + return { + 'open', + 'close', + 'toggle', + } +end + +function M.setup() + vim.api.nvim_create_user_command('Pipeline', handle_pipeline_command, { + nargs = '?', + complete = completion_customlist, + }) + vim.api.nvim_create_user_command('GhActions', handle_pipeline_command, { + nargs = '?', + complete = completion_customlist, + }) +end + +return M diff --git a/lua/gh-actions/config.lua b/lua/pipeline/config.lua similarity index 73% rename from lua/gh-actions/config.lua rename to lua/pipeline/config.lua index a4f499f..397f6cf 100644 --- a/lua/gh-actions/config.lua +++ b/lua/pipeline/config.lua @@ -41,37 +41,37 @@ local defaultConfig = { ---@class pipeline.config.Highlights highlights = { ---@type vim.api.keyset.highlight - GhActionsRunIconSuccess = { link = 'LspDiagnosticsVirtualTextHint' }, + PipelineRunIconSuccess = { link = 'LspDiagnosticsVirtualTextHint' }, ---@type vim.api.keyset.highlight - GhActionsRunIconFailure = { link = 'LspDiagnosticsVirtualTextError' }, + PipelineRunIconFailure = { link = 'LspDiagnosticsVirtualTextError' }, ---@type vim.api.keyset.highlight - GhActionsRunIconStartup_failure = { + PipelineRunIconStartup_failure = { link = 'LspDiagnosticsVirtualTextError', }, ---@type vim.api.keyset.highlight - GhActionsRunIconPending = { link = 'LspDiagnosticsVirtualTextWarning' }, + PipelineRunIconPending = { link = 'LspDiagnosticsVirtualTextWarning' }, ---@type vim.api.keyset.highlight - GhActionsRunIconRequested = { link = 'LspDiagnosticsVirtualTextWarning' }, + PipelineRunIconRequested = { link = 'LspDiagnosticsVirtualTextWarning' }, ---@type vim.api.keyset.highlight - GhActionsRunIconWaiting = { link = 'LspDiagnosticsVirtualTextWarning' }, + PipelineRunIconWaiting = { link = 'LspDiagnosticsVirtualTextWarning' }, ---@type vim.api.keyset.highlight - GhActionsRunIconIn_progress = { link = 'LspDiagnosticsVirtualTextWarning' }, + PipelineRunIconIn_progress = { link = 'LspDiagnosticsVirtualTextWarning' }, ---@type vim.api.keyset.highlight - GhActionsRunIconCancelled = { link = 'Comment' }, + PipelineRunIconCancelled = { link = 'Comment' }, ---@type vim.api.keyset.highlight - GhActionsRunIconSkipped = { link = 'Comment' }, + PipelineRunIconSkipped = { link = 'Comment' }, ---@type vim.api.keyset.highlight - GhActionsRunCancelled = { link = 'Comment' }, + PipelineRunCancelled = { link = 'Comment' }, ---@type vim.api.keyset.highlight - GhActionsRunSkipped = { link = 'Comment' }, + PipelineRunSkipped = { link = 'Comment' }, ---@type vim.api.keyset.highlight - GhActionsJobCancelled = { link = 'Comment' }, + PipelineJobCancelled = { link = 'Comment' }, ---@type vim.api.keyset.highlight - GhActionsJobSkipped = { link = 'Comment' }, + PipelineJobSkipped = { link = 'Comment' }, ---@type vim.api.keyset.highlight - GhActionsStepCancelled = { link = 'Comment' }, + PipelineStepCancelled = { link = 'Comment' }, ---@type vim.api.keyset.highlight - GhActionsStepSkipped = { link = 'Comment' }, + PipelineStepSkipped = { link = 'Comment' }, }, ---@type nui_split_options split = { diff --git a/lua/gh-actions/git.lua b/lua/pipeline/git.lua similarity index 100% rename from lua/gh-actions/git.lua rename to lua/pipeline/git.lua diff --git a/lua/gh-actions/health.lua b/lua/pipeline/health.lua similarity index 74% rename from lua/gh-actions/health.lua rename to lua/pipeline/health.lua index 6a664d9..b0fc737 100644 --- a/lua/gh-actions/health.lua +++ b/lua/pipeline/health.lua @@ -5,7 +5,7 @@ function M.check() health.start('Checking ability to parse yaml files') - local has_native_module = pcall(require, 'gh_actions_native.yaml') + local has_native_module = pcall(require, 'pipeline_native.yaml') if has_native_module then health.ok('Found native module') @@ -27,8 +27,8 @@ function M.check() health.error('No yaml parser found') end - require('gh-actions.providers.github.rest.health').check() - require('gh-actions.providers.gitlab.graphql.health').check() + require('pipeline.providers.github.rest.health').check() + require('pipeline.providers.gitlab.graphql.health').check() end return M diff --git a/lua/pipeline/init.lua b/lua/pipeline/init.lua new file mode 100644 index 0000000..4f1434e --- /dev/null +++ b/lua/pipeline/init.lua @@ -0,0 +1,156 @@ +local M = { + init_root = '', +} + +---@param opts? pipeline.Config +function M.setup(opts) + opts = opts or {} + + M.init_root = vim.fn.getcwd() + + require('pipeline.config').setup(opts) + require('pipeline.ui').setup() + require('pipeline.command').setup() + + M.setup_provider() +end + +function M.setup_provider() + if M.pipeline then + return + end + + local config = require('pipeline.config') + local store = require('pipeline.store') + + M.pipeline = require('pipeline.providers.provider'):new(config.options, store) + for provider, provider_options in pairs(config.options.providers) do + local Provider = require('pipeline.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 pipeline.State +function M.update_workflow_configs(state) + local gh_utils = require('pipeline.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('pipeline.utils').open(pipeline_object.url) +end + +function M.open() + local ui = require('pipeline.ui') + local store = require('pipeline.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('pipeline.ui') + local store = require('pipeline.store') + + ui.close() + M.stop_polling() + store.off_update(M.update_workflow_configs) +end + +function M.toggle() + local ui = require('pipeline.ui') + + if ui.split.winid then + return M.close() + else + return M.open() + end +end + +return M diff --git a/lua/gh-actions/providers/github/rest/_api.lua b/lua/pipeline/providers/github/rest/_api.lua similarity index 99% rename from lua/gh-actions/providers/github/rest/_api.lua rename to lua/pipeline/providers/github/rest/_api.lua index 4557523..a997efc 100644 --- a/lua/gh-actions/providers/github/rest/_api.lua +++ b/lua/pipeline/providers/github/rest/_api.lua @@ -1,5 +1,5 @@ function gh_utils() - return require('gh-actions.providers.github.utils') + return require('pipeline.providers.github.utils') end ---@class pipeline.providers.github.rest.Api diff --git a/lua/gh-actions/providers/github/rest/_mapper.lua b/lua/pipeline/providers/github/rest/_mapper.lua similarity index 90% rename from lua/gh-actions/providers/github/rest/_mapper.lua rename to lua/pipeline/providers/github/rest/_mapper.lua index c2d5077..db362c4 100644 --- a/lua/gh-actions/providers/github/rest/_mapper.lua +++ b/lua/pipeline/providers/github/rest/_mapper.lua @@ -4,8 +4,8 @@ local M = {} ---By default the workflow.html_url points to the workflow definition file. ---We want to jump to the UI of all the workflow runs instead. ---Example: ---- input: https://github.com/topaxi/gh-actions.nvim/blob/main/.github/workflows/dispatch-echo.yaml ---- output: https://github.com/topaxi/gh-actions.nvim/actions/workflows/dispatch-echo.yaml +--- input: https://github.com/topaxi/pipeline.nvim/blob/main/.github/workflows/dispatch-echo.yaml +--- output: https://github.com/topaxi/pipeline.nvim/actions/workflows/dispatch-echo.yaml ---@param workflow GhWorkflow local function workflow_url(workflow) return workflow.html_url:gsub('blob/main/%.github', 'actions') diff --git a/lua/gh-actions/providers/github/rest/health.lua b/lua/pipeline/providers/github/rest/health.lua similarity index 77% rename from lua/gh-actions/providers/github/rest/health.lua rename to lua/pipeline/providers/github/rest/health.lua index 7c99f05..14f1489 100644 --- a/lua/gh-actions/providers/github/rest/health.lua +++ b/lua/pipeline/providers/github/rest/health.lua @@ -6,7 +6,7 @@ function M.check() health.start('Github REST provider') local k, token = - pcall(require('gh-actions.providers.github.utils').get_github_token) + pcall(require('pipeline.providers.github.utils').get_github_token) if k and token then health.ok('Found GitHub token') diff --git a/lua/gh-actions/providers/github/rest/init.lua b/lua/pipeline/providers/github/rest/init.lua similarity index 90% rename from lua/gh-actions/providers/github/rest/init.lua rename to lua/pipeline/providers/github/rest/init.lua index 67e981c..8e01c2a 100644 --- a/lua/gh-actions/providers/github/rest/init.lua +++ b/lua/pipeline/providers/github/rest/init.lua @@ -1,12 +1,12 @@ -local utils = require('gh-actions.utils') -local Provider = require('gh-actions.providers.provider') +local utils = require('pipeline.utils') +local Provider = require('pipeline.providers.provider') local function git() - return require('gh-actions.git') + return require('pipeline.git') end local function gh_api() - return require('gh-actions.providers.github.rest._api') + return require('pipeline.providers.github.rest._api') end ---@class pipeline.providers.github.rest.Options @@ -26,7 +26,7 @@ function GithubRestProvider.detect() return false end - local config = require('gh-actions.config') + local config = require('pipeline.config') local server, repo = git().get_current_repository() if not config.is_host_allowed(server) then @@ -58,7 +58,7 @@ end --TODO Maybe send lsp progress events when fetching, to interact -- with fidget.nvim function GithubRestProvider:fetch() - local Mapper = require('gh-actions.providers.github.rest._mapper') + local Mapper = require('pipeline.providers.github.rest._mapper') gh_api().get_workflows(self.server, self.repo, { callback = function(workflows) @@ -116,7 +116,7 @@ function GithubRestProvider:dispatch(pipeline) return end - local store = require('gh-actions.store') + local store = require('pipeline.store') if pipeline then local server = store.get_state().server @@ -124,10 +124,10 @@ function GithubRestProvider:dispatch(pipeline) -- TODO should we get current ref instead or show an input with the -- default branch or current ref preselected? - local default_branch = require('gh-actions.git').get_default_branch() + local default_branch = require('pipeline.git').get_default_branch() ---@type pipeline.providers.github.WorkflowDef|nil local workflow_config = - require('gh-actions.yaml').read_yaml_file(pipeline.meta.workflow_path) + require('pipeline.yaml').read_yaml_file(pipeline.meta.workflow_path) if not workflow_config or not workflow_config.on.workflow_dispatch then return @@ -169,7 +169,7 @@ function GithubRestProvider:dispatch(pipeline) { callback = function(workflow_runs) local Mapper = - require('gh-actions.providers.github.rest._mapper') + require('pipeline.providers.github.rest._mapper') local runs = vim.tbl_map(Mapper.to_run, workflow_runs) store.update_state(function(state) @@ -212,7 +212,7 @@ function GithubRestProvider:dispatch(pipeline) local prompt = string.format('%s: ', input.description or name) if input.type == 'choice' then - local question = require('gh-actions.ui.components.select') { + local question = require('pipeline.ui.components.select') { prompt = prompt, title = pipeline.name, options = input.options, @@ -228,7 +228,7 @@ function GithubRestProvider:dispatch(pipeline) table.insert(questions, question) else - local question = require('gh-actions.ui.components.input') { + local question = require('pipeline.ui.components.input') { prompt = prompt, title = pipeline.name, default_value = input.default, diff --git a/lua/gh-actions/providers/github/types.lua b/lua/pipeline/providers/github/types.lua similarity index 100% rename from lua/gh-actions/providers/github/types.lua rename to lua/pipeline/providers/github/types.lua diff --git a/lua/gh-actions/providers/github/utils.lua b/lua/pipeline/providers/github/utils.lua similarity index 96% rename from lua/gh-actions/providers/github/utils.lua rename to lua/pipeline/providers/github/utils.lua index a86645c..4c3e28c 100644 --- a/lua/gh-actions/providers/github/utils.lua +++ b/lua/pipeline/providers/github/utils.lua @@ -45,7 +45,7 @@ end function M.get_workflow_config(path) path = vim.fn.expand(path) - local utils = require('gh-actions.utils') + local utils = require('pipeline.utils') local workflow_yaml = utils.read_file(path) or '' local config = { on = { diff --git a/lua/gh-actions/providers/gitlab/graphql/_api.lua b/lua/pipeline/providers/gitlab/graphql/_api.lua similarity index 100% rename from lua/gh-actions/providers/gitlab/graphql/_api.lua rename to lua/pipeline/providers/gitlab/graphql/_api.lua diff --git a/lua/gh-actions/providers/gitlab/graphql/_mapper.lua b/lua/pipeline/providers/gitlab/graphql/_mapper.lua similarity index 100% rename from lua/gh-actions/providers/gitlab/graphql/_mapper.lua rename to lua/pipeline/providers/gitlab/graphql/_mapper.lua diff --git a/lua/gh-actions/providers/gitlab/graphql/health.lua b/lua/pipeline/providers/gitlab/graphql/health.lua similarity index 100% rename from lua/gh-actions/providers/gitlab/graphql/health.lua rename to lua/pipeline/providers/gitlab/graphql/health.lua diff --git a/lua/gh-actions/providers/gitlab/graphql/init.lua b/lua/pipeline/providers/gitlab/graphql/init.lua similarity index 81% rename from lua/gh-actions/providers/gitlab/graphql/init.lua rename to lua/pipeline/providers/gitlab/graphql/init.lua index 981b544..2f0d097 100644 --- a/lua/gh-actions/providers/gitlab/graphql/init.lua +++ b/lua/pipeline/providers/gitlab/graphql/init.lua @@ -1,12 +1,12 @@ -local utils = require('gh-actions.utils') -local Provider = require('gh-actions.providers.provider') +local utils = require('pipeline.utils') +local Provider = require('pipeline.providers.provider') local function git() - return require('gh-actions.git') + return require('pipeline.git') end local function glab_api() - return require('gh-actions.providers.gitlab.graphql._api') + return require('pipeline.providers.gitlab.graphql._api') end ---@class pipeline.providers.gitlab.graphql.Options @@ -26,7 +26,7 @@ function GitlabGraphQLProvider.detect() return false end - local config = require('gh-actions.config') + local config = require('pipeline.config') local server, repo = git().get_current_repository() if not config.is_host_allowed(server) then @@ -52,7 +52,7 @@ function GitlabGraphQLProvider:init(opts) end function GitlabGraphQLProvider:fetch() - local Mapper = require('gh-actions.providers.gitlab.graphql._mapper') + local Mapper = require('pipeline.providers.gitlab.graphql._mapper') glab_api().get_project_pipelines(self.repo, 10, function(response) if @@ -98,17 +98,11 @@ function GitlabGraphQLProvider:dispatch(pipeline) return end - local store = require('gh-actions.store') - if pipeline then - local server = store.get_state().server - local repo = store.get_state().repo - - local default_branch = require('gh-actions.git').get_default_branch() - local ci_config = - require('gh-actions.yaml').read_yaml_file(pipeline.meta.ci_config_path) - - -- TODO + vim.notify( + 'Gitlab Pipeline dispatch is not yet implemented', + vim.log.levels.INFO + ) end end diff --git a/lua/gh-actions/providers/init.lua b/lua/pipeline/providers/init.lua similarity index 81% rename from lua/gh-actions/providers/init.lua rename to lua/pipeline/providers/init.lua index ed5a5e5..34e4234 100644 --- a/lua/gh-actions/providers/init.lua +++ b/lua/pipeline/providers/init.lua @@ -7,7 +7,7 @@ local providers = { ---@field github pipeline.providers.github.rest.Provider local M = setmetatable({}, { __index = function(_, key) - return require('gh-actions.providers.' .. providers[key]) + return require('pipeline.providers.' .. providers[key]) end, }) diff --git a/lua/gh-actions/providers/provider.lua b/lua/pipeline/providers/provider.lua similarity index 97% rename from lua/gh-actions/providers/provider.lua rename to lua/pipeline/providers/provider.lua index 987f124..6093200 100644 --- a/lua/gh-actions/providers/provider.lua +++ b/lua/pipeline/providers/provider.lua @@ -25,7 +25,7 @@ ---@class pipeline.Provider ---@field protected config pipeline.Config ----@field protected store GhActionsStore +---@field protected store pipeline.Store ---@field private listener_count integer local Provider = {} @@ -44,7 +44,7 @@ end ---@generic T: pipeline.Provider ---@param config pipeline.Config ----@param store GhActionsStore +---@param store pipeline.Store ---@param opts? table ---@return self function Provider:new(config, store, opts) diff --git a/lua/gh-actions/providers/types.lua b/lua/pipeline/providers/types.lua similarity index 100% rename from lua/gh-actions/providers/types.lua rename to lua/pipeline/providers/types.lua diff --git a/lua/gh-actions/store.lua b/lua/pipeline/store.lua similarity index 70% rename from lua/gh-actions/store.lua rename to lua/pipeline/store.lua index 07a67ad..e9ed5b2 100644 --- a/lua/gh-actions/store.lua +++ b/lua/pipeline/store.lua @@ -1,10 +1,10 @@ -local utils = require('gh-actions.utils') +local utils = require('pipeline.utils') ----@class GhActionsStateWorkflowConfig +---@class pipeline.StatePipelineConfig ---@field last_read integer ---@field config table ----@class GhActionsState +---@class pipeline.State ---@field title string ---@field repo string ---@field server string @@ -12,7 +12,7 @@ local utils = require('gh-actions.utils') ---@field runs table Runs indexed by pipeline id ---@field jobs table Jobs indexed by run id ---@field steps table Steps indexed by job id ----@field workflow_configs table +---@field workflow_configs table local initialState = { title = 'pipeline.nvim', repo = '', @@ -25,15 +25,15 @@ local initialState = { workflow_configs = {}, } ----@class GhActionsStore ----@field package _state GhActionsState ----@field package _update fun(state: GhActionsState)[] +---@class pipeline.Store +---@field package _state pipeline.State +---@field package _update fun(state: pipeline.State)[] local M = { _state = initialState, _update = {}, } ----@param state GhActionsState +---@param state pipeline.State local function emit_update(state) for _, update in ipairs(M._update) do update(state) @@ -42,26 +42,26 @@ end emit_update = utils.debounced(vim.schedule_wrap(emit_update)) ----@param fn fun(render_state: GhActionsState): GhActionsState|nil +---@param fn fun(render_state: pipeline.State): pipeline.State|nil function M.update_state(fn) M._state = fn(M._state) or M._state emit_update(M._state) end ----@param fn function +---@param fn function function M.on_update(fn) table.insert(M._update, fn) end ----@param fn function +---@param fn function function M.off_update(fn) M._update = vim.tbl_filter(function(f) return f ~= fn end, M._update) end ----@return GhActionsState +---@return pipeline.State function M.get_state() return M._state end diff --git a/lua/gh-actions/ui.lua b/lua/pipeline/ui.lua similarity index 88% rename from lua/gh-actions/ui.lua rename to lua/pipeline/ui.lua index 44f246d..ebb2541 100644 --- a/lua/gh-actions/ui.lua +++ b/lua/pipeline/ui.lua @@ -1,9 +1,9 @@ -local store = require('gh-actions.store') +local store = require('pipeline.store') local M = { ---@type NuiSplit split = nil, - ---@type GhActionsRender + ---@type pipeline.Render renderer = nil, } @@ -11,7 +11,7 @@ local function get_cursor_line(line) return line or vim.api.nvim_win_get_cursor(M.split.winid)[1] end ----@param kind GhActionsRenderLocationKind +---@param kind pipeline.RenderLocationKind ---@param line? integer local function get_location(kind, line) line = get_cursor_line(line) @@ -63,8 +63,8 @@ end function M.setup() local Split = require('nui.split') - local Config = require('gh-actions.config') - local Render = require('gh-actions.ui.render') + local Config = require('pipeline.config') + local Render = require('pipeline.ui.render') M.split = Split(Config.options.split) M.renderer = Render.new(store) diff --git a/lua/gh-actions/ui/buffer.lua b/lua/pipeline/ui/buffer.lua similarity index 98% rename from lua/gh-actions/ui/buffer.lua rename to lua/pipeline/ui/buffer.lua index 0c6ff66..175c968 100644 --- a/lua/gh-actions/ui/buffer.lua +++ b/lua/pipeline/ui/buffer.lua @@ -8,7 +8,7 @@ ---@field protected _lines Line[] ---@field protected _indent number local Buffer = { - ns = vim.api.nvim_create_namespace('gh-actions'), + ns = vim.api.nvim_create_namespace('pipeline.nvim'), } ---@param opts? { indent?: integer } diff --git a/lua/gh-actions/ui/components/input.lua b/lua/pipeline/ui/components/input.lua similarity index 100% rename from lua/gh-actions/ui/components/input.lua rename to lua/pipeline/ui/components/input.lua diff --git a/lua/gh-actions/ui/components/select.lua b/lua/pipeline/ui/components/select.lua similarity index 100% rename from lua/gh-actions/ui/components/select.lua rename to lua/pipeline/ui/components/select.lua diff --git a/lua/gh-actions/ui/render.lua b/lua/pipeline/ui/render.lua similarity index 74% rename from lua/gh-actions/ui/render.lua rename to lua/pipeline/ui/render.lua index 4ea1fe6..22af12e 100644 --- a/lua/gh-actions/ui/render.lua +++ b/lua/pipeline/ui/render.lua @@ -1,25 +1,25 @@ -local Config = require('gh-actions.config') -local Buffer = require('gh-actions.ui.buffer') -local utils = require('gh-actions.utils') +local Config = require('pipeline.config') +local Buffer = require('pipeline.ui.buffer') +local utils = require('pipeline.utils') ---TODO: Shade background like https://github.com/akinsho/toggleterm.nvim/blob/2e477f7ee8ee8229ff3158e3018a067797b9cd38/lua/toggleterm/colors.lua ----@alias GhActionsRenderLocationKind 'pipeline'|'run'|'job'|'step' +---@alias pipeline.RenderLocationKind 'pipeline'|'run'|'job'|'step' ----@class GhActionsRenderLocation +---@class pipeline.RenderLocation ---@field value any ----@field kind GhActionsRenderLocationKind +---@field kind pipeline.RenderLocationKind ---@field from? integer ---@field to? integer ----@class GhActionsRender:Buffer ----@field store { get_state: fun(): GhActionsState } ----@field locations GhActionsRenderLocation[] -local GhActionsRender = { +---@class pipeline.Render:Buffer +---@field store { get_state: fun(): pipeline.State } +---@field locations pipeline.RenderLocation[] +local PipelineRender = { locations = {}, } -setmetatable(GhActionsRender, { __index = Buffer }) +setmetatable(PipelineRender, { __index = Buffer }) ---@param run { status: string, conclusion: string } ---@return string @@ -45,21 +45,21 @@ local function get_status_highlight(run, prefix) end if run.status == 'completed' then - return 'GhActions' + return 'Pipeline' .. utils.string.upper_first(prefix) .. utils.string.upper_first(run.conclusion) end - return 'GhActions' + return 'Pipeline' .. utils.string.upper_first(prefix) .. utils.string.upper_first(run.status) end ----@param store { get_state: fun(): GhActionsState } ----@return GhActionsRender -function GhActionsRender.new(store) +---@param store { get_state: fun(): pipeline.State } +---@return pipeline.Render +function PipelineRender.new(store) local self = setmetatable({}, { - __index = GhActionsRender, + __index = PipelineRender, }) Buffer.init(self, { indent = Config.options.indent }) @@ -70,7 +70,7 @@ function GhActionsRender.new(store) end ---@param bufnr integer -function GhActionsRender:render(bufnr) +function PipelineRender:render(bufnr) self._lines = {} self.locations = {} @@ -84,23 +84,23 @@ function GhActionsRender:render(bufnr) end --- Render title of the split window ----@param state GhActionsState -function GhActionsRender:title(state) +---@param state pipeline.State +function PipelineRender:title(state) self:append(state.title):nl():nl() end --- Render each pipeline ----@param state GhActionsState -function GhActionsRender:pipelines(state) +---@param state pipeline.State +function PipelineRender:pipelines(state) for _, pipeline in ipairs(state.pipelines) do self:pipeline(state, pipeline, state.runs[pipeline.pipeline_id] or {}) end end ----@param state GhActionsState +---@param state pipeline.State ---@param pipeline pipeline.Pipeline ---@param runs pipeline.Run[] -function GhActionsRender:pipeline(state, pipeline, runs) +function PipelineRender:pipeline(state, pipeline, runs) self:with_location({ kind = 'pipeline', value = pipeline }, function() local runs_n = math.min(5, #runs) @@ -128,9 +128,9 @@ function GhActionsRender:pipeline(state, pipeline, runs) end end ----@param state GhActionsState +---@param state pipeline.State ---@param run pipeline.Run -function GhActionsRender:run(state, run) +function PipelineRender:run(state, run) self:with_location({ kind = 'run', value = run }, function() self :status_icon(run, { indent = 1 }) @@ -146,9 +146,9 @@ function GhActionsRender:run(state, run) end) end ----@param state GhActionsState +---@param state pipeline.State ---@param job pipeline.Job -function GhActionsRender:job(state, job) +function PipelineRender:job(state, job) self:with_location({ kind = 'job', value = job }, function() self :status_icon(job, { indent = 2 }) @@ -165,7 +165,7 @@ function GhActionsRender:job(state, job) end ---@param step pipeline.Step -function GhActionsRender:step(step) +function PipelineRender:step(step) self:with_location({ kind = 'step', value = step }, function() self :status_icon(step, { indent = 3 }) @@ -177,7 +177,7 @@ end ---@param status { status: string, conclusion: string } ---@param opts? { indent?: number | nil } -function GhActionsRender:status_icon(status, opts) +function PipelineRender:status_icon(status, opts) opts = opts or {} self:append( @@ -189,17 +189,17 @@ function GhActionsRender:status_icon(status, opts) return self end ----@param location GhActionsRenderLocation -function GhActionsRender:append_location(location) +---@param location pipeline.RenderLocation +function PipelineRender:append_location(location) table.insert( self.locations, vim.tbl_extend('keep', location, { to = self:get_current_line_nr() - 1 }) ) end ----@param kind GhActionsRenderLocationKind +---@param kind pipeline.RenderLocationKind ---@param line integer -function GhActionsRender:get_location(kind, line) +function PipelineRender:get_location(kind, line) for _, loc in ipairs(self.locations) do if loc.kind == kind and line >= loc.from and line <= loc.to then return loc.value @@ -207,9 +207,9 @@ function GhActionsRender:get_location(kind, line) end end ----@param location GhActionsRenderLocation +---@param location pipeline.RenderLocation ---@param fn fun() -function GhActionsRender:with_location(location, fn) +function PipelineRender:with_location(location, fn) local start_line_nr = self:get_current_line_nr() fn() @@ -219,4 +219,4 @@ function GhActionsRender:with_location(location, fn) ) end -return GhActionsRender +return PipelineRender diff --git a/lua/gh-actions/utils.lua b/lua/pipeline/utils.lua similarity index 94% rename from lua/gh-actions/utils.lua rename to lua/pipeline/utils.lua index f73aa36..615e613 100644 --- a/lua/gh-actions/utils.lua +++ b/lua/pipeline/utils.lua @@ -1,4 +1,4 @@ -local stringUtils = require('gh-actions.utils.string') +local stringUtils = require('pipeline.utils.string') local M = { string = stringUtils, @@ -105,7 +105,7 @@ function M.open(uri) return M.float { style = '', file = uri } end - local Config = require('gh-actions.config') + local Config = require('pipeline.config') local cmd if Config.options.browser then @@ -141,7 +141,7 @@ end function M.is_nil(value) return value == nil or value == vim.NIL - or require('gh-actions.yaml').is_yaml_nil(value) + or require('pipeline.yaml').is_yaml_nil(value) end return M diff --git a/lua/gh-actions/utils/icons.lua b/lua/pipeline/utils/icons.lua similarity index 93% rename from lua/gh-actions/utils/icons.lua rename to lua/pipeline/utils/icons.lua index 9d38929..57df520 100644 --- a/lua/gh-actions/utils/icons.lua +++ b/lua/pipeline/utils/icons.lua @@ -1,5 +1,5 @@ local function Config() - return require('gh-actions.config') + return require('pipeline.config') end local M = {} diff --git a/lua/gh-actions/utils/string.lua b/lua/pipeline/utils/string.lua similarity index 100% rename from lua/gh-actions/utils/string.lua rename to lua/pipeline/utils/string.lua diff --git a/lua/gh-actions/yaml.lua b/lua/pipeline/yaml.lua similarity index 83% rename from lua/gh-actions/yaml.lua rename to lua/pipeline/yaml.lua index 41f8c4d..0ad0eb9 100644 --- a/lua/gh-actions/yaml.lua +++ b/lua/pipeline/yaml.lua @@ -1,5 +1,5 @@ -local utils = require('gh-actions.utils') -local has_native_module, native_yaml = pcall(require, 'gh_actions_native.yaml') +local utils = require('pipeline.utils') +local has_native_module, native_yaml = pcall(require, 'pipeline_native.yaml') local M = {} diff --git a/lua/gh_actions_native/.gitkeep b/lua/pipeline_native/.gitkeep similarity index 100% rename from lua/gh_actions_native/.gitkeep rename to lua/pipeline_native/.gitkeep diff --git a/lua/gh_actions_native/yaml.meta.lua b/lua/pipeline_native/yaml.meta.lua similarity index 84% rename from lua/gh_actions_native/yaml.meta.lua rename to lua/pipeline_native/yaml.meta.lua index f0f1e8c..2bd405e 100644 --- a/lua/gh_actions_native/yaml.meta.lua +++ b/lua/pipeline_native/yaml.meta.lua @@ -1,4 +1,4 @@ ----@meta gh_actions_native.yaml +---@meta pipeline_native.yaml --# selene: allow(unused_variable) local M = {} diff --git a/src/lib.rs b/src/lib.rs index 7a48950..6a1f613 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ fn yaml_to_lua(lua: &Lua, yamlstr: String) -> LuaResult { } #[mlua::lua_module] -fn gh_actions_native_yaml(lua: &Lua) -> LuaResult { +fn pipeline_native_yaml(lua: &Lua) -> LuaResult { let exports = lua.create_table()?; exports.set("NIL", lua.null())?; diff --git a/tests/github_spec.lua b/tests/github_spec.lua index b8d1e86..85d6f77 100644 --- a/tests/github_spec.lua +++ b/tests/github_spec.lua @@ -1,5 +1,5 @@ describe('get_github_token', function() - local gh = require('gh-actions.providers.github.utils') + local gh = require('pipeline.providers.github.utils') before_each(function() vim.env.GITHUB_TOKEN = nil diff --git a/tests/utils_spec.lua b/tests/utils_spec.lua index 86a5832..9c67eb8 100644 --- a/tests/utils_spec.lua +++ b/tests/utils_spec.lua @@ -1,13 +1,16 @@ -local utils = require("gh-actions.utils") +local utils = require('pipeline.utils') -describe("uniq", function() - it("it remove duplicate values from table", function() +describe('uniq', function() + it('it remove duplicate values from table', function() local list = { { id = 1 }, { id = 1 }, { id = 2 }, { id = 1 }, { id = 3 } } local function get_id(li) return li.id end - assert.are.same(utils.uniq(get_id, list), { { id = 1 }, { id = 2 }, { id = 3 } }) + assert.are.same( + utils.uniq(get_id, list), + { { id = 1 }, { id = 2 }, { id = 3 } } + ) end) end)