2022-09-26 02:09:22 +03:00
|
|
|
local utils = require("openingh.utils")
|
|
|
|
|
local M = {}
|
2022-09-25 23:53:23 +03:00
|
|
|
|
2022-09-26 02:09:22 +03:00
|
|
|
function M.setup()
|
|
|
|
|
local repo_url = vim.fn.system("git config --get remote.origin.url")
|
|
|
|
|
|
|
|
|
|
if repo_url:len() == 0 then
|
|
|
|
|
M.is_no_git_origin = true
|
|
|
|
|
vim.g.openingh = false
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-26 22:57:58 +03:00
|
|
|
-- init global variables
|
2022-09-26 02:09:22 +03:00
|
|
|
local username_and_reponame = utils.get_username_reponame(repo_url)
|
|
|
|
|
M.username = username_and_reponame.username
|
|
|
|
|
M.reponame = username_and_reponame.reponame
|
|
|
|
|
M.gh_url = "https://github.com/"
|
2022-09-26 22:57:58 +03:00
|
|
|
M.repo_url = M.gh_url .. M.username .. "/" .. M.reponame
|
2022-09-26 02:09:22 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M.openFile()
|
|
|
|
|
-- TODO - 3: get the selected range in the buffer and add it to the file url
|
|
|
|
|
if M.is_no_git_origin then
|
|
|
|
|
utils.print_no_remote_message()
|
|
|
|
|
return
|
|
|
|
|
end
|
2022-09-26 22:57:58 +03:00
|
|
|
|
|
|
|
|
local file_path = utils.get_current_relative_file_path()
|
|
|
|
|
local current_branch_name = utils.get_current_branch()
|
|
|
|
|
|
|
|
|
|
local file_page_url = M.repo_url .. "/blob/" .. current_branch_name .. file_path
|
|
|
|
|
|
|
|
|
|
local result = utils.open_url(file_page_url)
|
|
|
|
|
|
|
|
|
|
if result then
|
|
|
|
|
print("Opening url " .. file_page_url)
|
|
|
|
|
else
|
|
|
|
|
print("Unknown OS please open report")
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-26 02:09:22 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M.openRepo()
|
|
|
|
|
if M.is_no_git_origin then
|
|
|
|
|
utils.print_no_remote_message()
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-26 22:57:58 +03:00
|
|
|
local repo_page_url = M.repo_url
|
2022-09-26 21:43:50 +03:00
|
|
|
local current_branch_name = utils.get_current_branch()
|
|
|
|
|
|
2022-09-26 23:02:31 +03:00
|
|
|
repo_page_url = M.repo_url .. "/tree/" .. current_branch_name
|
2022-09-26 21:43:50 +03:00
|
|
|
|
2022-09-26 22:57:58 +03:00
|
|
|
local result = utils.open_url(repo_page_url)
|
2022-09-26 02:09:22 +03:00
|
|
|
|
|
|
|
|
if result then
|
2022-09-26 22:57:58 +03:00
|
|
|
print("Opening url " .. repo_page_url)
|
2022-09-26 02:09:22 +03:00
|
|
|
else
|
|
|
|
|
print("Unknown OS please open report")
|
2022-09-25 23:53:23 +03:00
|
|
|
end
|
2022-09-26 02:09:22 +03:00
|
|
|
end
|
2022-09-25 23:53:23 +03:00
|
|
|
|
|
|
|
|
return M
|