diff --git a/README.md b/README.md index 9661eac..29abf92 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,28 @@ require('lazy').setup({ }) ``` +## Configfile + +Create a `~/.config/ndoo/config.json` file with the following content: + +```json +{ + "bitbucket_use_jira_issues": true, + "bitbucket_username": "gorillamoe", + "bitbucket_app_password": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +} +``` + +The `bitbucket_use_jira_issues` key optional and only needed if you want to use the Jira integration +in your Bitbucket repositories. + +The `bitbucket_username` and `bitbucket_app_password` are required for the Bitbucket integration. + +You can obtain the `bitbucket_app_password` by going to your Bitbucket settings and +creating a new app password. + +The username is your Bitbucket username. + ## Public methods ### `require('ndoo').open()` diff --git a/lua/ndoo/init.lua b/lua/ndoo/init.lua index 076831b..2d29058 100644 --- a/lua/ndoo/init.lua +++ b/lua/ndoo/init.lua @@ -1,3 +1,5 @@ +local CONFIG = require("ndoo.config") +local JSON_CONFIG = CONFIG.get_config_json() local HELPER = require("ndoo.helper") local PORTALS = require("ndoo.portals") local GITHUB = require("ndoo.portals.github") @@ -181,6 +183,10 @@ function M.issues() open_slug("issues/" .. issue_number) end) elseif PORTALS.is_bitbucket() then + if JSON_CONFIG.bitbucket_use_jira_issues ~= nil then + open_slug("jira") + return + end BITBUCKET.show_bitbucket_issues_picker(function(issue_number) if (issue_number == nil) then print("no issue selected") diff --git a/lua/ndoo/portals/bitbucket.lua b/lua/ndoo/portals/bitbucket.lua index 278c653..dffe8a6 100644 --- a/lua/ndoo/portals/bitbucket.lua +++ b/lua/ndoo/portals/bitbucket.lua @@ -4,16 +4,22 @@ local JSON_CONFIG = CONFIG.get_config_json() local USERNAME = JSON_CONFIG.bitbucket_username local APP_PASSWORD = JSON_CONFIG.bitbucket_app_password local BASE64_CREDS = vim.base64.encode(USERNAME .. ":" .. APP_PASSWORD) +local REPO_OWNER = nil +local REPO_NAME = nil local M = {} M.base_url = "https://bitbucket.org/" -M.API_BASE_URL = "https://api.bitbucket.org" +M.API_BASE_URL = "https://api.bitbucket.org/2.0/repositories/" local function get_data(slug) - local repo_owner = M.get_bitbucket_repo_owner() - local repo_name = M.get_bitbucket_repo_name() - local curl_cmd = "curl -s -X GET -H 'Authorization: Basic " .. BASE64_CREDS .. "' " .. M.API_BASE_URL .. "/2.0/repositories/" .. repo_owner .. "/" .. repo_name .. "/" .. slug + if REPO_OWNER == nil then + REPO_OWNER = M.get_bitbucket_repo_owner() + end + if REPO_NAME == nil then + REPO_NAME = M.get_bitbucket_repo_name() + end + local curl_cmd = "curl -s -X GET -H 'Authorization: Basic " .. BASE64_CREDS .. "' " .. M.API_BASE_URL .. REPO_OWNER .. "/" .. REPO_NAME .. "/" .. slug local jsonstr = vim.fn.system(curl_cmd) local data = vim.fn.json_decode(jsonstr) return data