Skip to content

Commit

Permalink
fix: allow gitlab.com by default
Browse files Browse the repository at this point in the history
  • Loading branch information
topaxi committed Dec 2, 2024
1 parent 89fe5a1 commit 78c4736
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 41 deletions.
1 change: 1 addition & 0 deletions lua/pipeline/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function M.setup(opts)
M.options = vim.tbl_deep_extend('force', defaultConfig, opts)
M.options.allowed_hosts = M.options.allowed_hosts or {}
table.insert(M.options.allowed_hosts, 'github.com')
table.insert(M.options.allowed_hosts, 'gitlab.com')
end

function M.is_host_allowed(host)
Expand Down
5 changes: 4 additions & 1 deletion lua/pipeline/providers/github/rest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ function GithubRestProvider:fetch()
---@type pipeline.Run[]
local runs = vim.tbl_map(Mapper.to_run, workflow_runs)
---@type pipeline.Run[]
local old_runs = vim.iter(vim.tbl_values(self.store.get_state().runs)):flatten():totable()
local old_runs = vim
.iter(vim.tbl_values(self.store.get_state().runs))
:flatten()
:totable()

self.store.update_state(function(state)
state.latest_run = runs[1]
Expand Down
3 changes: 2 additions & 1 deletion lua/pipeline/providers/gitlab/graphql/_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ end
---@class pipeline.providers.gitlab.graphql.QueryResponse
---@field data { project: pipeline.providers.gitlab.graphql.QueryResponseProject }

---@param _host string Currently unused, glab selects the host automatically
---@param repo string
---@param limit number
---@param callback fun(response: pipeline.providers.gitlab.graphql.QueryResponse)
function M.get_project_pipelines(repo, limit, callback)
function M.get_project_pipelines(_host, repo, limit, callback)
local query_job =
glab_graphql(pipelines_with_jobs_query, { repo = repo, limit = limit })

Expand Down
76 changes: 41 additions & 35 deletions lua/pipeline/providers/gitlab/graphql/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,48 @@ end
function GitlabGraphQLProvider:fetch()
local Mapper = require('pipeline.providers.gitlab.graphql._mapper')

glab_api().get_project_pipelines(self.repo, 10, function(response)
if
utils.is_nil(response.data) or type(response.data.project) == 'userdata'
then
-- TODO: Handle errors
return
glab_api().get_project_pipelines(
self.server,
self.repo,
10,
function(response)
if
utils.is_nil(response.data)
or type(response.data.project) == 'userdata'
then
-- TODO: Handle errors
return
end

local pipeline = Mapper.to_pipeline(response.data.project)
local runs = {
[pipeline.pipeline_id] = vim.tbl_map(function(node)
return Mapper.to_run(pipeline.pipeline_id, node)
end, response.data.project.pipelines.nodes),
}
local jobs = utils.group_by(
function(job)
return job.run_id
end,
vim
.iter(response.data.project.pipelines.nodes)
:map(function(node)
return vim.tbl_map(function(job)
return Mapper.to_job(node.id, job)
end, node.jobs.nodes)
end)
:flatten()
:totable()
)

self.store.update_state(function(state)
state.pipelines = { pipeline }
state.latest_run = runs[pipeline.pipeline_id][1]
state.runs = runs
state.jobs = jobs
end)
end

local pipeline = Mapper.to_pipeline(response.data.project)
local runs = {
[pipeline.pipeline_id] = vim.tbl_map(function(node)
return Mapper.to_run(pipeline.pipeline_id, node)
end, response.data.project.pipelines.nodes),
}
local jobs = utils.group_by(
function(job)
return job.run_id
end,
vim
.iter(response.data.project.pipelines.nodes)
:map(function(node)
return vim.tbl_map(function(job)
return Mapper.to_job(node.id, job)
end, node.jobs.nodes)
end)
:flatten()
:totable()
)

self.store.update_state(function(state)
state.pipelines = { pipeline }
state.latest_run = runs[pipeline.pipeline_id][1]
state.runs = runs
state.jobs = jobs
end)
end)
)
end

---@param pipeline pipeline.providers.gitlab.graphql.Pipeline|nil
Expand Down
7 changes: 5 additions & 2 deletions lua/pipeline/store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ local initialState = {
workflow_configs = {},
}

---@class pipeline.Store
---@class pipeline.ReadonlyStore
---@field get_state fun(): pipeline.State

---@class pipeline.Store: pipeline.ReadonlyStore
---@field package _state pipeline.State
---@field package _update fun(state: pipeline.State)[]
local M = {
Expand All @@ -40,7 +43,7 @@ local function emit_update(state)
end
end

emit_update = utils.debounced(vim.schedule_wrap(emit_update))
emit_update = utils.debounced(emit_update)

---@param fn fun(render_state: pipeline.State): pipeline.State|nil
function M.update_state(fn)
Expand Down
4 changes: 2 additions & 2 deletions lua/pipeline/ui/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local utils = require('pipeline.utils')
---@field to? integer

---@class pipeline.Render:Buffer
---@field store { get_state: fun(): pipeline.State }
---@field store pipeline.ReadonlyStore
---@field locations pipeline.RenderLocation[]
local PipelineRender = {
locations = {},
Expand Down Expand Up @@ -55,7 +55,7 @@ local function get_status_highlight(run, prefix)
.. utils.string.upper_first(run.status)
end

---@param store { get_state: fun(): pipeline.State }
---@param store pipeline.ReadonlyStore
---@return pipeline.Render
function PipelineRender.new(store)
local self = setmetatable({}, {
Expand Down

0 comments on commit 78c4736

Please sign in to comment.