From 5eb04bc3981f85bde6229a3c185734c49d907bea Mon Sep 17 00:00:00 2001 From: Willem Jan Noort Date: Sat, 22 Jun 2024 18:34:49 +0200 Subject: [PATCH] rename to adopure --- adopure.nvim-0.0.1-1.rockspec | 2 +- lua/ado/types.lua | 135 ------------------ lua/{ado.lua => adopure.lua} | 28 ++-- lua/{ado => adopure}/activate.lua | 12 +- lua/{ado => adopure}/api.lua | 88 ++++++------ lua/{ado => adopure}/config/internal.lua | 0 lua/{ado => adopure}/config/meta.lua | 0 lua/{ado => adopure}/git.lua | 4 +- lua/{ado => adopure}/marker.lua | 12 +- lua/{ado => adopure}/pickers/pull_request.lua | 22 +-- lua/{ado => adopure}/pickers/thread.lua | 40 +++--- .../previews/pull_request.lua | 8 +- lua/{ado => adopure}/previews/thread.lua | 4 +- lua/{ado => adopure}/project.lua | 6 +- lua/{ado => adopure}/quickfix.lua | 2 +- lua/{ado => adopure}/render.lua | 2 +- lua/{ado => adopure}/review.lua | 4 +- lua/{ado => adopure}/state.lua | 50 +++---- lua/{ado => adopure}/thread.lua | 76 +++++----- lua/adopure/types.lua | 135 ++++++++++++++++++ lua/{ado => adopure}/utils.lua | 0 plugin/init.lua | 4 +- spec/load_spec.lua | 6 +- spec/submit_spec.lua | 30 ++-- 24 files changed, 335 insertions(+), 335 deletions(-) delete mode 100644 lua/ado/types.lua rename lua/{ado.lua => adopure.lua} (82%) rename lua/{ado => adopure}/activate.lua (64%) rename lua/{ado => adopure}/api.lua (76%) rename lua/{ado => adopure}/config/internal.lua (100%) rename lua/{ado => adopure}/config/meta.lua (100%) rename lua/{ado => adopure}/git.lua (96%) rename lua/{ado => adopure}/marker.lua (91%) rename lua/{ado => adopure}/pickers/pull_request.lua (80%) rename lua/{ado => adopure}/pickers/thread.lua (78%) rename lua/{ado => adopure}/previews/pull_request.lua (94%) rename lua/{ado => adopure}/previews/thread.lua (92%) rename lua/{ado => adopure}/project.lua (90%) rename lua/{ado => adopure}/quickfix.lua (96%) rename lua/{ado => adopure}/render.lua (99%) rename lua/{ado => adopure}/review.lua (90%) rename lua/{ado => adopure}/state.lua (59%) rename lua/{ado => adopure}/thread.lua (79%) create mode 100644 lua/adopure/types.lua rename lua/{ado => adopure}/utils.lua (100%) diff --git a/adopure.nvim-0.0.1-1.rockspec b/adopure.nvim-0.0.1-1.rockspec index ff086ec..02f255f 100644 --- a/adopure.nvim-0.0.1-1.rockspec +++ b/adopure.nvim-0.0.1-1.rockspec @@ -2,7 +2,7 @@ rockspec_format = "3.0" package = "adopure.nvim" version = "0.0.1-1" source = { - url = "git+https://github.com/Willem-J-an/ado.nvim", + url = "git+https://github.com/Willem-J-an/adopure.nvim", } dependencies = { "plenary.nvim", diff --git a/lua/ado/types.lua b/lua/ado/types.lua deleted file mode 100644 index b11a181..0000000 --- a/lua/ado/types.lua +++ /dev/null @@ -1,135 +0,0 @@ ----@class RequestResult ----@field value any - - ----@class PullRequest ----@field codeReviewid integer ----@field description string ----@field isDraft boolean ----@field pullRequestId boolean ----@field sourceRefName string ----@field targetRefName string ----@field title string ----@field url string ----@field status string ----@field createdBy User ----@field creationDate string ----@field mergeStatus string ----@field reviewers Reviewer[] - ----@class User ----@field displayName string ----@field id string - ----@class ConnectionUser ----@field id string ----@field isActive boolean - ----@class ConnectionData ----@field authenticatedUser ConnectionUser ----@field authorizedUser ConnectionUser - ----@class Reviewer ----@field displayName string ----@field id string ----@field vote PullRequestVote - ----@class Repository ----@field name string ----@field id string ----@field url string ----@field defaultBranch string - ----@class Project ----@field id string ----@field name string ----@field url string - ----@class Thread ----@field id number ----@field comments Comment[] ----@field threadContext ThreadContext|nil ----@field status string ----@field isDeleted boolean ----@field publishedDate string ----@field lastUpdatedDate string - ----@class Comment ----@field id number ----@field commentType string ----@field content string|nil ----@field author Author ----@field isDeleted boolean ----@field publishedDate string ----@field lastUpdatedDate string ----@field lastContentUpdatedDate string - ----@class ThreadContext ----@field filePath string ----@field leftFileEnd Position|nil ----@field leftFileStart Position|nil ----@field rightFileEnd Position|nil ----@field rightFileStart Position|nil - ----@class Position ----@field line number ----@field offset number - ----@class Author ----@field id string ----@field displayName string - ----@class CommentReply ----@field bufnr number ----@field mark_id number ----@field content string|nil ----@field thread Thread - ----@class CommentCreate ----@field bufnr number ----@field mark_id number ----@field thread_context ThreadContext ----@field content string|nil - ----@class NewThread ----@field comments NewComment[] ----@field threadContext ThreadContext ----@field pullRequestThreadContext PullRequestCommentThreadContext ----@field status number - ----@class NewComment ----@field parentCommentId number ----@field commentType number ----@field content string - ----@class PullRequestCommentThreadContext ----@field changeTrackingId number ----@field iterationContext IterationContext ---@field trackingCriteria TrackingCriteria - ----@class IterationContext ----@field firstComparingIteration number ----@field secondComparingIteration number - ---@class TrackingCriteria ---@field firstComparingIteration number ---@field secondTrackingCriteria number - ----@class Iteration ----@field id number ----@field sourceRefCommit CommitRef ----@field targetRefCommit CommitRef - ----@class CommitRef ----@field commitId string - ----@class ChangeEntries ----@field changeEntries ChangeEntry[] - ----@class ChangeEntry ----@field changeId number ----@field changeTrackingId number ----@field item ChangeEntryItem - ----@class ChangeEntryItem ----@field path string diff --git a/lua/ado.lua b/lua/adopure.lua similarity index 82% rename from lua/ado.lua rename to lua/adopure.lua index 1dc151c..6e462a0 100644 --- a/lua/ado.lua +++ b/lua/adopure.lua @@ -1,8 +1,8 @@ local M = {} ----@type StateManager|nil +---@type adopure.StateManager|nil local state_manager ----@return AdoState +---@return adopure.AdoState function M.get_loaded_state() assert(state_manager and state_manager.state, "Choose and activate a pull request first;") return state_manager.state @@ -37,22 +37,22 @@ local function execute_or_prompt(sub_impl, subcommand_args, subcommand) sub_impl[subcommand_args[1]](ok and opts or {}) end ----@class SubCommand +---@class adopure.SubCommand ---@field impl fun(args:string[]) ---@field complete_args? string[] ---Initial load of state_manager with all open PRs; ----@return StateManager +---@return adopure.StateManager function M.load_state_manager() if not state_manager then - local context = require("ado.state").AdoContext:new() - state_manager = require("ado.state").StateManager:new(context) + local context = require("adopure.state").AdoContext:new() + state_manager = require("adopure.state").StateManager:new(context) end assert(state_manager, "StateManager should not be nil after loading;") return state_manager end ----@type table +---@type table local subcommand_tbl = { load = { complete_args = { "context", "threads" }, @@ -74,13 +74,13 @@ local subcommand_tbl = { impl = function(args) local sub_impl = { comment = function(opts) - require("ado.thread").submit_comment(M.get_loaded_state(), opts) + require("adopure.thread").submit_comment(M.get_loaded_state(), opts) end, vote = function(opts) - require("ado.review").submit_vote(M.get_loaded_state(), opts) + require("adopure.review").submit_vote(M.get_loaded_state(), opts) end, thread_status = function(opts) - require("ado.thread").update_thread_status(M.get_loaded_state(), opts) + require("adopure.thread").update_thread_status(M.get_loaded_state(), opts) end, } execute_or_prompt(sub_impl, args, "submit") @@ -91,16 +91,16 @@ local subcommand_tbl = { impl = function(args) local sub_impl = { quickfix = function(opts) - require("ado.quickfix").render_quickfix(M.get_loaded_state().pull_request_threads, opts) + require("adopure.quickfix").render_quickfix(M.get_loaded_state().pull_request_threads, opts) end, thread_picker = function(opts) - require("ado.pickers.thread").choose_thread(M.get_loaded_state(), opts) + require("adopure.pickers.thread").choose_thread(M.get_loaded_state(), opts) end, new_thread = function(opts) - require("ado.thread").new_thread_window(M.get_loaded_state(), opts) + require("adopure.thread").new_thread_window(M.get_loaded_state(), opts) end, existing_thread = function(opts) - require("ado.thread").open_thread_window(M.get_loaded_state(), opts) + require("adopure.thread").open_thread_window(M.get_loaded_state(), opts) end, } execute_or_prompt(sub_impl, args, "open") diff --git a/lua/ado/activate.lua b/lua/adopure/activate.lua similarity index 64% rename from lua/ado/activate.lua rename to lua/adopure/activate.lua index 2394dea..91632af 100644 --- a/lua/ado/activate.lua +++ b/lua/adopure/activate.lua @@ -1,6 +1,6 @@ local M = {} ----@param pull_request PullRequest +---@param pull_request adopure.PullRequest local function confirm_open_in_diffview(pull_request) vim.ui.input({ prompt = "Open in diffview? / " }, function(input) if not input then @@ -12,21 +12,21 @@ local function confirm_open_in_diffview(pull_request) end local function buffer_marker_autocmd(state) - local augroup = vim.api.nvim_create_augroup("ado.nvim", { clear = true }) + local augroup = vim.api.nvim_create_augroup("adopure.nvim", { clear = true }) vim.api.nvim_create_autocmd({ "BufEnter" }, { group = augroup, callback = function() if state.pull_request_threads then - require("ado.marker").create_buffer_extmarks(state.pull_request_threads) + require("adopure.marker").create_buffer_extmarks(state.pull_request_threads) end end, }) end ----@param state AdoState +---@param state adopure.AdoState function M.activate_pull_request_context(state) - require("ado.marker").create_buffer_extmarks(state.pull_request_threads) - require("ado.git").confirm_checkout_and_open(state.active_pull_request, function() + require("adopure.marker").create_buffer_extmarks(state.pull_request_threads) + require("adopure.git").confirm_checkout_and_open(state.active_pull_request, function() confirm_open_in_diffview(state.active_pull_request) end) buffer_marker_autocmd(state) diff --git a/lua/ado/api.lua b/lua/adopure/api.lua similarity index 76% rename from lua/ado/api.lua rename to lua/adopure/api.lua index feb92f8..468b280 100644 --- a/lua/ado/api.lua +++ b/lua/adopure/api.lua @@ -1,6 +1,6 @@ local M = {} local curl = require("plenary.curl") -local config = require("ado.config.internal") +local config = require("adopure.config.internal") local GIT_API_VERSION = "api-version=7.1-preview.1" @@ -35,8 +35,8 @@ local function get_azure_devops(url, request_type) end ---Get repository from Azure DevOps ----@param context AdoContext ----@return Repository|nil repository, string|nil err +---@param context adopure.AdoContext +---@return adopure.Repository|nil repository, string|nil err function M.get_repository(context) if organization_url == "" then organization_url = context.organization_url @@ -45,13 +45,13 @@ function M.get_repository(context) project_name = context.project_name end local url = organization_url .. project_name .. "/_apis/git/repositories?" .. GIT_API_VERSION - ---@type RequestResult + ---@type adopure.RequestResult local result, err = get_azure_devops(url, "repositories") if not result then return nil, err end - ---@type Repository[] + ---@type adopure.Repository[] local repositories = result.value for _, _repository in pairs(repositories) do if _repository.name == context.repository_name then @@ -61,42 +61,42 @@ function M.get_repository(context) end ---Get pull requests from Azure DevOps ----@param repository Repository ----@return PullRequest[] pull_requests, string|nil err +---@param repository adopure.Repository +---@return adopure.PullRequest[] pull_requests, string|nil err function M.get_pull_requests(repository) - ---@type RequestResult + ---@type adopure.RequestResult local result, err = get_azure_devops(repository.url .. "/pullrequests?" .. GIT_API_VERSION, "pull requests") if not result then return {}, err end - ---@type PullRequest[] + ---@type adopure.PullRequest[] local pull_requests = result.value return pull_requests, err end ---Get pull request iterations from Azure DevOps ----@param pull_request PullRequest ----@return Iteration[] iterations, string|nil err +---@param pull_request adopure.PullRequest +---@return adopure.Iteration[] iterations, string|nil err function M.get_pull_request_iterations(pull_request) - ---@type RequestResult + ---@type adopure.RequestResult local result, err = get_azure_devops(pull_request.url .. "/iterations?" .. GIT_API_VERSION, "pull request iterations") if not result then return {}, err end - ---@type Iteration[] + ---@type adopure.Iteration[] local iterations = result.value return iterations, err end ---Get pull request iteration changes from Azure DevOps ----@param pull_request PullRequest ----@param iteration Iteration ----@return ChangeEntry[] change_entries, string|nil err +---@param pull_request adopure.PullRequest +---@param iteration adopure.Iteration +---@return adopure.ChangeEntry[] change_entries, string|nil err function M.get_pull_requests_iteration_changes(pull_request, iteration) - ---@type ChangeEntries + ---@type adopure.ChangeEntries local result, err = get_azure_devops( pull_request.url .. "/iterations/" .. iteration.id .. "/changes?" .. GIT_API_VERSION, "pull request iteration changes" @@ -109,11 +109,11 @@ function M.get_pull_requests_iteration_changes(pull_request, iteration) end ---Get not deleted pull request threads from Azure DevOps ----@param state AdoState ----@return Thread[] threads, string|nil err +---@param state adopure.AdoState +---@return adopure.Thread[] threads, string|nil err function M.get_pull_request_threads(state) local iteration = "$baseIteration=1&iteration=" .. state.active_pull_request_iteration.id - ---@type RequestResult + ---@type adopure.RequestResult local result, err = get_azure_devops( state.active_pull_request.url .. "/threads?" .. table.concat({ GIT_API_VERSION, iteration }, "&"), "pull request threads" @@ -122,10 +122,10 @@ function M.get_pull_request_threads(state) return {}, err end - ---@type Thread[] + ---@type adopure.Thread[] local threads = result.value local active_threads = vim.iter(threads) - :filter(function(thread) ---@param thread Thread + :filter(function(thread) ---@param thread adopure.Thread return not thread.isDeleted end) :totable() @@ -151,7 +151,7 @@ local function submit_azure_devops(url, http_verb, request_type, body) return nil, "Failed to " .. http_verb .. " " .. request_type .. "; " .. details end if type(response.body) == "string" and #response.body ~=0 then - ---@type Thread|Comment|Reviewer|nil + ---@type adopure.Thread|adopure.Comment|adopure.Reviewer|nil local result = vim.fn.json_decode(response.body) return result, nil end @@ -159,11 +159,11 @@ local function submit_azure_devops(url, http_verb, request_type, body) end ---Create new pull request comment thread ----@param pull_request PullRequest ----@param new_thread NewThread ----@return Thread|nil thread, string|nil err +---@param pull_request adopure.PullRequest +---@param new_thread adopure.NewThread +---@return adopure.Thread|nil thread, string|nil err function M.create_pull_request_comment_thread(pull_request, new_thread) - ---@type Thread|nil + ---@type adopure.Thread|nil local result, err = submit_azure_devops( pull_request.url .. "/threads?" .. GIT_API_VERSION, "POST", @@ -175,12 +175,12 @@ function M.create_pull_request_comment_thread(pull_request, new_thread) end ---Create new pull request comment reply ----@param pull_request PullRequest ----@param thread Thread ----@param comment NewComment ----@return Comment|nil comment, string|nil err +---@param pull_request adopure.PullRequest +---@param thread adopure.Thread +---@param comment adopure.NewComment +---@return adopure.Comment|nil comment, string|nil err function M.create_pull_request_comment_reply(pull_request, thread, comment) - ---@type Comment|nil + ---@type adopure.Comment|nil local result, err = submit_azure_devops( pull_request.url .. "/threads/" .. thread.id .. "/comments?" .. GIT_API_VERSION, "POST", @@ -192,11 +192,11 @@ function M.create_pull_request_comment_reply(pull_request, thread, comment) end ---Create new pull request comment reply ----@param pull_request PullRequest ----@param thread Thread ----@return Thread|nil thread, string|nil err +---@param pull_request adopure.PullRequest +---@param thread adopure.Thread +---@return adopure.Thread|nil thread, string|nil err function M.update_pull_request_thread(pull_request, thread) - ---@type Thread|nil + ---@type adopure.Thread|nil local result, err = submit_azure_devops( pull_request.url .. "/threads/" .. thread.id .. "?" .. GIT_API_VERSION, "PATCH", @@ -207,12 +207,12 @@ function M.update_pull_request_thread(pull_request, thread) end ---Create new pull request comment reply ----@param pull_request PullRequest ----@param thread Thread +---@param pull_request adopure.PullRequest +---@param thread adopure.Thread ---@param comment_id number ----@return Thread|nil thread, string|nil err +---@return adopure.Thread|nil thread, string|nil err function M.delete_pull_request_comment(pull_request, thread, comment_id) - ---@type Thread|nil + ---@type adopure.Thread|nil local result, err = submit_azure_devops( table.concat({ pull_request.url, "/threads/", thread.id, "/comments/", comment_id, "?", GIT_API_VERSION }), "DELETE", @@ -223,11 +223,11 @@ function M.delete_pull_request_comment(pull_request, thread, comment_id) end ---Create new pull request vote ----@param pull_request PullRequest +---@param pull_request adopure.PullRequest ---@param vote PullRequestVote ----@return Reviewer|nil reviewer, string|nil err +---@return adopure.Reviewer|nil reviewer, string|nil err function M.submit_vote(pull_request, vote) - ---@type ConnectionData + ---@type adopure.ConnectionData local connection_result, connection_err = get_azure_devops(organization_url .. "/_apis/connectionData", "connectionData") if connection_err then @@ -236,7 +236,7 @@ function M.submit_vote(pull_request, vote) local reviewer_id = connection_result.authenticatedUser.id - ---@type Reviewer|nil + ---@type adopure.Reviewer|nil local result, err = submit_azure_devops( pull_request.url .. "/reviewers/" .. reviewer_id .. "?" .. GIT_API_VERSION, "PUT", diff --git a/lua/ado/config/internal.lua b/lua/adopure/config/internal.lua similarity index 100% rename from lua/ado/config/internal.lua rename to lua/adopure/config/internal.lua diff --git a/lua/ado/config/meta.lua b/lua/adopure/config/meta.lua similarity index 100% rename from lua/ado/config/meta.lua rename to lua/adopure/config/meta.lua diff --git a/lua/ado/git.lua b/lua/adopure/git.lua similarity index 96% rename from lua/ado/git.lua rename to lua/adopure/git.lua index 7c2b9c1..7057427 100644 --- a/lua/ado/git.lua +++ b/lua/adopure/git.lua @@ -39,11 +39,11 @@ function M.get_remote_config() }) get_remotes:start() ---@type string - local remote = require("ado.utils").await_result(get_remotes)[1] + local remote = require("adopure.utils").await_result(get_remotes)[1] return extract_git_details(remote) end ----@param pull_request PullRequest +---@param pull_request adopure.PullRequest ---@param open_callable function function M.confirm_checkout_and_open(pull_request, open_callable) local Job = require("plenary.job") diff --git a/lua/ado/marker.lua b/lua/adopure/marker.lua similarity index 91% rename from lua/ado/marker.lua rename to lua/adopure/marker.lua index 2a62d95..94e7b96 100644 --- a/lua/ado/marker.lua +++ b/lua/adopure/marker.lua @@ -1,7 +1,7 @@ local M = { - ---@type table: + ---@type table: buffer_extmarks = {}, - ---@type table: + ---@type table: thread_extmarks = {}, } local Path = require("plenary.path") @@ -31,14 +31,14 @@ local signs = { wontFix = "󰗞 ", } ---@param bufnr number ----@param pull_request_thread Thread ----@param context ThreadContext +---@param pull_request_thread adopure.Thread +---@param context adopure.ThreadContext local function create_extmark(bufnr, pull_request_thread, context) local end_offset = context.rightFileEnd.offset local status = pull_request_thread.status local hl_group, sign_hl_group - local hl_groups = require("ado.config.internal").hl_groups + local hl_groups = require("adopure.config.internal").hl_groups if status == "active" or status == "pending" then hl_group = hl_groups.active sign_hl_group = hl_groups.active_sign @@ -70,7 +70,7 @@ local function create_extmark(bufnr, pull_request_thread, context) end ---Create extmarks for pull request threads ----@param pull_request_threads Thread[] +---@param pull_request_threads adopure.Thread[] function M.create_buffer_extmarks(pull_request_threads) for _, extmark in pairs(vim.api.nvim_buf_get_extmarks(0, namespace, 0, -1, {})) do local extmark_id = extmark[1] diff --git a/lua/ado/pickers/pull_request.lua b/lua/adopure/pickers/pull_request.lua similarity index 80% rename from lua/ado/pickers/pull_request.lua rename to lua/adopure/pickers/pull_request.lua index d6c0d5c..e9de909 100644 --- a/lua/ado/pickers/pull_request.lua +++ b/lua/adopure/pickers/pull_request.lua @@ -1,5 +1,5 @@ ----@class PullRequestEntry ----@field value PullRequest +---@class adopure.PullRequestEntry +---@field value adopure.PullRequest ---@field ordinal number ---@field display string @@ -18,14 +18,14 @@ end local pull_request_previewer = require("telescope.previewers").new_buffer_previewer({ title = "Pull request preview", ---@param self any - ---@param entry PullRequestEntry + ---@param entry adopure.PullRequestEntry ---@param _ any define_preview = function(self, entry, _) - require("ado.previews.pull_request").pull_request_preview(self.state.bufnr, entry.value) + require("adopure.previews.pull_request").pull_request_preview(self.state.bufnr, entry.value) end, }) ----@param entry PullRequest ----@return PullRequestEntry +---@param entry adopure.PullRequest +---@return adopure.PullRequestEntry local function entry_maker(entry) ---@type string|nil local votes = vim.iter(entry.reviewers) @@ -33,7 +33,7 @@ local function entry_maker(entry) return reviewer.vote ~= 0 end) :map(function(reviewer) - local Review = require("ado.review") + local Review = require("adopure.review") local vote = Review.get_vote_from_value(reviewer.vote) return Review.vote_icons[vote] end) @@ -49,17 +49,17 @@ local function entry_maker(entry) end ---@param prompt_bufnr number ----@param state_manager StateManager +---@param state_manager adopure.StateManager local function handle_choice(prompt_bufnr, state_manager) require("telescope.actions").close(prompt_bufnr) - ---@type PullRequestEntry + ---@type adopure.PullRequestEntry local selection = require("telescope.actions.state").get_selected_entry() state_manager:set_state_by_choice(selection.value) - require("ado.activate").activate_pull_request_context(state_manager.state) + require("adopure.activate").activate_pull_request_context(state_manager.state) end ---Choose and activate selected pull request ----@param state_manager StateManager +---@param state_manager adopure.StateManager function M.choose_and_activate(state_manager) local wrap_preview_id = M.create_auto_wrap_preview() require("telescope.pickers") diff --git a/lua/ado/pickers/thread.lua b/lua/adopure/pickers/thread.lua similarity index 78% rename from lua/ado/pickers/thread.lua rename to lua/adopure/pickers/thread.lua index cf7cd2a..323c1dc 100644 --- a/lua/ado/pickers/thread.lua +++ b/lua/adopure/pickers/thread.lua @@ -1,7 +1,7 @@ ---@diagnostic disable: undefined-doc-name ----@class ThreadEntry ----@field value Thread +---@class adopure.ThreadEntry +---@field value adopure.Thread ---@field ordinal number ---@field display string @@ -9,15 +9,15 @@ local M = {} local thread_previewer = require("telescope.previewers").new_buffer_previewer({ title = "Thread preview", ---@param self any - ---@param entry ThreadEntry + ---@param entry adopure.ThreadEntry ---@param _ any define_preview = function(self, entry, _) - require("ado.previews.thread").thread_preview(self.state.bufnr, entry.value) + require("adopure.previews.thread").thread_preview(self.state.bufnr, entry.value) end, }) ----@param entry Thread ----@return ThreadEntry +---@param entry adopure.Thread +---@return adopure.ThreadEntry local function entry_maker(entry) return { value = entry, @@ -27,7 +27,7 @@ local function entry_maker(entry) end ---@param file_path string ----@param thread_context ThreadContext +---@param thread_context adopure.ThreadContext local function open_scroll(file_path, thread_context) if vim.fn.filereadable(file_path) == 0 then vim.notify("No such file: " .. file_path, 3) @@ -40,10 +40,10 @@ local function open_scroll(file_path, thread_context) end ---@param prompt_bufnr number ----@param state AdoState +---@param state adopure.AdoState local function handle_choice(prompt_bufnr, state) require("telescope.actions").close(prompt_bufnr) - ---@type ThreadEntry + ---@type adopure.ThreadEntry local selection = require("telescope.actions.state").get_selected_entry() local context = selection.value["threadContext"] if context == vim.NIL or not context then @@ -51,22 +51,22 @@ local function handle_choice(prompt_bufnr, state) end local file_path = string.sub(context.filePath, 2) open_scroll(file_path, context) - ---@type OpenThreadWindowOpts + ---@type adopure.OpenThreadWindowOpts local open_thread_window_opts = { thread_id = selection.value.id } - require("ado.thread").open_thread_window(state, open_thread_window_opts) + require("adopure.thread").open_thread_window(state, open_thread_window_opts) end local thread_filters = { - ---@param thread Thread + ---@param thread adopure.Thread hide_system = function(thread) return thread.comments[1].commentType == "text" end, - ---@param thread Thread + ---@param thread adopure.Thread hide_closed = function(thread) return thread.status == "active" or thread.status == "pending" end, } ----@class ChooseThreadOpts +---@class adopure.ChooseThreadOpts ---@field thread_filters string[] ---@param thread_iter Iter @@ -79,9 +79,9 @@ local function apply_filter(thread_iter, thread_filter) end return thread_iter:filter(thread_filters[thread_filter]) ---@diagnostic disable-line: undefined-field end ----@param pull_request_threads Thread[] ----@param opts ChooseThreadOpts ----@return Thread[] pull_request_threads +---@param pull_request_threads adopure.Thread[] +---@param opts adopure.ChooseThreadOpts +---@return adopure.Thread[] pull_request_threads local function filter_pull_request_threads(pull_request_threads, opts) if not opts.thread_filters then return pull_request_threads @@ -94,10 +94,10 @@ local function filter_pull_request_threads(pull_request_threads, opts) end ---Choose thread ----@param state AdoState ----@param opts ChooseThreadOpts +---@param state adopure.AdoState +---@param opts adopure.ChooseThreadOpts function M.choose_thread(state, opts) - local wrap_preview_id = require("ado.pickers.pull_request").create_auto_wrap_preview() + local wrap_preview_id = require("adopure.pickers.pull_request").create_auto_wrap_preview() require("telescope.pickers") .new(require("telescope.themes").get_ivy({}), { prompt_title = "Threads", diff --git a/lua/ado/previews/pull_request.lua b/lua/adopure/previews/pull_request.lua similarity index 94% rename from lua/ado/previews/pull_request.lua rename to lua/adopure/previews/pull_request.lua index 3efdcdd..2ac26e8 100644 --- a/lua/ado/previews/pull_request.lua +++ b/lua/adopure/previews/pull_request.lua @@ -1,6 +1,6 @@ local M = {} -local namespace = vim.api.nvim_create_namespace("ado") +local namespace = vim.api.nvim_create_namespace("adopure") function M.readable_timestamp(iso_str) local pattern = "(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)" @@ -28,11 +28,11 @@ local function get_info_table(pull_request) } end ----@param pull_request PullRequest +---@param pull_request adopure.PullRequest ---@return string[] votes local function get_votes(pull_request) local votes = {} - local vote_from_value = require("ado.review").get_vote_from_value + local vote_from_value = require("adopure.review").get_vote_from_value vim.iter(pull_request.reviewers) :filter(function(reviewer) return reviewer.vote ~= 0 @@ -44,7 +44,7 @@ local function get_votes(pull_request) end ---@param info_line string ----@param pull_request PullRequest +---@param pull_request adopure.PullRequest ---@param subtitle string ---@param votes string[] ---@return string[] diff --git a/lua/ado/previews/thread.lua b/lua/adopure/previews/thread.lua similarity index 92% rename from lua/ado/previews/thread.lua rename to lua/adopure/previews/thread.lua index 9b1d0d7..fbd1ad4 100644 --- a/lua/ado/previews/thread.lua +++ b/lua/adopure/previews/thread.lua @@ -1,9 +1,9 @@ local M = {} ---@param bufnr number ----@param thread Thread +---@param thread adopure.Thread function M.thread_preview(bufnr, thread) - local pull_request = require("ado.previews.pull_request") + local pull_request = require("adopure.previews.pull_request") local preview_content = { "Comment thread: " .. tostring(thread.id), "Created: " .. pull_request.readable_timestamp(thread.publishedDate), diff --git a/lua/ado/project.lua b/lua/adopure/project.lua similarity index 90% rename from lua/ado/project.lua rename to lua/adopure/project.lua index 6a7b3ab..733c0df 100644 --- a/lua/ado/project.lua +++ b/lua/adopure/project.lua @@ -10,7 +10,7 @@ local function encode_uri_component(text) return text end ----@param project Project +---@param project adopure.Project ---@return string project_name local function format_project_choice(project) return project.name @@ -20,7 +20,7 @@ end ---@diagnostic disable-next-line: undefined-doc-name ---@return string|nil err local function set_project_name_cache(project_cache_path) - local projects, err = require("ado.api").get_projects() + local projects, err = require("adopure.api").get_projects() if err then return err end @@ -38,7 +38,7 @@ end ---Get project name from cache or select correct one; ---@return string|nil project_name, string|nil err function M.get_project_name(repository_name) - local project_cache_path = require("plenary.path"):new(vim.fn.stdpath("cache"), "ado.nvim", repository_name) + local project_cache_path = require("plenary.path"):new(vim.fn.stdpath("cache"), "adopure.nvim", repository_name) if project_cache_path:exists() then return vim.split(project_cache_path:read(), "project_name=")[2] end diff --git a/lua/ado/quickfix.lua b/lua/adopure/quickfix.lua similarity index 96% rename from lua/ado/quickfix.lua rename to lua/adopure/quickfix.lua index 92228b7..1fb6be2 100644 --- a/lua/ado/quickfix.lua +++ b/lua/adopure/quickfix.lua @@ -1,7 +1,7 @@ local M = {} ---Render pull request threads in quickfix panel ----@param pull_request_threads Thread[] +---@param pull_request_threads adopure.Thread[] ---@param _ table function M.render_quickfix(pull_request_threads, _) local entries = {} diff --git a/lua/ado/render.lua b/lua/adopure/render.lua similarity index 99% rename from lua/ado/render.lua rename to lua/adopure/render.lua index 1f33712..d43a56d 100644 --- a/lua/ado/render.lua +++ b/lua/adopure/render.lua @@ -96,7 +96,7 @@ local icons = { } ---Render pull request thread ----@param pull_request_thread Thread +---@param pull_request_thread adopure.Thread ---@return number, number: bufnr, mark_id function M.render_reply_thread(pull_request_thread) local bufnr = new_or_convert_window("[adopure - thread - " .. pull_request_thread.id .. "]") diff --git a/lua/ado/review.lua b/lua/adopure/review.lua similarity index 90% rename from lua/ado/review.lua rename to lua/adopure/review.lua index dcf0acf..9120dd8 100644 --- a/lua/ado/review.lua +++ b/lua/adopure/review.lua @@ -28,7 +28,7 @@ function M.get_vote_from_value(vote_value) end ---Submit vote of choice on pull request ----@param state AdoState +---@param state adopure.AdoState ---@param _ table function M.submit_vote(state, _) vim.ui.select(vim.tbl_keys(M.pull_request_vote), { prompt = "Select vote;" }, function(vote) @@ -36,7 +36,7 @@ function M.submit_vote(state, _) vim.notify("No vote chosen;", 2) return end - local new_reviewer, err = require("ado.api").submit_vote(state.active_pull_request, M.pull_request_vote[vote]) + local new_reviewer, err = require("adopure.api").submit_vote(state.active_pull_request, M.pull_request_vote[vote]) if err or not new_reviewer then error(err or "Expected Reviewer but not nil;") end diff --git a/lua/ado/state.lua b/lua/adopure/state.lua similarity index 59% rename from lua/ado/state.lua rename to lua/adopure/state.lua index 486a31e..fccb018 100644 --- a/lua/ado/state.lua +++ b/lua/adopure/state.lua @@ -1,11 +1,11 @@ ----@class AdoContext +---@class adopure.AdoContext ---@field organization_url string ---@field project_name string ---@field repository_name string local AdoContext = {} ----@return AdoContext +---@return adopure.AdoContext function AdoContext:new() - local organization_url, project_name, repository_name = require("ado.git").get_remote_config() + local organization_url, project_name, repository_name = require("adopure.git").get_remote_config() local o = { organization_url = organization_url, project_name = project_name, @@ -15,18 +15,18 @@ function AdoContext:new() return setmetatable(o, self) end ----@class AdoState ----@field repository Repository ----@field active_pull_request PullRequest ----@field active_pull_request_iteration Iteration ----@field pull_request_threads Thread[] ----@field comment_creations CommentCreate[] ----@field comment_replies CommentReply[] +---@class adopure.AdoState +---@field repository adopure.Repository +---@field active_pull_request adopure.PullRequest +---@field active_pull_request_iteration adopure.Iteration +---@field pull_request_threads adopure.Thread[] +---@field comment_creations adopure.CommentCreate[] +---@field comment_replies adopure.CommentReply[] local AdoState = {} ----@param repository Repository ----@param pull_request PullRequest ----@return AdoState +---@param repository adopure.Repository +---@param pull_request adopure.PullRequest +---@return adopure.AdoState function AdoState:new(repository, pull_request) local o = { repository = repository, @@ -44,7 +44,7 @@ function AdoState:new(repository, pull_request) end function AdoState:load_pull_request_iterations() - local iterations, err = require("ado.api").get_pull_request_iterations(self.active_pull_request) + local iterations, err = require("adopure.api").get_pull_request_iterations(self.active_pull_request) if err then error(err) end @@ -53,27 +53,27 @@ end ---@param _ table function AdoState:load_pull_request_threads(_) - local pull_request_threads, err = require("ado.api").get_pull_request_threads(self) + local pull_request_threads, err = require("adopure.api").get_pull_request_threads(self) if err then error(err) end self.pull_request_threads = pull_request_threads end ----@class StateManager ----@field repository Repository ----@field pull_requests PullRequest[] ----@field state AdoState|nil +---@class adopure.StateManager +---@field repository adopure.Repository +---@field pull_requests adopure.PullRequest[] +---@field state adopure.AdoState|nil local StateManager = {} ----@param context AdoContext +---@param context adopure.AdoContext function StateManager:new(context) - local repository, repository_err = require("ado.api").get_repository(context) + local repository, repository_err = require("adopure.api").get_repository(context) if repository_err then error(repository_err) end assert(repository, "No repository with correct name found in project;") - local pull_requests, pull_request_err = require("ado.api").get_pull_requests(repository) + local pull_requests, pull_request_err = require("adopure.api").get_pull_requests(repository) if pull_request_err then error(pull_request_err) end @@ -88,12 +88,12 @@ end ---@param _ table function StateManager:choose_and_activate(_) - require("ado.pickers.pull_request").choose_and_activate(self) + require("adopure.pickers.pull_request").choose_and_activate(self) end ----@param pull_request PullRequest +---@param pull_request adopure.PullRequest function StateManager:set_state_by_choice(pull_request) - self.state = require("ado.state").AdoState:new(self.repository, pull_request) + self.state = require("adopure.state").AdoState:new(self.repository, pull_request) end return { diff --git a/lua/ado/thread.lua b/lua/adopure/thread.lua similarity index 79% rename from lua/ado/thread.lua rename to lua/adopure/thread.lua index 629e8de..ad4d5ba 100644 --- a/lua/ado/thread.lua +++ b/lua/adopure/thread.lua @@ -1,32 +1,32 @@ local M = {} ----@param state AdoState +---@param state adopure.AdoState ---@param bufnr number ----@param comment_reply CommentReply +---@param comment_reply adopure.CommentReply ---@return string|nil err local function submit_thread_reply(state, bufnr, comment_reply) local comments = comment_reply.thread.comments - ---@type NewComment + ---@type adopure.NewComment local new_reply = { parentCommentId = comments[#comments].id - 1, content = table.concat(vim.api.nvim_buf_get_lines(bufnr, 0, -1, false), "\n"), commentType = 1, } local comment, err = - require("ado.api").create_pull_request_comment_reply(state.active_pull_request, comment_reply.thread, new_reply) + require("adopure.api").create_pull_request_comment_reply(state.active_pull_request, comment_reply.thread, new_reply) if err or not comment then return err or "Expected Comment but not nil;" end table.insert(comments, comment) - require("ado.render").render_reply_thread(comment_reply.thread) + require("adopure.render").render_reply_thread(comment_reply.thread) end ----@param state AdoState ----@param thread_context ThreadContext ----@return PullRequestCommentThreadContext|nil pull_request_thread_context, string|nil err +---@param state adopure.AdoState +---@param thread_context adopure.ThreadContext +---@return adopure.PullRequestCommentThreadContext|nil pull_request_thread_context, string|nil err local function get_pull_request_comment_thread_context(state, thread_context) - local iteration_changes, err = require("ado.api").get_pull_requests_iteration_changes( + local iteration_changes, err = require("adopure.api").get_pull_requests_iteration_changes( state.active_pull_request, state.active_pull_request_iteration ) @@ -35,7 +35,7 @@ local function get_pull_request_comment_thread_context(state, thread_context) end for _, change in pairs(iteration_changes) do if change.item.path == thread_context.filePath then - ---@type PullRequestCommentThreadContext + ---@type adopure.PullRequestCommentThreadContext local comment_thread_context = { changeTrackingId = change.changeTrackingId, iterationContext = { @@ -51,17 +51,17 @@ end ---@param bufnr number ---@param mark_id number ----@param state AdoState ----@param thread_to_open Thread +---@param state adopure.AdoState +---@param thread_to_open adopure.Thread local function add_comment_reply(bufnr, mark_id, state, thread_to_open) - ---@type CommentReply + ---@type adopure.CommentReply local comment_reply = { bufnr = bufnr, mark_id = mark_id, thread = thread_to_open } table.insert(state.comment_replies, comment_reply) end ----@param state AdoState +---@param state adopure.AdoState ---@param bufnr number ----@param comment_creation CommentCreate +---@param comment_creation adopure.CommentCreate ---@return string|nil err local function submit_thread(state, bufnr, comment_creation) local pull_request_thread_context, get_err = @@ -70,7 +70,7 @@ local function submit_thread(state, bufnr, comment_creation) return get_err or "Expected PullRequestCommentThreadContext but got nil;" end - ---@type NewThread + ---@type adopure.NewThread local new_thread = { threadContext = comment_creation.thread_context, status = 1, @@ -83,13 +83,13 @@ local function submit_thread(state, bufnr, comment_creation) }, }, } - local thread, err = require("ado.api").create_pull_request_comment_thread(state.active_pull_request, new_thread) + local thread, err = require("adopure.api").create_pull_request_comment_thread(state.active_pull_request, new_thread) if err or not thread then return err or "Expected Thread but got nil;" end table.insert(state.pull_request_threads, thread) local mark_id - bufnr, mark_id = require("ado.render").render_reply_thread(thread) + bufnr, mark_id = require("adopure.render").render_reply_thread(thread) add_comment_reply(bufnr, mark_id, state, thread) end @@ -114,12 +114,12 @@ end ---@param col_start number ---@param line_end number ---@param line_start number ----@return ThreadContext +---@return adopure.ThreadContext local function get_thread_context(col_end, col_start, line_end, line_start) local file_path = "/" .. vim.fn.expand("%:.") if file_path:match("^/diffview://") then local left_path = file_path:gsub("^/diffview://.+/.git/[^/]+(.*)$", "%1") - ---@type ThreadContext + ---@type adopure.ThreadContext return { filePath = left_path, leftFileStart = { line = line_start + 1, offset = col_start + 1 }, @@ -128,7 +128,7 @@ local function get_thread_context(col_end, col_start, line_end, line_start) rightFileEnd = nil, } end - ---@type ThreadContext + ---@type adopure.ThreadContext return { filePath = file_path, leftFileStart = nil, @@ -138,7 +138,7 @@ local function get_thread_context(col_end, col_start, line_end, line_start) } end ----@param state AdoState +---@param state adopure.AdoState ---@param _ table function M.new_thread_window(state, _) local line_start, col_start, line_end, col_end = get_selected_position() @@ -150,9 +150,9 @@ function M.new_thread_window(state, _) end local thread_context = get_thread_context(col_end, col_start, line_end, line_start) - local bufnr, mark_id = require("ado.render").render_new_thread(selection) + local bufnr, mark_id = require("adopure.render").render_new_thread(selection) - ---@type CommentCreate + ---@type adopure.CommentCreate local comment_creation = { bufnr = bufnr, mark_id = mark_id, @@ -161,20 +161,20 @@ function M.new_thread_window(state, _) table.insert(state.comment_creations, comment_creation) end ----@class OpenThreadWindowOpts +---@class adopure.OpenThreadWindowOpts ---@field thread_id number|nil ---Open thread in window ----@param opts OpenThreadWindowOpts +---@param opts adopure.OpenThreadWindowOpts function M.open_thread_window(state, opts) local extmark_id = opts.thread_id if not extmark_id then - local extmarks = require("ado.marker").get_extmarks_at_position() + local extmarks = require("adopure.marker").get_extmarks_at_position() local first_extmark = extmarks[1] extmark_id = first_extmark[1] end - ---@type Thread|nil + ---@type adopure.Thread|nil local thread_to_open for _, pull_request_thread in pairs(state.pull_request_threads) do if pull_request_thread.id == extmark_id then @@ -185,12 +185,12 @@ function M.open_thread_window(state, opts) vim.notify("Did not find thread to open;", 3) return end - local bufnr, mark_id = require("ado.render").render_reply_thread(thread_to_open) + local bufnr, mark_id = require("adopure.render").render_reply_thread(thread_to_open) add_comment_reply(bufnr, mark_id, state, thread_to_open) end ---@param bufnr number ----@return CommentCreate|nil +---@return adopure.CommentCreate|nil local function _get_comment_creation(state, bufnr) for _, comment_creation in pairs(state.comment_creations) do if comment_creation.bufnr == bufnr then @@ -199,9 +199,9 @@ local function _get_comment_creation(state, bufnr) end end ----@param state AdoState +---@param state adopure.AdoState ---@param bufnr number ----@return CommentReply|nil +---@return adopure.CommentReply|nil local function _get_comment_reply(state, bufnr) for _, comment_reply in pairs(state.comment_replies) do if comment_reply.bufnr == bufnr then @@ -221,7 +221,7 @@ local thread_status = { } ---Update pull request thread status ----@param state AdoState +---@param state adopure.AdoState ---@param _ table function M.update_thread_status(state, _) ---@type number @@ -238,21 +238,21 @@ function M.update_thread_status(state, _) return end - ---@type Thread + ---@type adopure.Thread local thread = { ---@diagnostic disable-line: missing-fields id = comment_reply.thread.id, status = choice, } - local updated_thread, err = require("ado.api").update_pull_request_thread(state.active_pull_request, thread) + local updated_thread, err = require("adopure.api").update_pull_request_thread(state.active_pull_request, thread) if err or not updated_thread then error(err or "Expected Thread but not nil;") end comment_reply.thread.status = updated_thread.status - require("ado.render").render_reply_thread(comment_reply.thread) + require("adopure.render").render_reply_thread(comment_reply.thread) end) end ----@param state AdoState +---@param state adopure.AdoState ---@param _ table function M.submit_comment(state, _) ---@type string|nil @@ -266,7 +266,7 @@ function M.submit_comment(state, _) error(err) end state.comment_creations = vim.iter(state.comment_creations) - :filter(function(state_comment_creation) ---@param state_comment_creation CommentCreate + :filter(function(state_comment_creation) ---@param state_comment_creation adopure.CommentCreate return comment_creation.bufnr ~= state_comment_creation.bufnr end) :totable() diff --git a/lua/adopure/types.lua b/lua/adopure/types.lua new file mode 100644 index 0000000..53279e7 --- /dev/null +++ b/lua/adopure/types.lua @@ -0,0 +1,135 @@ +---@class adopure.RequestResult +---@field value any + + +---@class adopure.PullRequest +---@field codeReviewid integer +---@field description string +---@field isDraft boolean +---@field pullRequestId boolean +---@field sourceRefName string +---@field targetRefName string +---@field title string +---@field url string +---@field status string +---@field createdBy adopure.User +---@field creationDate string +---@field mergeStatus string +---@field reviewers adopure.Reviewer[] + +---@class adopure.User +---@field displayName string +---@field id string + +---@class adopure.ConnectionUser +---@field id string +---@field isActive boolean + +---@class adopure.ConnectionData +---@field authenticatedUser adopure.ConnectionUser +---@field authorizedUser adopure.ConnectionUser + +---@class adopure.Reviewer +---@field displayName string +---@field id string +---@field vote PullRequestVote + +---@class adopure.Repository +---@field name string +---@field id string +---@field url string +---@field defaultBranch string + +---@class adopure.Project +---@field id string +---@field name string +---@field url string + +---@class adopure.Thread +---@field id number +---@field comments adopure.Comment[] +---@field threadContext adopure.ThreadContext|nil +---@field status string +---@field isDeleted boolean +---@field publishedDate string +---@field lastUpdatedDate string + +---@class adopure.Comment +---@field id number +---@field commentType string +---@field content string|nil +---@field author adopure.Author +---@field isDeleted boolean +---@field publishedDate string +---@field lastUpdatedDate string +---@field lastContentUpdatedDate string + +---@class adopure.ThreadContext +---@field filePath string +---@field leftFileEnd adopure.Position|nil +---@field leftFileStart adopure.Position|nil +---@field rightFileEnd adopure.Position|nil +---@field rightFileStart adopure.Position|nil + +---@class adopure.Position +---@field line number +---@field offset number + +---@class adopure.Author +---@field id string +---@field displayName string + +---@class adopure.CommentReply +---@field bufnr number +---@field mark_id number +---@field content string|nil +---@field thread adopure.Thread + +---@class adopure.CommentCreate +---@field bufnr number +---@field mark_id number +---@field thread_context adopure.ThreadContext +---@field content string|nil + +---@class adopure.NewThread +---@field comments adopure.NewComment[] +---@field threadContext adopure.ThreadContext +---@field pullRequestThreadContext adopure.PullRequestCommentThreadContext +---@field status number + +---@class adopure.NewComment +---@field parentCommentId number +---@field commentType number +---@field content string + +---@class adopure.PullRequestCommentThreadContext +---@field changeTrackingId number +---@field iterationContext adopure.IterationContext +---@field trackingCriteria adopure.TrackingCriteria + +---@class adopure.IterationContext +---@field firstComparingIteration number +---@field secondComparingIteration number + +---@class adopure.TrackingCriteria +---@field firstComparingIteration number +---@field secondTrackingCriteria number + +---@class adopure.Iteration +---@field id number +---@field sourceRefCommit adopure.CommitRef +---@field targetRefCommit adopure.CommitRef + +---@class adopure.CommitRef +---@field commitId string + +---@class adopure.ChangeEntries +---@field changeEntries adopure.ChangeEntry[] + +---@class adopure.ChangeEntry +---@field changeId number +---@field changeTrackingId number +---@field item adopure.ChangeEntryItem + +---@class adopure.ChangeEntryItem +---@field path string diff --git a/lua/ado/utils.lua b/lua/adopure/utils.lua similarity index 100% rename from lua/ado/utils.lua rename to lua/adopure/utils.lua diff --git a/plugin/init.lua b/plugin/init.lua index f57599e..dbf17c2 100644 --- a/plugin/init.lua +++ b/plugin/init.lua @@ -1,10 +1,10 @@ vim.api.nvim_create_user_command("AdoPure", function(opts) - require("ado").ado_pure(opts) + require("adopure").ado_pure(opts) end, { nargs = "*", range = true, desc = "Azure DevOps Pull Request command.", complete = function(arg_lead, cmdline, _) - return require("ado").auto_completer(arg_lead, cmdline, _) + return require("adopure").auto_completer(arg_lead, cmdline, _) end, }) diff --git a/spec/load_spec.lua b/spec/load_spec.lua index c01b33e..23d6a98 100644 --- a/spec/load_spec.lua +++ b/spec/load_spec.lua @@ -1,7 +1,7 @@ local assert = require("luassert.assert") describe("Load command", function() - ---@type StateManager|nil + ---@type adopure.StateManager|nil local state_manager local function get_secret_value() local secret = os.getenv("AZURE_DEVOPS_EXT_PAT") @@ -20,12 +20,12 @@ describe("Load command", function() it("can retrieve PRs", function() require("plenary.path") - state_manager = require("ado").load_state_manager() + state_manager = require("adopure").load_state_manager() assert.are.same(#state_manager.pull_requests, 1) end) it("can activate a PR", function() - state_manager = require("ado").load_state_manager() + state_manager = require("adopure").load_state_manager() state_manager:set_state_by_choice(state_manager.pull_requests[1]) assert.are.same(state_manager.state.active_pull_request.title, "Updated pr-test-file.md PR title") diff --git a/spec/submit_spec.lua b/spec/submit_spec.lua index 6ffc959..2b0d1b5 100644 --- a/spec/submit_spec.lua +++ b/spec/submit_spec.lua @@ -41,7 +41,7 @@ describe("submit command", function() end before_each(function() - local state_manager = require("ado").load_state_manager() + local state_manager = require("adopure").load_state_manager() state_manager:set_state_by_choice(state_manager.pull_requests[1]) mock_functions() end) @@ -59,16 +59,16 @@ describe("submit command", function() mark_id = 10000, thread_context = thread_context, } - local state = require("ado").get_loaded_state() + local state = require("adopure").get_loaded_state() table.insert(state.comment_creations, comment_creation) - require("ado.thread").submit_comment(state, {}) + require("adopure.thread").submit_comment(state, {}) end it("can submit a comment", function() create_comment() - local state = require("ado").get_loaded_state() - ---@type Thread - local thread = vim.iter(state.pull_request_threads):find(function(thread) ---@param thread Thread + local state = require("adopure").get_loaded_state() + ---@type adopure.Thread + local thread = vim.iter(state.pull_request_threads):find(function(thread) ---@param thread adopure.Thread return thread.comments[1].commentType == "text" end) assert.are.same(expect_message, thread.comments[1].content) @@ -76,32 +76,32 @@ describe("submit command", function() it("can submit a reply", function() create_comment() - local state = require("ado").get_loaded_state() - require("ado.thread").submit_comment(state, {}) + local state = require("adopure").get_loaded_state() + require("adopure.thread").submit_comment(state, {}) assert.are.same(2, #state.pull_request_threads[1].comments) end) it("can submit a thread status change", function() create_comment() - local state = require("ado").get_loaded_state() - require("ado.thread").update_thread_status(state, {}) + local state = require("adopure").get_loaded_state() + require("adopure.thread").update_thread_status(state, {}) assert.are.same("closed", state.pull_request_threads[1].status) end) it("can submit a pull request vote", function() - local state = require("ado").get_loaded_state() + local state = require("adopure").get_loaded_state() ---@diagnostic disable-next-line: unused-local vim.ui.select = function(_1, _2, cb) ---@diagnostic disable-line: duplicate-set-field local _, _ = _1, _2 cb("approved") end - require("ado.review").submit_vote(state, {}) + require("adopure.review").submit_vote(state, {}) assert.are.same(10, state.active_pull_request.reviewers[1].vote) vim.ui.select = function(_1, _2, cb) ---@diagnostic disable-line: duplicate-set-field local _, _ = _1, _2 cb("no vote") end - require("ado.review").submit_vote(state, {}) + require("adopure.review").submit_vote(state, {}) end) local function unmock_functions() @@ -111,11 +111,11 @@ describe("submit command", function() end after_each(function() - local state = require("ado").get_loaded_state() + local state = require("adopure").get_loaded_state() for _, thread in pairs(state.pull_request_threads) do for _, comment in pairs(thread.comments) do local _, err = - require("ado.api").delete_pull_request_comment(state.active_pull_request, thread, comment.id) + require("adopure.api").delete_pull_request_comment(state.active_pull_request, thread, comment.id) if err then error(err) end