feat: change the pull request handling
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
--
|
||||
-- Provides functions specifically for Gitea pull requests:
|
||||
-- list, create, merge, comment, etc.
|
||||
-- We add a key binding to merge the PR in the PR buffer.
|
||||
-- Modified so the "list_pulls" call only returns open PRs.
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
local M = {}
|
||||
@@ -12,7 +12,7 @@ local Job = require('plenary.job')
|
||||
local lyaml = require("lyaml")
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- fallback for owner/repo
|
||||
-- fallback_owner_repo
|
||||
----------------------------------------------------------------------------
|
||||
local function fallback_owner_repo(owner, repo)
|
||||
if (not owner or owner == "") or (not repo or repo == "") then
|
||||
@@ -30,12 +30,13 @@ end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- M.list_pulls
|
||||
-- Use "?state=open" so it only shows open PRs
|
||||
----------------------------------------------------------------------------
|
||||
function M.list_pulls(owner, repo, on_done)
|
||||
owner, repo = fallback_owner_repo(owner, repo)
|
||||
if not owner or not repo then return end
|
||||
|
||||
local ep = string.format("/api/v1/repos/%s/%s/pulls", owner, repo)
|
||||
local ep = string.format("/api/v1/repos/%s/%s/pulls?state=open", owner, repo)
|
||||
core.request("GET", ep, nil, function(data, err)
|
||||
if err then
|
||||
vim.schedule(function()
|
||||
@@ -46,7 +47,7 @@ function M.list_pulls(owner, repo, on_done)
|
||||
if on_done then
|
||||
on_done(data)
|
||||
else
|
||||
print(string.format("Got %d PRs for %s/%s", #data, owner, repo))
|
||||
print(string.format("Got %d open PRs for %s/%s", #data, owner, repo))
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -58,7 +59,7 @@ function M.merge_pull(owner, repo, pr_number)
|
||||
owner, repo = fallback_owner_repo(owner, repo)
|
||||
if not owner or not repo or not pr_number then
|
||||
vim.schedule(function()
|
||||
vim.cmd([[echoerr "Usage: :Gitea pr merge <owner> <repo> <pr_number>"]])
|
||||
vim.cmd([[echoerr "No valid <owner>/<repo>/<pr_number> for merge_pull()"]])
|
||||
end)
|
||||
return
|
||||
end
|
||||
@@ -107,7 +108,7 @@ function M.create_pull(owner, repo, head, base, title, body, cb)
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Buffer approach for the PR (like issues)
|
||||
-- Buffer approach for the PR
|
||||
----------------------------------------------------------------------------
|
||||
local function set_pr_buffer_options(buf)
|
||||
vim.api.nvim_buf_set_option(buf, "buftype", "acwrite") -- allow saving
|
||||
@@ -125,7 +126,6 @@ local function attach_pr_autocmds(buf)
|
||||
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||
local doc_str = table.concat(lines, "\n")
|
||||
|
||||
-- Parse as YAML
|
||||
local ok, docs = pcall(lyaml.load, doc_str)
|
||||
if not ok or type(docs) ~= "table" then
|
||||
vim.schedule(function()
|
||||
@@ -160,9 +160,6 @@ local function attach_pr_autocmds(buf)
|
||||
})
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Keymap callback to merge the current PR
|
||||
----------------------------------------------------------------------------
|
||||
function M.merge_current_pr()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local owner = vim.api.nvim_buf_get_var(buf, "gitea_pr_owner")
|
||||
|
||||
Reference in New Issue
Block a user