mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
97 lines
2.6 KiB
Lua
97 lines
2.6 KiB
Lua
-- Fetch workflow runs from GitHub API
|
|
|
|
---@class FetchRunsModule
|
|
local M = {}
|
|
|
|
---@class FetchOptions
|
|
---@field owner string Repository owner
|
|
---@field repo string Repository name
|
|
---@field workflow? string Workflow file name
|
|
---@field branch? string Filter by branch
|
|
---@field status? RunStatus Filter by status
|
|
---@field per_page? number Results per page (default 30)
|
|
---@field page? number Page number (default 1)
|
|
|
|
---@class FetchResult
|
|
---@field runs WorkflowRun[] Array of workflow runs
|
|
---@field total_count number Total number of runs
|
|
---@field page number Current page
|
|
---@field has_more boolean Whether more pages exist
|
|
|
|
---Build API URL for workflow runs
|
|
---@param opts FetchOptions
|
|
---@return string
|
|
local function buildUrl(opts)
|
|
local base = "https://api.github.com/repos/" .. opts.owner .. "/" .. opts.repo
|
|
|
|
if opts.workflow then
|
|
base = base .. "/actions/workflows/" .. opts.workflow .. "/runs"
|
|
else
|
|
base = base .. "/actions/runs"
|
|
end
|
|
|
|
local params = {}
|
|
if opts.branch then
|
|
table.insert(params, "branch=" .. opts.branch)
|
|
end
|
|
if opts.status then
|
|
table.insert(params, "status=" .. opts.status)
|
|
end
|
|
table.insert(params, "per_page=" .. (opts.per_page or 30))
|
|
table.insert(params, "page=" .. (opts.page or 1))
|
|
|
|
if #params > 0 then
|
|
base = base .. "?" .. table.concat(params, "&")
|
|
end
|
|
|
|
return base
|
|
end
|
|
|
|
---Fetch workflow runs from GitHub
|
|
---@param opts FetchOptions Fetch options
|
|
---@return FetchResult
|
|
function M.fetchRuns(opts)
|
|
local url = buildUrl(opts)
|
|
|
|
-- In production, this would make HTTP request
|
|
-- For now, return placeholder structure
|
|
log("Fetching runs from: " .. url)
|
|
|
|
return {
|
|
runs = {},
|
|
total_count = 0,
|
|
page = opts.page or 1,
|
|
has_more = false
|
|
}
|
|
end
|
|
|
|
---Fetch jobs for a specific run
|
|
---@param owner string Repository owner
|
|
---@param repo string Repository name
|
|
---@param run_id number Run ID
|
|
---@return WorkflowJob[]
|
|
function M.fetchJobs(owner, repo, run_id)
|
|
local url = "https://api.github.com/repos/" .. owner .. "/" .. repo
|
|
url = url .. "/actions/runs/" .. tostring(run_id) .. "/jobs"
|
|
|
|
log("Fetching jobs from: " .. url)
|
|
|
|
return {}
|
|
end
|
|
|
|
---Fetch logs for a job
|
|
---@param owner string Repository owner
|
|
---@param repo string Repository name
|
|
---@param job_id number Job ID
|
|
---@return string Log content
|
|
function M.fetchLogs(owner, repo, job_id)
|
|
local url = "https://api.github.com/repos/" .. owner .. "/" .. repo
|
|
url = url .. "/actions/jobs/" .. tostring(job_id) .. "/logs"
|
|
|
|
log("Fetching logs from: " .. url)
|
|
|
|
return ""
|
|
end
|
|
|
|
return M
|