From b30894369c33360726973453d38d6fec58e202fe Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 31 Mar 2023 13:32:08 +0800 Subject: [PATCH] fix(github api): fix authentication --- .ci/detach_plugin.sh | 21 +++++++++++++++++++ .github/workflows/async.yml | 2 +- bundle/github.vim/autoload/github/api.vim | 7 +++++++ .../github.vim/autoload/github/api/issues.vim | 11 ++++++++-- bundle/github.vim/plugin/github.vim | 2 ++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/.ci/detach_plugin.sh b/.ci/detach_plugin.sh index cb07312f7..fa4ff1fd8 100755 --- a/.ci/detach_plugin.sh +++ b/.ci/detach_plugin.sh @@ -366,6 +366,27 @@ EOT rm -rf detach/$1 exit 0 ;; + github.vim) + git clone https://github.com/wsdjeg/GitHub.vim.git detach/$1 + cd detach/$1 + _checkdir plugin/ + _checkdir autoload/ + _detact LICENSE + _detact_bundle github.vim autoload/github.vim + _detact_bundle github.vim plugin/github.vim + _default_readme "GitHub.vim" "GitHub API support for neovim/vim[wip]" + _checkdir doc/ + _detact_bundle github doc/github.txt + git add . + git config user.email "wsdjeg@qq.com" + git config user.name "SpaceVimBot" + git commit -m "Auto Update based on https://github.com/SpaceVim/SpaceVim/commit/${GITHUB_SHA}" + git remote add wsdjeg_github_vim https://SpaceVimBot:${BOTSECRET}@github.com/wsdjeg/GitHub.vim.git + git push wsdjeg_github_vim master + cd - + rm -rf detach/$1 + exit 0 + ;; spacevim-theme) exit 0 esac diff --git a/.github/workflows/async.yml b/.github/workflows/async.yml index 170195d4f..b179ed9db 100644 --- a/.github/workflows/async.yml +++ b/.github/workflows/async.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - detachPlugin: ["flygrep", "dein-ui", "vim-todo", "iedit", "scrollbar.vim", "vim-chat", "vim-cheat", "xmake.vim"] + detachPlugin: ["flygrep", "dein-ui", "vim-todo", "iedit", "scrollbar.vim", "vim-chat", "vim-cheat", "xmake.vim", "github.vim"] runs-on: ubuntu-latest steps: - name: Checkout diff --git a/bundle/github.vim/autoload/github/api.vim b/bundle/github.vim/autoload/github/api.vim index e69de29bb..6384e0c8b 100644 --- a/bundle/github.vim/autoload/github/api.vim +++ b/bundle/github.vim/autoload/github/api.vim @@ -0,0 +1,7 @@ +function! github#api#authorize() abort + if !empty(g:githubapi_token) + return ['--header', "Authorization: Bearer " . g:githubapi_token] + else + return [] + endif +endfunction diff --git a/bundle/github.vim/autoload/github/api/issues.vim b/bundle/github.vim/autoload/github/api/issues.vim index fba6c3022..82917e8ca 100644 --- a/bundle/github.vim/autoload/github/api/issues.vim +++ b/bundle/github.vim/autoload/github/api/issues.vim @@ -107,11 +107,18 @@ endfunction " < " Github API : POST /repos/:owner/:repo/issues function! github#api#issues#Create(owner,repo,user,password,issue) abort + if empty(a:password) || empty(a:user) return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues', - \ ['-X', 'POST', '-d', json_encode(a:issue), - \ '-u', a:user . ':' . a:password]) + \ ['-X', 'POST', '-d', json_encode(a:issue) + \ ] + github#api#authorize()) + else + return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues', + \ ['-X', 'POST', '-d', json_encode(a:issue), + \ '-u', a:user . ':' . a:password]) + endif endfunction + "" " Edit an issue " PATCH /repos/:owner/:repo/issues/:number diff --git a/bundle/github.vim/plugin/github.vim b/bundle/github.vim/plugin/github.vim index fb3d16145..11644cace 100644 --- a/bundle/github.vim/plugin/github.vim +++ b/bundle/github.vim/plugin/github.vim @@ -13,6 +13,8 @@ let g:githubapi_root_url = 'https://api.github.com/' "" " set githubapi verbose when run shell command. By default it is 0. let g:githubapi_verbose = get(g:, 'githubapi_verbose', 0) + +let g:githubapi_token = '' "" " Specific the path for curl, by default it is 'curl', in windows you can use " >