From dbc16962d31c774a8df6d3bf781839d815f9354b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 27 Aug 2011 13:05:15 -0400 Subject: [PATCH] Initial commit --- .gitignore | 1 + README.markdown | 62 ++++++++++++++++++++++++++ doc/rhubarb.txt | 15 +++++++ plugin/rhubarb.vim | 109 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 .gitignore create mode 100644 README.markdown create mode 100644 doc/rhubarb.txt create mode 100644 plugin/rhubarb.vim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a56e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/doc/tags diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..6fcf46e --- /dev/null +++ b/README.markdown @@ -0,0 +1,62 @@ +rhubarb.vim +=========== + +If [fugitive.vim][] is the Git, rhubarb.vim is the Hub. Or at least it +could be. One day. Right now it's pretty stupid. I almost named it +chubby.vim, but it just didn't feel right. + +So far there's only one feature: In Git commit messages, GitHub issues +can be omni-completed (``, see `:help compl-omni`). This +makes inserting those `Closes #123` remarks slightly easier than copying +and pasting from the browser. + +Maybe I'll extract `:Gbrowse` out of fugitive.vim and put it here +instead. Or maybe I'll add some cool Gist stuff. You never know with +rhubarb.vim. + +[fugitive.vim]: https://github.com/tpope/vim-fugitive + +Installation +------------ + +In addition to [fugitive.vim][], [Curl](http://curl.haxx.se/) is +required (included with OS X). If you haven't already, you'll need to +set up your [GitHub API +token](http://help.github.com/set-your-user-name-email-and-github-token/). + +If you don't have a preferred installation method, I recommend +installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and +then simply copy and paste: + + cd ~/.vim/bundle + git clone git://github.com/tpope/vim-rhubarb.git + +Once help tags have been generated, you can view the manual with +`:help rhubarb`. + +FAQ +--- + +> How do I turn off that preview window that shows the issue body? + + set completeopt-=preview + +Contributing +------------ + +See the contribution guidelines for +[fugitive.vim](https://github.com/tpope/vim-fugitive#readme). + +Self-Promotion +-------------- + +Like rhubarb.vim? Follow the repository on +[GitHub](https://github.com/tpope/vim-rhubarb). And if +you're feeling especially charitable, follow [tpope](http://tpo.pe/) on +[Twitter](http://twitter.com/tpope) and +[GitHub](https://github.com/tpope). + +License +------- + +Distributable under the same terms as Vim itself. See `:help license`. diff --git a/doc/rhubarb.txt b/doc/rhubarb.txt new file mode 100644 index 0000000..2fd3be3 --- /dev/null +++ b/doc/rhubarb.txt @@ -0,0 +1,15 @@ +*rhubarb.txt* fugitive.vim extension for GitHub + +Author: Tim Pope +License: Same terms as Vim itself (see |license|) + +Use |i_CTRL-X_CTRL-O| to omni-complete GitHub issues when editing a commit +message. + +ABOUT *rhubarb-about* + +Grab the latest version or report a bug on GitHub: + +http://github.com/tpope/vim-rhubarb + + vim:tw=78:et:ft=help:norl: diff --git a/plugin/rhubarb.vim b/plugin/rhubarb.vim new file mode 100644 index 0000000..737370f --- /dev/null +++ b/plugin/rhubarb.vim @@ -0,0 +1,109 @@ +" rhubarb.vim - fugitive.vim extension for GitHub +" Maintainer: Tim Pope + +if exists("g:loaded_rhubarb") || v:version < 700 || &cp + finish +endif +let g:loaded_rhubarb = 1 + +" Utility {{{1 + +function! s:throw(string) abort + let v:errmsg = 'rhubarb: '.a:string + throw v:errmsg +endfunction + +function! s:repo_name() + if !exists('b:github_repo') + let repo = fugitive#buffer().repo() + let url = repo.config('remote.origin.url') + if url !~# 'github\.com[:/][^/]*/[^/]*\.git' + call s:throw('origin is not a GitHub repository: '.url) + endif + let b:github_repo = matchstr(url,'github\.com[:/]\zs[^/]*/[^/]*\ze\.git') + endif + return b:github_repo +endfunction + +" }}}1 +" HTTP {{{1 + +function! s:credentials() + if !exists('g:github_user') + let g:github_user = $GITHUB_USER + if g:github_user ==# '' + let g:github_user = system('git config --get github.user')[0:-2] + endif + if g:github_user ==# '' + let g:github_user = $LOGNAME + endif + endif + if !exists('g:github_token') + let g:github_token = $GITHUB_TOKEN + if g:github_token ==# '' + let g:github_token = system('git config --get github.token')[0:-2] + endif + endif + return g:github_user.'/token:'.g:github_token +endfunction + +function! rhubarb#json_parse(string) + let [null, false, true] = ['', 0, 1] + let stripped = substitute(a:string,'\C"\(\\.\|[^"\\]\)*"','','g') + if stripped !~# "[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \n\r\t]" + try + return eval(substitute(a:string,"[\r\n]"," ",'g')) + catch + endtry + endif + call s:throw("invalid JSON: ".stripped) +endfunction + +function! rhubarb#get(path) + if !executable('curl') + call s:throw('cURL is required') + endif + let url = a:path =~# '://' ? a:path : 'https://github.com/api/v2/json'.a:path + let url = substitute(url,'%s','\=s:repo_name()','') + let output = system('curl -s -L -H "Accept: application/json" -H "Content-Type: application/json" -u "'.s:credentials().'" '.url) + return rhubarb#json_parse(output) +endfunction + +" }}}1 +" Issues {{{1 + +function! rhubarb#issues(...) + return rhubarb#get('/issues/list/%s/'.(a:0 ? a:1 : 'open'))['issues'] +endfunction + +function! rhubarb#omnifunc(findstart,base) + if a:findstart + let existing = matchstr(getline('.')[0:col('.')-1],'#\d*$') + return col('.')-1-strlen(existing) + endif + try + return map(reverse(rhubarb#issues()),'{"word": "#".v:val.number, "menu": v:val.title, "info": substitute(v:val.body,"\\r","","g")}') + catch /^\%(fugitive\|rhubarb\):/ + return v:errmsg + endtry +endfunction + +augroup rhubarb + autocmd! + autocmd User Fugitive + \ if fugitive#buffer().path() =~# '^\.git.COMMIT_EDITMSG$' && + \ exists('+omnifunc') && + \ &omnifunc =~# '^\%(syntaxcomplete#Complete\)\=$' && + \ join(readfile(fugitive#buffer().repo().dir('config')),"\n") + \ =~# '\n[^;]*github\.com' | + \ setlocal omnifunc=rhubarb#omnifunc | + \ endif + autocmd BufEnter * + \ if expand('%') ==# '' && &previewwindow && pumvisible() && getbufvar('#', '&omnifunc') ==# 'rhubarb#omnifunc' | + \ setlocal nolist linebreak filetype=markdown | + \ endif +augroup END + +" }}}1 + +" vim:set sw=2 sts=2: