From 4c1fcb5d16b7d007cd70d5e1f2769f580b9044d2 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 7 Jun 2017 19:04:29 -0400 Subject: [PATCH] More versatile API URL generation --- autoload/rhubarb.vim | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/autoload/rhubarb.vim b/autoload/rhubarb.vim index ac9a04a..0b31323 100644 --- a/autoload/rhubarb.vim +++ b/autoload/rhubarb.vim @@ -138,7 +138,7 @@ function! s:curl_arguments(path, ...) abort elseif has_key(options, 'data') call extend(args, ['-d', options.data]) endif - call add(args, a:path =~# '://' ? a:path : 'https://api.github.com'.a:path) + call add(args, a:path) return args endfunction @@ -146,8 +146,21 @@ function! rhubarb#request(path, ...) abort if !executable('curl') call s:throw('cURL is required') endif + if a:path =~# '://' + let path = a:path + elseif a:path =~# '^/' + let path = 'https://api.github.com' . a:path + else + let base = s:repo_homepage() + let path = substitute(a:path, '%s', matchstr(base, '[^/]\+/[^/]\+$'), '') + if base =~# '//github\.com/' + let path = 'https://api.github.com/' . path + else + let path = substitute(base, '[^/]\+/[^/]\+$', 'api/v3/', '') . path + endif + endif let options = a:0 ? a:1 : {} - let args = s:curl_arguments(a:path, options) + let args = s:curl_arguments(path, options) let raw = system('curl '.join(map(copy(args), 's:shellesc(v:val)'), ' ')) if raw ==# '' return raw @@ -157,13 +170,7 @@ function! rhubarb#request(path, ...) abort endfunction function! rhubarb#repo_request(...) abort - let base = s:repo_homepage() - if base =~# '//github\.com/' - let base = substitute(base, '//github\.com/', '//api.github.com/repos/', '') - else - let base = substitute(base, '//[^/]\+/\zs', 'api/v3/repos/', '') - endif - return rhubarb#request(base . (a:0 && a:1 !=# '' ? '/' . a:1 : ''), a:0 > 1 ? a:2 : {}) + return rhubarb#request('repos/%s' . (a:0 && a:1 !=# '' ? '/' . a:1 : ''), a:0 > 1 ? a:2 : {}) endfunction " Section: Issues