changes
This commit is contained in:
@@ -5,18 +5,13 @@ local curl = require("plenary.curl")
|
||||
local M = {}
|
||||
|
||||
local function get_base_url()
|
||||
local server = config.values.server_url
|
||||
if not server or server == "" then
|
||||
-- fallback
|
||||
server = "https://gitea.example.com"
|
||||
end
|
||||
return server
|
||||
return config.values.server_url
|
||||
end
|
||||
|
||||
local function get_auth_header()
|
||||
local token = auth.get_token()
|
||||
if not token or token == "" then
|
||||
error("[gitea.nvim] Missing Gitea token. Please run :Gitea again or restart after entering a token.")
|
||||
error("[gitea.nvim] Missing Gitea token.")
|
||||
end
|
||||
return "token " .. token
|
||||
end
|
||||
@@ -31,15 +26,14 @@ local function request(method, endpoint, opts)
|
||||
url = url,
|
||||
method = method,
|
||||
headers = headers,
|
||||
timeout = 5000, -- we can also read config.values.timeout
|
||||
timeout = 10000,
|
||||
body = opts.body and vim.json.encode(opts.body) or nil,
|
||||
query = opts.query,
|
||||
})
|
||||
return result
|
||||
end
|
||||
|
||||
-------------------------------------------------------
|
||||
-- ISSUES
|
||||
-------------------------------------------------------
|
||||
-- Issues
|
||||
function M.list_issues(owner, repo, opts)
|
||||
local endpoint = string.format("/api/v1/repos/%s/%s/issues", owner, repo)
|
||||
local result = request("GET", endpoint, { query = opts })
|
||||
@@ -59,7 +53,6 @@ function M.get_issue(owner, repo, number)
|
||||
end
|
||||
|
||||
function M.create_issue(owner, repo, data)
|
||||
-- data = { title = "", body = "", labels = {"bug"}, etc. }
|
||||
local endpoint = string.format("/api/v1/repos/%s/%s/issues", owner, repo)
|
||||
local result = request("POST", endpoint, { body = data })
|
||||
if result and result.status == 201 then
|
||||
@@ -78,7 +71,6 @@ function M.edit_issue(owner, repo, number, data)
|
||||
end
|
||||
|
||||
function M.close_issue(owner, repo, number)
|
||||
-- Gitea: state -> "closed"
|
||||
return M.edit_issue(owner, repo, number, { state = "closed" })
|
||||
end
|
||||
|
||||
@@ -95,9 +87,28 @@ function M.comment_issue(owner, repo, number, body)
|
||||
return nil, result and result.status
|
||||
end
|
||||
|
||||
-------------------------------------------------------
|
||||
-- PULL REQUESTS
|
||||
-------------------------------------------------------
|
||||
-- ADDED: edit_issue_comment
|
||||
-- Gitea supports: PATCH /repos/{owner}/{repo}/issues/comments/{id}
|
||||
function M.edit_issue_comment(owner, repo, number, comment_id, body)
|
||||
local endpoint = string.format("/api/v1/repos/%s/%s/issues/comments/%d", owner, repo, comment_id)
|
||||
local result = request("PATCH", endpoint, { body = { body = body } })
|
||||
if result and result.status == 200 then
|
||||
return vim.json.decode(result.body)
|
||||
end
|
||||
return nil, result and result.status
|
||||
end
|
||||
|
||||
-- ADDED: get_issue_comments
|
||||
function M.get_issue_comments(owner, repo, number)
|
||||
local endpoint = string.format("/api/v1/repos/%s/%s/issues/%d/comments", owner, repo, number)
|
||||
local result = request("GET", endpoint)
|
||||
if result and result.status == 200 then
|
||||
return vim.json.decode(result.body)
|
||||
end
|
||||
return nil, result and result.status
|
||||
end
|
||||
|
||||
-- PR
|
||||
function M.list_pull_requests(owner, repo, opts)
|
||||
local endpoint = string.format("/api/v1/repos/%s/%s/pulls", owner, repo)
|
||||
local result = request("GET", endpoint, { query = opts })
|
||||
@@ -117,7 +128,6 @@ function M.get_pull_request(owner, repo, number)
|
||||
end
|
||||
|
||||
function M.create_pull_request(owner, repo, data)
|
||||
-- data = { head = "branch", base = "master", title = "My PR", body = "..." }
|
||||
local endpoint = string.format("/api/v1/repos/%s/%s/pulls", owner, repo)
|
||||
local result = request("POST", endpoint, { body = data })
|
||||
if result and result.status == 201 then
|
||||
@@ -136,12 +146,10 @@ function M.edit_pull_request(owner, repo, number, data)
|
||||
end
|
||||
|
||||
function M.merge_pull_request(owner, repo, number, merge_style, merge_title, merge_message)
|
||||
-- merge_style: "merge"|"rebase"|"squash" (in Gitea it's "merge"|"rebase"|"rebase-merge"|"squash" -
|
||||
-- see Gitea docs for specifics; we can map the user’s choice to Gitea’s).
|
||||
local endpoint = string.format("/api/v1/repos/%s/%s/pulls/%d/merge", owner, repo, number)
|
||||
local result = request("POST", endpoint, {
|
||||
body = {
|
||||
Do = merge_style or "merge", -- e.g. "merge"
|
||||
Do = merge_style or "merge",
|
||||
MergeTitleField = merge_title or "",
|
||||
MergeMessageField = merge_message or "",
|
||||
}
|
||||
@@ -161,8 +169,7 @@ function M.reopen_pull_request(owner, repo, number)
|
||||
end
|
||||
|
||||
function M.comment_pull_request(owner, repo, number, body)
|
||||
-- same endpoint as issues for Gitea. A PR is an issue with is_pull = true
|
||||
return M.comment_issue(owner, repo, number, body)
|
||||
end
|
||||
|
||||
return M
|
||||
return M
|
||||
Reference in New Issue
Block a user