Skip to content

Commit 9e55de9

Browse files
authored
fix: linewise actions broken (#481)
1 parent 58f30e7 commit 9e55de9

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

lua/gitlab/actions/pipeline.lua

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local job = require("gitlab.job")
77
local u = require("gitlab.utils")
88
local popup = require("gitlab.popup")
99
local M = {
10-
pipeline_jobs = nil,
10+
pipeline_jobs = {},
1111
latest_pipeline = nil,
1212
pipeline_popup = nil,
1313
}
@@ -56,7 +56,12 @@ M.open = function()
5656
for idx, pipeline in ipairs(M.latest_pipelines) do
5757
local width = string.len(pipeline.web_url) + 10
5858
max_width = math.max(max_width, width)
59+
5960
local pipeline_jobs = get_pipeline_jobs(idx)
61+
for _, j in ipairs(pipeline_jobs) do
62+
table.insert(M.pipeline_jobs, j)
63+
end
64+
6065
local pipeline_status = M.get_pipeline_status(idx, false)
6166
local height = 6 + #pipeline_jobs + 3
6267
total_height = total_height + height
@@ -151,19 +156,32 @@ M.open = function()
151156
u.switch_can_edit_buf(bufnr, false)
152157
end)
153158
end
159+
154160
M.retrigger = function()
155-
M.latest_pipeline = get_latest_pipelines()
156-
if not M.latest_pipeline then
157-
return
158-
end
159-
if M.latest_pipeline.status ~= "failed" then
160-
u.notify("Pipeline is not in a failed state!", vim.log.levels.WARN)
161+
local pipelines = get_latest_pipelines()
162+
if not pipelines then
161163
return
162164
end
163165

164-
job.run_job("/pipeline/" .. M.latest_pipeline.id, "POST", nil, function()
165-
u.notify("Pipeline re-triggered!", vim.log.levels.INFO)
166-
end)
166+
local failed_pipelines = {}
167+
168+
for idx, pipeline in ipairs(pipelines) do
169+
local pipeline_jobs = get_pipeline_jobs(idx)
170+
for _, pjob in ipairs(pipeline_jobs) do
171+
if pjob.status == "failed" then
172+
if pipeline.status ~= "failed" then
173+
u.notify("Pipeline is not in a failed state!", vim.log.levels.WARN)
174+
return
175+
end
176+
if not failed_pipelines[pipeline.id] then
177+
job.run_job("/pipeline/trigger/" .. pipeline.id, "POST", nil, function()
178+
u.notify("Pipeline " .. pipeline.id .. " re-triggered!", vim.log.levels.INFO)
179+
end)
180+
failed_pipelines[pipeline.id] = true
181+
end
182+
end
183+
end
184+
end
167185
end
168186

169187
M.see_logs = function()

0 commit comments

Comments
 (0)