Skip to content

Commit

Permalink
Merge pull request #11 from mistweaverco/feat/all-the-portals
Browse files Browse the repository at this point in the history
feat: support multiple portals
  • Loading branch information
gorillamoe authored Jul 4, 2024
2 parents eb1e239 + 9964bfd commit 239074c
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 290 deletions.
42 changes: 42 additions & 0 deletions lua/ndoo/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local M = {}
local DEFAULT_CONFIG = {}
local UV = vim.loop

local function get_os_path_separator()
if vim.fn.has("win32") == 1 then
return "\\"
else
return "/"
end
end

M.PS = get_os_path_separator()

M.get_config = function()
return config
end

M.set_config = function(config)
config = config or {}
config = vim.tbl_deep_extend("force", DEFAULT_CONFIG, config)
end

M.get_config_dir = function()
local config_dir = vim.fn.stdpath("config")
return config_dir:match("(.*)" .. M.PS .. ".*") .. M.PS .. "ndoo"
end

M.get_config_json = function()
local config_dir = M.get_config_dir()
local config_file = config_dir .. M.PS .. "config.json"
local config = {}
if vim.fn.filereadable(config_file) == 1 then
local file = io.open(config_file, "r")
local content = file:read("*a")
config = vim.fn.json_decode(content)
file:close()
end
return config
end

return M
6 changes: 0 additions & 6 deletions lua/ndoo/github/init.lua

This file was deleted.

104 changes: 0 additions & 104 deletions lua/ndoo/helper/init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
local telescope_pickers = require "telescope.pickers"
local telescope_finders = require "telescope.finders"
local telescope_conf = require("telescope.config").values
local telescope_actions = require "telescope.actions"
local telescope_action_state = require "telescope.actions.state"
local telescope_themes = require("telescope.themes")
local telescope_theme_dropdown = telescope_themes.get_dropdown{}
local json = require("ndoo.helper.json")
local pickers = require("ndoo.helper.pickers")

local M = {}
Expand All @@ -18,52 +10,6 @@ function M.get_current_git_commit_hash()
return commit_hash
end

function M.show_github_labels_picker(cb_func)
local jsonstr = vim.fn.system("gh label list --json name,description,url -L 30")
local pulls = json.parse(jsonstr)

pickers.generic_table_picker({
prompt_title = "Pick a label",
dropdown = true,
results = pulls,
entry_maker_value_key = "url",
entry_maker_display_key = "name",
entry_maker_ordinal_key = "name",
cb_func = cb_func,
})
end

function M.show_github_pull_picker(cb_func)
local jsonstr = vim.fn.system("gh pr list --json number,title,body,updatedAt -L 2000")
local pulls = json.parse(jsonstr)

pickers.generic_table_picker({
prompt_title = "Pick a pull",
results = pulls,
entry_maker_value_key = "number",
entry_maker_display_key = "title",
entry_maker_ordinal_key = "title",
preview = true,
previewer_value_key = "body",
cb_func = cb_func,
})
end

function M.show_github_issues_picker(cb_func)
local jsonstr = vim.fn.system("gh issue list --json number,title,body,updatedAt -L 2000")
local issues = json.parse(jsonstr)

pickers.generic_table_picker({
prompt_title = "Pick an issue",
results = issues,
entry_maker_value_key = "number",
entry_maker_display_key = "title",
entry_maker_ordinal_key = "title",
preview = true,
previewer_value_key = "body",
cb_func = cb_func,
})
end

function M.get_current_git_branch()
local branch = vim.fn.systemlist("git branch --show-current")[1]
Expand Down Expand Up @@ -108,55 +54,5 @@ function M.open_url_in_browser(url)
end
end

function M.get_github_remote_url(remote)
if remote == nil then
remote = "origin"
end
local url = vim.fn.systemlist("git remote get-url " .. remote)[1]
if url == "" then
return nil
end
return url
end

function M.get_github_repo_protocol()
local url = M.get_github_remote_url()
if url:match("^git@") then
return "ssh"
end
if url:match("^https://") then
return "https"
end
return nil
end

function M.get_github_repo_name(remote)
local url = M.get_github_remote_url(remote)
if url == nil then
return nil
end
local repo_name = url:match("^.+/(.+)$")
if repo_name == nil then
return nil
end
repo_name = repo_name:gsub("%.git$", "")
return repo_name
end

function M.get_github_repo_owner(remote)
local url = M.get_github_remote_url(remote)
if url == nil then
return nil
end
local repo_owner = nil
local repo_protocol = M.get_github_repo_protocol(remote)
if repo_protocol == "ssh" then
repo_owner = url:match("^.+:(.+)/.+$")
end
if repo_protocol == "https" then
repo_owner = url:match("^.+/(.+)/.+$")
end
return repo_owner
end

return M
147 changes: 0 additions & 147 deletions lua/ndoo/helper/json.lua

This file was deleted.

Loading

0 comments on commit 239074c

Please sign in to comment.