1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-13 12:19:10 +08:00

chore(github): use bundle github.vim

This commit is contained in:
wsdjeg 2022-04-28 21:46:05 +08:00
parent e360f0c9d5
commit d64edc6302
38 changed files with 3439 additions and 1 deletions

View File

@ -41,7 +41,7 @@ function! SpaceVim#layers#github#plugins() abort
\ 'depends': 'open-browser.vim',
\ 'on_cmd': ['OpenGithubFile', 'OpenGithubIssue', 'OpenGithubPullReq'],
\ }],
\ ['wsdjeg/GitHub-api.vim', {'merged' : 0}],
\ [g:_spacevim_root_dir . 'bundle/github.com', {'merged' : 0}],
\ ['lambdalisue/vim-gista', {'merged' : 0}],
\ ]
endfunction

3
bundle/github.vim/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
libs/GitHub-api/target
build/
tags

View File

@ -0,0 +1,71 @@
language: python
sudo: false
notifications:
slack:
on_success: never
on_failure: never
email:
on_success: never # default: change
on_failure: never # default: always
cache:
pip: true
env:
global:
- DEPS=$HOME/deps
- PATH=$DEPS/bin:$PATH
matrix:
- LINT=vimlint-errors
- LINT=vimlint
- LINT=vint-errors
- LINT=vint
- LINT=vader
matrix:
allow_failures:
- env: LINT=vimlint
- env: LINT=vint
install:
- |
set -e
if [ "${LINT#vimlint}" != "$LINT" ]; then
git clone --depth=1 https://github.com/syngan/vim-vimlint /tmp/vimlint
git clone --depth=1 https://github.com/ynkdir/vim-vimlparser /tmp/vimlparser
elif [ "${LINT#vint}" != "$LINT" ]; then
virtualenv /tmp/vint && source /tmp/vint/bin/activate && pip install vim-vint
elif [ "${LINT#vader}" != "$LINT" ]; then
git clone --depth=1 https://github.com/Shougo/dein.vim.git ~/.cache/vimfiles/repos/github.com/Shougo/dein.vim
C_OPTS="--prefix=$DEPS --with-features=huge --disable-gui --enable-pythoninterp"
(git clone --depth 1 https://github.com/vim/vim /tmp/vim &&
cd /tmp/vim &&
./configure $C_OPTS &&
make install)
fi
script:
- |
set -ex
if [ "$LINT" = "vimlint" ]; then
for file in $(git diff --name-only HEAD dev | grep .vim$);
do
sh /tmp/vimlint/bin/vimlint.sh -l /tmp/vimlint -p /tmp/vimlparser $file;
done
elif [ "$LINT" = "vimlint-errors" ]; then
for file in $(git diff --name-only HEAD dev | grep .vim$);
do
sh /tmp/vimlint/bin/vimlint.sh -E -l /tmp/vimlint -p /tmp/vimlparser $file;
done
elif [ "$LINT" = "vint" ]; then
vint .
elif [ "$LINT" = "vint-errors" ]; then
vint --error .
elif [ "$LINT" = "vader" ]; then
pip install covimerage
make test_coverage
covimerage -vv xml --omit 'build/*'
pip install codecov
codecov -X search gcov pycov -f coverage.xml
fi
set +x

View File

@ -0,0 +1,9 @@
cmdargs:
# Checking more strictly
severity: style_problem
policies:
ProhibitImplicitScopeVariable:
enabled: false
ProhibitAbbreviationOption:
enabled: false

21
bundle/github.vim/LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Wang Shidong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,23 @@
test: build/vader | build
vim -Nu test/vimrc -c 'Vader! test/**'
COVIMERAGE=$(shell command -v ccovimerage 2>/dev/null || echo build/covimerage/bin/covimerage)
test_coverage: $(COVIMERAGE) build/vader | build
$(COVIMERAGE) run vim -Nu test/vimrc -c 'Vader! test/**'
build/covimerage:
virtualenv $@
build/covimerage/bin/covimerage: | build/covimerage
build/covimerage/bin/pip install covimerage
build/vader:
git clone --depth 1 https://github.com/junegunn/vader.vim.git $@
build:
mkdir -p $@
clean:
$(RM) -r build
.PHONY: clean test

View File

@ -0,0 +1,60 @@
# GitHub.vim
> Another github v3 api implemented in viml
[![Build Status](https://travis-ci.org/wsdjeg/GitHub.vim.svg?branch=master)](https://travis-ci.org/wsdjeg/GitHub.vim)
[![codecov](https://codecov.io/gh/wsdjeg/GitHub.vim/branch/master/graph/badge.svg)](https://codecov.io/gh/wsdjeg/GitHub.vim)
[![Gitter](https://badges.gitter.im/wsdjeg/GitHub.vim.svg)](https://gitter.im/wsdjeg/GitHub.vim?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Version 0.1.2](https://img.shields.io/badge/version-0.1.1-yellow.svg?style=flat-square)](https://github.com/wsdjeg/GitHub.vim/releases)
[![Support Vim 7.4 or above](https://img.shields.io/badge/support-%20Vim%207.4%20or%20above-yellowgreen.svg?style=flat-square)](https://github.com/vim/vim-win32-installer)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
[![Doc](https://img.shields.io/badge/doc-%3Ah%20github-orange.svg?style=flat-square)](doc/github.txt)
## Intro
This is a viml library to access the Github API v3. With it, you can manage
Github resources (repositories, user profiles, organizations, etc.) from viml
scripts.
It is WIP, it will covers the full API.
[![Throughput Graph](https://graphs.waffle.io/wsdjeg/GitHub.vim/throughput.svg)](https://waffle.io/wsdjeg/GitHub.vim/metrics/throughput)
If you have any question, any remark, or if you find a bug, or if there is
something you can do with the API but not with Github-api.vim, please open an issue.
## Install
It is easy to install the lib via [dein](https://github.com/Shougo/dein.vim):
```vim
call dein#add('wsdjeg/GitHub.vim')
```
**NOTE:** For unauthenticated requests, the rate limit allows for up to 60 requests per hour. Unauthenticated requests are associated with the originating IP address, and not the user making requests.Increasing the unauthenticated rate limit, you need [Create OAuth app](https://github.com/settings/applications/new), and set EVN: `CLIENTID` and `CLIENTSECRET`.
## Usage
create issue:
```viml
function! CreateIssue(owner, repo) abort
let username = input('your github username:')
let password = input('your github password:')
let title = input('Issue title: ')
let issue = {
\ 'title': title,
\ 'body': s:body(),
\ }
let response = github#api#issues#Create(a:owner, a:repo,
\ username, password, issue)
if !empty(response)
echomsg 'Create successed! ' . response.url
else
echom 'Create failed!'
endif
endfunction
func! s:body()
return 'Testting Github.vim...'
endf
```

View File

@ -0,0 +1 @@
theme: jekyll-theme-slate

View File

@ -0,0 +1,5 @@
{
"name": "github",
"description": "Implement Github API via viml",
"author": "Wang Shidong"
}

View File

@ -0,0 +1,14 @@
""
" @public
" List all orgs in github,{since} is the integer ID of the last Organization
" that you've seen.
"
" Github API : GET /organizations
function! github#ListAllOrgs(since) abort
let url = 'organizations'
if !empty(a:since)
let url = url . '?since=' . a:since
endif
return githubapi#util#Get([url], [])
endfunction

View File

@ -0,0 +1,345 @@
""
" @public
" List public events
"
" Github API : GET /events
function! github#api#activity#List_events() abort
return github#api#util#Get('events', [])
endfunction
""
" @public
" List repository events
"
" Github API : GET /repos/:owner/:repo/events
function! github#api#activity#List_repo_events(owner,repo) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'events'], '/'), [])
endfunction
""
" @public
" List public events for a network of repositories
"
" Github API : GET /networks/:owner/:repo/events
function! github#api#activity#List_net_events(owner,repo) abort
return github#api#util#Get(join(['networks', a:owner, a:repo, 'events'], '/'), [])
endfunction
""
" @public
" List public events for an organization
"
" Github API : GET /orgs/:org/events
function! github#api#activity#List_org_events(org) abort
return github#api#util#Get(join(['orgs/', a:org, 'events'], '/'), [])
endfunction
""
" @public
" List events that a user has received
"
" These are events that you've received by watching repos and following users.
" If you are authenticated as the given user, you will see private events.
" Otherwise, you'll only see public events.
"
" Github API : GET /users/:username/received_events
function! github#api#activity#List_user_events(user) abort
return github#api#util#Get(join(['users', a:user, 'received_events'], '/'), [])
endfunction
""
" @public
" List public events that a user has received
"
" Github API : GET /users/:username/received_events/public
function! github#api#activity#List_public_user_events(user) abort
return github#api#util#Get(join(['users', a:user, 'received_events', 'public'], '/'), [])
endfunction
""
" @public
" List events performed by a user
"
" If you are authenticated as the given user, you will see your private events.
" Otherwise, you'll only see public events.
"
" Github API : GET /users/:username/events
function! github#api#activity#Performed_events(user) abort
return github#api#util#Get(join(['users', a:user, 'events'], '/'), [])
endfunction
""
" @public
" List public events performed by a user
"
" Github API : GET /users/:username/events/public
function! github#api#activity#Performed_public_events(user) abort
return github#api#util#Get(join(['users', a:user, 'events', 'public'], '/'), [])
endfunction
""
" @public
" List events for an organization
"
" NOTE:This is the user's organization dashboard. You must be authenticated as the user to view this.
"
" Github API : GET /users/:username/events/orgs/:org
function! github#api#activity#List_user_org_events(user,org,password) abort
return github#api#util#Get(join(['users', a:user, 'events', 'org', a:org], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
" Notification Reasons
function! s:notification_reason(n) abort
let reasons = {
\ 'subscribed': 'The notification arrived because you`re watching the repository',
\ 'manual': 'The notification arrived because you`ve specifically decided'
\ . ' to subscribe to the thread (via an Issue or Pull Request)',
\ 'author': 'The notification arrived because you`ve created the thread',
\ 'comment': 'The notification arrived because you`ve commented on the thread',
\ 'mention': 'The notification arrived because you were specifically @mentioned in the content',
\ 'team_mention': 'The notification arrived because you were on a team that was mentioned (like @org/team)',
\ 'state_change': 'The notification arrived because you changed the thread state '
\ . '(like closing an Issue or merging a Pull Request)',
\ 'assign': 'The notification arrived because you were assigned to the Issue',
\}
return { 'reason' : a:n.reason . '->' . reasons[a:n.reason]}
endfunction
""
" @public
" List your notifications
"
" Github API : /notifications
function! github#api#activity#List_notifications(user,password) abort
return github#api#util#Get('notifications', ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" List your notifications in a repository
"
" Github API : GET /repos/:owner/:repo/notifications
function! github#api#activity#List_notifications_for_repo(onwer,repo,user,password) abort
return github#api#util#Get(join(['repos', a:onwer, a:repo, 'notifications'], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Mark as read,you need use {last_read_at} as args.
" This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Default: Time.now
"
" Github API : PUT /notifications
function! github#api#activity#Mark_All_as_read(user,password,last_read_at) abort
let time = !empty(a:last_read_at) ? a:last_read_at : github#api#util#Get_current_time()
let data = {}
let data.last_read_at = time
return github#api#util#GetStatus('notifications', ['-d', json_encode(data),
\ '-X', 'PUT', '-u', a:user . ':' . a:password]) == 205
endfunction
""
" @public
" Mark notifications as read in a repository
"
" Github API : PUT /repos/:owner/:repo/notifications
function! github#api#activity#Mark_All_as_read_for_repo(owner,repo,user,password,last_read_at) abort
let time = !empty(a:last_read_at) ? a:last_read_at : github#api#util#Get_current_time()
let data = {}
let data.last_read_at = time
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'notifications'], '/'),
\ ['-d', json_encode(data),
\ '-X', 'PUT', '-u', a:user . ':' . a:password])
endfunction
""
" @public
" View a single thread
"
" Github API : GET /notifications/threads/:id
function! github#api#activity#Get_thread(id,user,password) abort
return github#api#util#Get(join(['notifications', 'threads', a:id], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Mark a thread as read
"
" Github API : PATCH /notifications/threads/:id
function! github#api#activity#Mark_thread(id,user,password) abort
return github#api#util#GetStatus(join(['notifications', 'threads', a:id], '/'),
\ ['-X', 'PATCH',
\ '-u', a:user . ':' . a:password]) == 205
endfunction
""
" @public
" Get a Thread Subscription
"
" Github API : GET /notifications/threads/:id/subscription
function! github#api#activity#Get_thread_sub(id,user,password) abort
return github#api#util#Get(join(['notifications', 'threads', a:id, 'subscription'], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Set a Thread Subscription
"
" This lets you subscribe or unsubscribe from a conversation.
" Unsubscribing from a conversation mutes all future notifications
" (until you comment or get @mentioned once more).
"
" Github API : PUT /notifications/threads/:id/subscription
function! github#api#activity#Set_thread_sub(id,user,password,subscribed,ignored) abort
let data = {}
let data.subscribed = a:subscribed
let data.ignored = a:ignored
return github#api#util#Get(join(['notifications', 'threads', a:id, 'subscription'], '/'),
\ ['-X', 'PUT', '-d', json_encode(data),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Delete a Thread Subscription
"
" Github API : DELETE /notifications/threads/:id/subscription
function! github#api#activity#Del_thread_sub(id,user,password) abort
return github#api#util#GetStatus(join(['notifications', 'threads', a:id, 'subscription'], '/'),
\ ['-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" List stargazers of the repo
"
" Github API : GET /repos/:owner/:repo/stargazers
function! github#api#activity#List_stargazers(owner,repo, ...) abort
if a:0 > 0
let page = a:1
let repo = github#api#repos#get_repo(a:owner, a:repo)
if has_key(repo, 'id')
let repo_id = repo.id
" https://api.github.com/repositories/77358263/stargazers?page=97
return github#api#util#Get(join(['repositories', repo_id, 'stargazers?page=' . page], '/'), [])
else
return repo
endif
else
return github#api#util#Get(join(['repos', a:owner, a:repo, 'stargazers'], '/'), [])
endif
endfunction
""
" @public
" List all stargazers of the repo
"
" Github API : GET /repos/:owner/:repo/stargazers
function! github#api#activity#List_all_stargazers(owner, repo) abort
let issues = []
for i in range(1,github#api#util#GetLastPage('repos/' . a:owner . '/' . a:repo . '/' . 'stargazers'))
call extend(issues,github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/' . 'stargazers?page=' . i, []))
endfor
return issues
endfunction
""
" @public
" Check starred
"
" Github API : GET /user/starred/:owner/:repo
function! github#api#activity#CheckStarred(owner,repo,user,password) abort
return github#api#util#GetStatus(join(['user', 'starred', a:owner, a:repo], '/'),
\ ['-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Star a repository
"
" Github API : PUT /user/starred/:owner/:repo
function! github#api#activity#Star(owner,repo,user,password) abort
return github#api#util#GetStatus(join(['user', 'starred', a:owner, a:repo], '/'),
\ ['-X', 'PUT',
\ '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Unstar a repository
"
" Github API : DELETE /user/starred/:owner/:repo
function! github#api#activity#Unstar(owner,repo,user,password) abort
return github#api#util#GetStatus(join(['user', 'starred', a:owner, a:repo], '/'),
\ ['-X', 'DELETE',
\ '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" List watchers
"
" Github API : GET /repos/:owner/:repo/subscribers
function! github#api#activity#List_watchers(owner,repo) abort
return github#api#util#Get(join(['repos', a:owner, a:repo , 'subscribers'], '/'), [])
endfunction
""
" @public
" List repositories being watched by a user.
"
" Github API : GET /users/:username/subscriptions
function! github#api#activity#List_watched_repo(user) abort
return github#api#util#Get(join(['users', a:user, 'subscriptions'], '/'), [])
endfunction
""
" @public
" List repositories being watched by the authenticated user.
"
" Github API : GET /user/subscriptions
function! github#api#activity#List_auth_watched_repo(user,password) abort
return github#api#util#Get(join(['user', 'subscriptions'], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Get a Repository Subscription
"
" Github API : GET /repos/:owner/:repo/subscription
function! github#api#activity#Check_repo_Sub(owner,repo,user,password) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'subscription'], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Set a Repository Subscription
"
" If you would like to watch a repository, set {sub} to 1. If you would like to ignore
" notifications made within a repository, set {ignore} to 1. If you would like to stop
" watching a repository, delete the repository's subscription completely.
"
" Github API : PUT /repos/:owner/:repo/subscription
function! github#api#activity#Set_repo_sub(owner,repo,user,password,sub,ignore) abort
let data = {}
let data.subscribed = a:sub == 1 ? v:true : v:false
let data.ignored = a:ignore == 1 ? v:true : v:false
return github#api#util#Get(join(['repos', a:owner, a:repo, 'subscription'], '/'),
\ ['-X', 'PUT', '-d', json_encode(data),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Delete a Repository Subscription
"
" Github API : DELETE /repos/:owner/:repo/subscription
function! github#api#activity#Del_repo_sub(owner,repo,user,password) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'subscription'], '/'),
\ ['-X', 'DELETE',
\ '-u', a:user . ':' . a:password]) == 204
endfunction

View File

@ -0,0 +1,9 @@
let s:save_cpo = &cpo
set cpo&vim
function! github#api#cache#Update() abort
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -0,0 +1,244 @@
""
" @public
" List public gists for the specified user:
"
" GET /users/:username/gists
function! github#api#gist#List(user) abort
return github#api#util#Get(join(['users', a:user, 'gists'], '/'), [])
endfunction
""
" @public
" List the authenticated user's gists or if called anonymously, this will return all public gists:
"
" GET /gists
function! github#api#gist#ListAll(user,password) abort
if empty(a:user) || empty(a:password)
return github#api#util#Get('gists','')
else
return github#api#util#Get('gists', ['-u', a:user . ':' . a:password])
endif
endfunction
""
" @public
" List all public gists
"
" Get /gists/public
function! github#api#gist#ListPublic(since) abort
let url = 'gists/public'
if !empty(a:since)
let url = url . '?since=' . a:since
endif
return github#api#util#Get(url, [])
endfunction
""
" @public
" List starred gists,{since}A timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
" Only gists updated at or after this time are returned.
"
" GET /gists/starred
function! github#api#gist#ListStarred(user,password,since) abort
let url = 'gists/starred'
if !empty(a:since)
let url = url . '?since=' . a:since
endif
return github#api#util#Get(url, ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Get a single gist
"
" Github API : GET /gists/:id
function! github#api#gist#GetSingle(id) abort
return github#api#util#Get('gists/' . a:id, [])
endfunction
""
" @public
" Get a specific revision of a gist
"
" Github API : GET /gists/:id/:sha
function! github#api#gist#GetSingleSha(id,sha) abort
return github#api#util#Get(join(['gists', a:id, a:sha], '/'), [])
endfunction
""
" @public
" Create a gist
"
" Input: >
" {
" "description": "the description for this gist",
" "public": true,
" "files": {
" "file1.txt": {
" "content": "String file contents"
" }
" }
" }
" <
" POST : /gists
function! github#api#gist#Create(desc,filename,content,public,user,password) abort
let data = {}
let data.description = a:desc
let data.public = a:public
call extend(data, {'files': {a:filename : {'content' :a:content}}})
return github#api#util#Get('gists', ['-d', json_encode(data), '-X', 'POST', '-u', a:user . ':' .a:password])
endfunction
""
" @public
" Edit a gist
"
" Input: >
" {
" "description": "the description for this gist",
" "files": {
" "file1.txt": {
" "content": "updated file contents"
" },
" "old_name.txt": {
" "filename": "new_name.txt",
" "content": "modified contents"
" },
" "new_file.txt": {
" "content": "a new file"
" },
" "delete_this_file.txt": null
" }
" }
" <
" PATCH : /gists/:id
" Note: All files from the previous version of the gist are carried over by default
" if not included in the object. Deletes can be performed by including the filename
" with a null object.
function! github#api#gist#Edit(desc,filename,content,public,user,password,id) abort
let data = {}
let data.description = a:desc
let data.public = a:public
call extend(data, {'files': {a:filename : {'content' :a:content}}})
return github#api#util#Get('gists/' . a:id, ['-d', json_encode(data), '-X', 'PATCH', '-u', a:user . ':' .a:password])
endfunction
""
" @public
" List gist commits
"
" Github API : GET /gists/:id/commits
function! github#api#gist#ListCommits(id) abort
return github#api#util#Get(join(['gists', a:id, 'commits'], '/'), [])
endfunction
""
" @public
" Star a gist
"
" Github API : PUT /gists/:id/star
function! github#api#gist#Star(user,password,id) abort
return github#api#util#GetStatus(join(['gists', a:id, 'star'], '/'),
\ ['-X', 'PUT', '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Unstar a gist
"
" Github API : DELETE /gists/:id/star
function! github#api#gist#Unstar(user,password,id) abort
return github#api#util#GetStatus(join(['gists', a:id, 'star'], '/'),
\ ['-X', 'DELETE', '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Check if a gist is starred
"
" Github API : GET /gists/:id/star
function! github#api#gist#CheckStar(user,password,id) abort
return github#api#util#GetStatus(join(['gists', a:id, 'star'], '/'),
\ ['-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Fork a gist
"
" Github API : POST /gists/:id/forks
function! github#api#gist#Fork(user,password,id) abort
return github#api#util#Get(join(['gists', a:id, 'forks'], '/'),
\ ['-X', 'POST', '-u', a:user . ':' . a:password])
endfunction
""
" @public
" List Fork of a gist
"
" Github API : GET /gists/:id/forks
function! github#api#gist#ListFork(user,password,id) abort
return github#api#util#Get(join(['gists', a:id, 'forks'], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Delete a gist
"
" Github API : DELETE /gists/:id
function! github#api#gist#Del(user,password,id) abort
return github#api#util#GetStatus(join(['gists', a:id], '/'),
\ ['-X', 'DELETE', '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" List comments on a gist
"
" Github API : GET /gists/:gist_id/comments
function! github#api#gist#ListComments(id) abort
return github#api#util#Get(join(['gists', a:id, 'comments'], '/') , [])
endfunction
""
" @public
" Get a single comment
"
" Github API : GET /gists/:gist_id/comments/:id
function! github#api#gist#GetComment(gistid,commentid) abort
return github#api#util#Get(join(['gists', a:gistid, 'comments', a:commentid], '/'), [])
endfunction
""
" @public
" Create a comment
"
" Github API : POST /gists/:gist_id/comments
function! github#api#gist#CreateComment(id,user,password,body) abort
return github#api#util#Get(join(['gists', a:id, 'comments'], '/'),
\ ['-X', 'POST', '-d', json_encode({'body':a:body}),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Edit a comment
"
" Github API : PATCH /gists/:gist_id/comments
function! github#api#gist#EditComment(id,user,password,body) abort
return github#api#util#Get(join(['gists', a:id, 'comments'], '/'),
\ ['-X', 'PATCH', '-d', json_encode({'body':a:body}),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Delete a comment
"
" Github API : DELETE /gists/:gist_id/comments/:id
function! github#api#gist#DelComment(gistid,id,user,password) abort
return github#api#util#GetStatus(join(['gists', a:gistid, 'comments', a:id], '/'),
\ ['-u', a:user . ':' . a:password]) == 204
endfunction

View File

@ -0,0 +1,449 @@
""
" List issues
" List all issues assigned to the authenticated user across all visible
" repositories including owned repositories, member repositories, and
" organization repositories:
"
" Github API : GET /issues
" @public
function! github#api#issues#List_All(user,password) abort
let issues = []
for i in range(1,github#api#util#GetLastPage('issues', ['-u', a:user . ':' . a:password]))
call extend(issues,github#api#util#Get('issues?page=' . i, ['-u', a:user . ':' . a:password]))
endfor
return issues
endfunction
""
" List all issues across owned and member repositories assigned to the
" authenticated user:
"
" Github API : GET /user/issues
" @public
function! github#api#issues#List_All_for_User(user,password) abort
let issues = []
for i in range(1,github#api#util#GetLastPage('user/issues', ['-u', a:user . ':' . a:password]))
call extend(issues,github#api#util#Get('user/issues?page=' . i, ['-u', a:user . ':' . a:password]))
endfor
return issues
endfunction
""
" List all issues for a given organization assigned to the authenticated user:
"
" Github API : GET /orgs/:org/issues
" @public
function! github#api#issues#List_All_for_User_In_Org(org,user,password) abort
let issues = []
for i in range(1,github#api#util#GetLastPage('orgs/' . a:org . '/issues', ['-u', a:user . ':' . a:password]))
call extend(issues,github#api#util#Get('orgs/' . a:org . '/issues?page=' . i, ['-u', a:user . ':' . a:password]))
endfor
return issues
endfunction
""
" List issues for a repository
" GET /repos/:owner/:repo/issues
" NOTE: this only list opened issues and pull request
function! github#api#issues#List_All_for_Repo(owner,repo, ...) abort
let args = ''
let page_key = '?page='
let opts = get(a:000, 0, {})
if !empty(opts)
let args = '?'
if has_key(opts, 'state')
let args .= 'state=' . opts.state
endif
if has_key(opts, 'since')
if args[-1:] !=# '?'
let args .='&'
endif
let args .= 'since=' . opts.since
endif
if args[-1:] !=# '?'
let page_key = '&page='
else
let page_key = 'page='
endif
endif
let issues = []
for i in range(1,github#api#util#GetLastPage('repos/' . a:owner . '/' . a:repo . '/issues' . args))
let iss = github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues' . args . page_key . i, [])
if !empty(iss) && type(iss) == 3
call extend(issues, iss)
endif
endfor
return issues
endfunction
function! github#api#issues#async_list_opened(owner, repo, callback) abort
for i in range(1,github#api#util#GetLastPage('repos/' . a:owner . '/' . a:repo . '/issues'))
call github#api#util#async_get('repos/' . a:owner . '/' . a:repo . '/issues?page=' . i, [], a:callback)
endfor
endfunction
""
" Get a single issue
" @public
" GET /repos/:owner/:repo/issues/:number
function! github#api#issues#Get_issue(owner,repo,num) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/' . a:num, [])
endfunction
""
" @public
" Create an issue
"
" Input: >
" {
" "title": "Found a bug",
" "body": "I'm having a problem with this.",
" "assignee": "octocat",
" "milestone": 1,
" "labels": [
" "bug"
" ]
" }
" <
" Github API : POST /repos/:owner/:repo/issues
function! github#api#issues#Create(owner,repo,user,password,issue) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues',
\ ['-X', 'POST', '-d', json_encode(a:issue),
\ '-u', a:user . ':' . a:password])
endfunction
""
" Edit an issue
" PATCH /repos/:owner/:repo/issues/:number
function! github#api#issues#Edit(owner,repo,num,user,password,issue) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/' . a:num,
\ ['-X', 'PATCH',
\ '-H', 'Accept: application/vnd.github.symmetra-preview+json',
\ '-d', json_encode(a:issue),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Lock an issue
"
" Github APi : PUT /repos/:owner/:repo/issues/:number/lock
function! github#api#issues#Lock(owner,repo,num,user,password) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/' . a:num . '/lock',
\ ['-X', 'PUT', '-u', a:user . ':' . a:password,
\ '-H', 'Accept: application/vnd.github.the-key-preview'])
endfunction
""
" @public
" Unlock an issue
"
" Github API : DELETE /repos/:owner/:repo/issues/:number/lock
function! github#api#issues#Unlock(owner,repo,num,user,password) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/' . a:num . '/lock',
\ ['-X', 'DELETE', '-u', a:user . ':' . a:password,
\ '-H', 'Accept: application/vnd.github.the-key-preview'])
endfunction
""
" @public
" Lists all the available assignees to which issues may be assigned.
"
" Github API : GET /repos/:owner/:repo/assignees
function! github#api#issues#List_assignees(owner,repo) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/assignees', [])
endfunction
""
" @public
" Check assignee
"
" Github API : GET /repos/:owner/:repo/assignees/:assignee
function! github#api#issues#Check_assignee(owner,repo,assignee) abort
return github#api#util#GetStatus('repos/' . a:owner . '/'
\ . a:repo . '/assignees/' . a:assignee, []) ==# 204
endfunction
""
" @public
" Add assignees to an Issue
"
" Input: >
" {
" "assignees": [
" "hubot",
" "other_assignee"
" ]
" }
" <
" Github API : POST /repos/:owner/:repo/issues/:number/assignees
"
" NOTE: need `Accep:application/vnd.github.cerberus-preview+json`
function! github#api#issues#Addassignee(owner,repo,num,assignees,user,password) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/' . a:num . '/assignees',
\ ['-X', 'POST', '-d', json_encode(a:assignees), '-u', a:user . ':' . a:password,
\ '-H', 'Accept: application/vnd.github.cerberus-preview+json'])
endfunction
""
" @public
" Remove assignees from an Issue
"
" Input: >
" {
" "assignees": [
" "hubot",
" "other_assignee"
" ]
" }
" <
" DELETE /repos/:owner/:repo/issues/:number/assignees
"
" NOTE: need `Accep:application/vnd.github.cerberus-preview+json`
function! github#api#issues#Removeassignee(owner,repo,num,assignees,user,password) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/' . a:num . '/assignees',
\ ['-X', 'DELETE', '-d', json_encode(a:assignees), '-u', a:user . ':' . a:password,
\ '-H', 'Accept: application/vnd.github.cerberus-preview+json'])
endfunction
""
" @public
" List comments on an issue, updated at or after {since} .
" {since} : YYYY-MM-DDTHH:MM:SSZ
"
" Github API : GET /repos/:owner/:repo/issues/:number/comments
function! github#api#issues#List_comments(owner,repo,num,since) abort
let comments = []
for i in range(1,github#api#util#GetLastPage('repos/' . a:owner . '/' . a:repo
\. '/issues/' . a:num . '/comments'
\. (empty(a:since) ? '' : '?since='.a:since)))
call extend(comments,github#api#util#Get('repos/' . a:owner . '/' . a:repo
\. '/issues/' . a:num . '/comments?page=' . i
\. (empty(a:since) ? '' : '&since='.a:since), []))
endfor
return comments
endfunction
""
" @public
" List comments in a repository
"
" Github API : GET /repos/:owner/:repo/issues/comments
function! github#api#issues#List_All_comments(owner,repo,sort,desc,since) abort
let url = 'repos/' . a:owner . '/' . a:repo . '/issues/comments'
if index(['created','updated'], a:sort) != -1
let url = url . '?sort=' . a:sort
if index(['asc','desc'], a:desc) != -1
let url = url . '&direction=' . a:desc
endif
if !empty(a:since)
let url = url . '&since=' . a:since
endif
else
if !empty(a:since)
let url = url . '?since=' . a:since
endif
endif
let comments = []
for i in range(1,github#api#util#GetLastPage(url))
call extend(comments,github#api#util#Get(url . (stridx(url,'?') == -1 ? '?page=' : '&page=') . i ,[]))
endfor
return comments
endfunction
""
" @public
" Get a single comment
"
" Github API : GET /repos/:owner/:repo/issues/comments/:id
function! github#api#issues#Get_comment(owner,repo,id) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/comments/' . a:id, [])
endfunction
""
" @public
" Create a comment
"
" Input: >
" {
" "body": "Me too"
" }
" <
" Github API : POST /repos/:owner/:repo/issues/:number/comments
function! github#api#issues#Create_comment(owner,repo,num,json,user,password) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/' . a:num . '/comments',
\ ['-X', 'POST', '-u', a:user . ':' . a:password, '-d', json_encode(a:json)])
endfunction
""
" @public
" Edit a comment
"
" Input: >
" {
" "body": "Me too"
" }
" <
" Github API : PATCH /repos/:owner/:repo/issues/comments/:id
function! github#api#issues#Edit_comment(owner,repo,id,json,user,password) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/comments/' . a:id,
\ ['-X', 'PATCH', '-u', a:user . ':' . a:password, '-d', json_encode(a:json)])
endfunction
""
" @public
" Delete a comment
"
" Github API : ELETE /repos/:owner/:repo/issues/comments/:id
function! github#api#issues#Delete_comment(owner,repo,id,user,password) abort
return github#api#util#GetStatus('repos/' . a:owner . '/'
\ . a:repo . '/issues/comments/' . a:id,
\ ['-u', a:user . ':' . a:password, '-X', 'DELETE']) ==# 204
endfunction
""
" @public
" List events for an issue
" Github API : GET /repos/:owner/:repo/issues/:issue_number/events
function! github#api#issues#List_events(owner,repo,num) abort
let url = join(['repos',a:owner,a:repo,'issues',a:num,'events'], '/')
let events = []
for i in range(1,github#api#util#GetLastPage(url))
call extend(events,github#api#util#Get(url . '?page=' . i, []))
endfor
return events
endfunction
function! s:GetEvent(event) abort
let events = {
\ 'closed' : 'The issue was closed by the actor. When the commit_id is present, '
\ . 'it identifies the commit that closed the issue using "closes / fixes #NN" syntax.',
\ 'reopened' : 'The issue was reopened by the actor.',
\ 'subscribed' : 'The actor subscribed to receive notifications for an issue.',
\ 'merged' : 'The issue was merged by the actor. The `commit_id` attribute is the SHA1 of the HEAD commit that was merged.',
\ 'referenced' : 'The issue was referenced from a commit message. '
\ . 'The `commit_id` attribute is the commit SHA1 of where that happened.',
\ 'mentioned' : 'The actor was @mentioned in an issue body.',
\ 'assigned' : 'The issue was assigned to the actor.',
\ 'unassigned' : 'The actor was unassigned from the issue.',
\ 'labeled' : 'A label was added to the issue.',
\ 'unlabeled' : 'A label was removed from the issue.',
\ 'milestoned' : 'The issue was added to a milestone.',
\ 'demilestoned' : 'The issue was removed from a milestone.',
\ 'renamed' : 'The issue title was changed.',
\ 'locked' : 'The issue was locked by the actor.',
\ 'unlocked' : 'The issue was unlocked by the actor.',
\ 'head_ref_deleted' : 'The pull request`s branch was deleted.',
\ 'head_ref_restored' : 'The pull request`s branch was restored. '
\ }
let event = json_decode(a:event).event
return get(events, event)
endfunction
""
" @public
" List events for a repository
"
" Github API : GET /repos/:owner/:repo/issues/events
function! github#api#issues#List_events_for_repo(owner,repo) abort
let url = join(['repos', a:owner, a:repo, 'issues','events'], '/')
let events = []
for i in range(1,github#api#util#GetLastPage(url))
call extend(events,github#api#util#Get(url . '?page=' . i, []))
endfor
return events
endfunction
""
" @public
" Get a single event
"
" Github API : GET /repos/:owner/:repo/issues/events/:id
function! github#api#issues#Get_event(owner,repo,id) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/issues/events/' . a:id, [])
endfunction
""
" @public
" List milestones for a repository
"
" Github API : GET /repos/:owner/:repo/milestones
" Parameters >
" Name Type Description
" state string The state of the milestone. Either open, closed, or all.
" Default: open
" sort string What to sort results by. Either due_on or completeness.
" Default: due_on
" direction string The direction of the sort. Either asc or desc.
" Default: asc
" <
function! github#api#issues#ListAllMilestones(owner,repo,state,sort,direction) abort
let url = join(['repos', a:owner, a:repo, 'milestones'], '/')
if index(['open', 'closed', 'all'], a:state) == -1
let url = url . '?state=open'
else
let url = url . '?state=' . a:state
endif
if index(['due_on', 'completeness'], a:sort) == -1
let url = url . '&sort=due_on'
else
let url = url . '&sort=' . a:sort
endif
if index(['asc', 'desc'], a:direction) == -1
let url = url . '&direction=asc'
else
let url = url . '&direction=' . a:direction
endif
return github#api#util#Get(url, ['-H', 'Accept: application/vnd.github.jean-grey-preview+json'])
endfunction
""
" @public
" Get a single milestone
"
" Github API : GET /repos/:owner/:repo/milestones/:number
function! github#api#issues#GetSingleMilestone(owner,repo,num) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'milestones', a:num], '/'), [])
endfunction
""
" @public
" Create a milestone
"
" Input >
" {
" "title": "v1.0",
" "state": "open",
" "description": "Tracking milestone for version 1.0",
" "due_on": "2012-10-09T23:39:01Z"
" }
" <
" Github API : POST /repos/:owner/:repo/milestones
function! github#api#issues#CreateMilestone(owner,repo,milestone,user,password) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'milestones'], '/'),
\ ['-X', 'POST',
\ '-d', json_encode(a:milestone),
\ '-u', a:user . ':' . a:password]) == 201
endfunction
""
" @public
" Update a milestone
"
" Github API : PATCH /repos/:owner/:repo/milestones/:number
function! github#api#issues#UpdateMilestone(owner,repo,num,milestone,user,password) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'milestones', a:num], '/'),
\ ['-X', 'PATCH',
\ '-d', json_encode(a:milestone),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Delete a milestone
"
" Github API : DELETE /repos/:owner/:repo/milestones/:number
function! github#api#issues#DeleteMilestone(owner,repo,num,user,password) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'milestones', a:num], '/'),
\ ['-u', a:user . ':' . a:password]) == 204
endfunction

View File

@ -0,0 +1,140 @@
""
" @public
" List all labels for this repository
"
" Github API : GET /repos/:owner/:repo/labels
function! github#api#labels#GetAll(owner,repo) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'labels'], '/'), ['-H', 'Accept: application/vnd.github.symmetra-preview+json'])
endfunction
""
" @public
" Get a single label
"
" Github API : GET /repos/:owner/:repo/labels/:name
function! github#api#labels#Get(owner,repo,name) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'labels', a:name], '/'), [])
endfunction
""
" @public
" Create a label
"
" Input: >
" {
" "name": "bug",
" "color": "f29513"
" }
" <
" Github API : POST /repos/:owner/:repo/labels
function! github#api#labels#Create(owner,repo,user,password,label) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'labels'], '/'),
\ ['-X', 'POST',
\ '-d', json_encode(a:label),
\ '-u', a:user . ':' . a:password]) == 201
endfunction
""
" @public
" Update a label
"
" Input: >
" {
" "name": "bug",
" "color": "f29513"
" }
" <
" Github API : PATCH /repos/:owner/:repo/labels/:name
function! github#api#labels#Update(owner,repo,user,password,label) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'labels'], '/'),
\ ['-X', 'PATCH',
\ '-d', json_encode(a:label),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Delete a label
"
" Github API : DELETE /repos/:owner/:repo/labels/:name
function! github#api#labels#Delete(owner,repo,name,user,password) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'labels', a:name], '/'),
\ ['-X', 'DELETE',
\ '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" List labels on an issue
"
" Github API : GET /repos/:owner/:repo/issues/:number/labels
function! github#api#labels#List(owner,repo,num) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'issues', a:num, 'labels'], '/'), [])
endfunction
""
" @public
" Add labels to an issue
"
" Input: >
" [
" "Label1",
" "Label2"
" ]
" <
" Github API : POST /repos/:owner/:repo/issues/:number/labels
function! github#api#labels#Add(owner,repo,num,labels,user,password) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'issues', a:num, 'labels'], '/'),
\ ['-X', 'POST', '-d', json_encode(a:labels),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Remove a label from an issue
"
" Github API : DELETE /repos/:owner/:repo/issues/:number/labels/:name
function! github#api#labels#Remove(owner,repo,num,name,user,password) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'issues', a:num, 'labels', a:name], '/'),
\ [ '-X', 'DELETE',
\ '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Replace all labels for an issue
"
" Input: >
" [
" "Label1",
" "Label2"
" ]
" <
" Github API : PUT /repos/:owner/:repo/issues/:number/labels
function! github#api#labels#Replace(owner,repo,num,labels,user,password) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'issues', a:num, 'labels'], '/'),
\ ['-X', 'PUT', '-d', json_encode(a:labels),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Remove all label from an issue
"
" Github API : DELETE /repos/:owner/:repo/issues/:number/labels
function! github#api#labels#RemoveAll(owner,repo,num,user,password) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo, 'issues', a:num, 'labels'], '/'),
\ [ '-X', 'DELETE',
\ '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Get labels for every issue in a milestone
"
" Github API : GET /repos/:owner/:repo/milestones/:number/labels
function! github#api#labels#ListAllinMilestone(owner,repo,num) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'milestones', a:num, 'labels'], '/'), [])
endfunction

View File

@ -0,0 +1,21 @@
let s:User = {}
function! s:User.New(json) abort
let s:User.html_url = get(a:json, 'html_url' ,'')
let s:User.name = get(a:json, 'name', '')
let s:User.blog = get(a:json, 'blog', '')
let s:User.email = get(a:json, 'email', '')
endfunction
function! s:User.ToString() abort
echo 'Name : ' . s:User.name ."\n"
\. 'github url : ' . s:User.html_url . "\n"
\. 'blog : ' . s:User.blog . "\n"
\. 'email : ' . s:User.email
endfunction
let g:github#api#obj#User = copy(s:User)

View File

@ -0,0 +1,175 @@
" List organization repositories
" GET /orgs/:org/repos
function! github#api#orgs#ListRepos(org) abort
let repos = []
for i in range(1,github#api#util#GetLastPage('orgs/' . a:org . '/repos'))
call extend(repos,github#api#util#Get('orgs/' . a:org . '/repos?page=' . i,[]))
endfor
return repos
endfunction
""
" @public
" Get an organization
"
" Github API : GET /orgs/:org
function! github#api#orgs#Get(org) abort
return github#api#util#Get(join(['orgs', a:org], '/'), [])
endfunction
""
" @public
" Edit an organization
"
" Input: >
" {
" "billing_email": "support@github.com",
" "blog": "https://github.com/blog",
" "company": "GitHub",
" "email": "support@github.com",
" "location": "San Francisco",
" "name": "github",
" "description": "GitHub, the company."
" }
" <
" Github API : PATCH /orgs/:org
function! github#api#orgs#Edit(org,orgdata,user,password) abort
return github#api#util#Get(join(['orgs', a:org], '/'),
\ ['-X', 'PATCH', '-d', json_encode(a:orgdata),
\ '-u', a:user .':'. a:password])
endfunction
""
" @public
" List all users who are members of an organization.
"
" {filter}Filter members returned in the list. Can be one of:
" * 2fa_disabled: Members without two-factor authentication enabled. Available for organization owners.
" * all: All members the authenticated user can see.
" * Default: all.
"
" {role}Filter members returned by their role. Can be one of:
" * all: All members of the organization, regardless of role.
" * admin: Organization owners.
" * member: Non-owner organization members.
" * Default: all.
"
" Github API : GET /orgs/:org/members
function! github#api#orgs#ListMembers(org,filter,role) abort
let url = join(['orgs', a:org, 'members'], '/')
if index(['2fa_disabled', 'all'], a:filter) == -1
let url = url . '?filter=all'
else
let url = url . '?filter=' . a:filter
endif
if index(['admin', 'member', 'all'], a:role) == -1
let url = url . '&role=all'
else
let url = url . '&role=' . a:role
endif
return github#api#util#Get(url,[])
endfunction
""
" @public
" Check if a user is, publicly or privately, a member of the organization.
"
" Status:
"
" * 204: requester is an organization member and user is a member
" * 404: requester is an organization member and user is not a member,
" requester is not an organization member and is inquiring about themselves
" * 302: requester is not an organization member
"
" Github API : GET /orgs/:org/members/:username
function! github#api#orgs#CheckMembership(org,username,user,password) abort
return github#api#util#GetStatus(join(['orgs', a:org, 'members', a:username], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Remove a member
"
" Github API : DELETE /orgs/:org/members/:username
function! github#api#orgs#DeleteMember(org,username,user,password) abort
return github#api#util#GetStatus(join(['orgs', a:org, 'members', a:username], '/'),
\['-u', a:user . ':' . a:password])
endfunction
""
" @public
" List public members of an org
"
" Github API : GET /orgs/:org/public_members
function! github#api#orgs#ListPublicMembers(org) abort
return github#api#util#Get(join(['orgs', a:org, 'public_members'], '/'), [])
endfunction
""
" @public
" Check public membership
"
" Github API : GET /orgs/:org/public_members/:username
function! github#api#orgs#CheckPublicMembership(org,username) abort
return github#api#util#GetStatus(join(['orgs', a:org, 'public_members', a:username], '/'), []) == 204
endfunction
""
" @public
" Publicize a user's membership
" The user can publicize their own membership. (A user cannot publicize the membership for another user.)
"
" Github API : PUT /orgs/:org/public_members/:username
function! github#api#orgs#Publicize(org,user,password) abort
return github#api#util#GetStatus(join(['orgs', a:org, 'public_members', a:user], '/'),
\ ['-X', 'PUT',
\ '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Conceal a user's membership
"
" Github API : DELETE /orgs/:org/public_members/:username
function! github#api#orgs#ConcealUser(org,user,password) abort
return github#api#util#GetStatus(join(['orgs', a:org, 'public_members', a:user], '/'),
\ ['-X', 'DELETE',
\ '-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" Get organization membership
"
" Github API : GET /orgs/:org/memberships/:username
function! github#api#orgs#GetMemberships(org,username,user,password) abort
return github#api#util#Get(join(['orgs', a:org, 'memberships', a:username], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Add or update organization membership,use admin or member for {role}
"
" Github API : PUT /orgs/:org/memberships/:username
function! github#api#orgs#UpdateMembership(org,username,user,password,role) abort
let url = join(['orgs', a:org, 'memberships', a:username], '/')
if index(['admin', 'member'], a:role) == -1
let url .= '?role=member'
else
let url .= '?role=' . a:role
endif
return github#api#util#Get(url,['-X', 'PUT', '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Remove organization membership
"
" Github API : DELETE /orgs/:org/memberships/:username
function! github#api#orgs#RemoveMembership(org,username,user,password) abort
return github#api#util#GetStatus(join(['orgs', a:org, 'memberships', a:username], '/'),
\ ['-X', 'DELETE',
\ '-u', a:user . ':' . a:password]) == 204
endfunction

View File

@ -0,0 +1,110 @@
""
" @public
" List all the PRs of a repo.
"
" Github API : GET /repos/:owner/:repo/pulls
function! github#api#pulls#ListAllPRs(owner,repo) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'pulls'], '/'), [])
endfunction
""
" @public
" Get a single pull request
"
" Github API : GET /repos/:owner/:repo/pulls/:number
function! github#api#pulls#Get(owner,repo,number) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'pulls', a:number], '/'), [])
endfunction
""
" @public
" Create a pull request
"
" Input: >
" {
" "title": "Amazing new feature",
" "body": "Please pull this in!",
" "head": "octocat:new-feature",
" "base": "master"
" }
" <
" or: >
" {
" "issue": 5,
" "head": "octocat:new-feature",
" "base": "master"
" }
" <
" Github API : POST /repos/:owner/:repo/pulls
function! github#api#pulls#create(owner,repo,user,password,pull) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'pulls'], '/'),
\ ['-X', 'POST',
\ '-d', json_encode(a:pull),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Update a pull request
"
" Input: >
" {
" "title": "new title",
" "body": "updated body",
" "state": "open"
" }
" <
" Github API : PATCH /repos/:owner/:repo/pulls/:number
function! github#api#pulls#update(owner,repo,number,pull,user,password) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'pulls', a:number], '/'),
\ ['-X', 'PATCH',
\ '-d', json_encode(a:pull),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" List commits on a pull request
"
" Github API : GET /repos/:owner/:repo/pulls/:number/commits
function! github#api#pulls#ListCommits(owner,repo,number) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'pulls', a:number, 'commits'], '/'), [])
endfunction
""
" @public
" List pull requests files
"
" Github API : GET /repos/:owner/:repo/pulls/:number/files
function! github#api#pulls#ListFiles(owner,repo,number) abort
let page_key = '?page='
let issues = []
for i in range(1,github#api#util#GetLastPage(join(['repos', a:owner, a:repo, 'pulls', a:number, 'files'], '/')))
let iss = github#api#util#Get(join(['repos', a:owner, a:repo, 'pulls', a:number, 'files'], '/') . page_key . i, [])
if !empty(iss) && type(iss) == 3
call extend(issues, iss)
endif
endfor
return issues
endfunction
""
" @public
" Get if a pull request has been merged
"
" Github API : GET /repos/:owner/:repo/pulls/:number/merge
function! github#api#pulls#CheckMerged(owner,repo,number) abort
return github#api#util#GetStatus(join(['repos', a:owner, a:repo , 'pulls', a:number, 'merge'], '/'), []) == 204
endfunction
""
" @public
" Merge a pull request (Merge Button)
"
" Github API : PUT /repos/:owner/:repo/pulls/:number/merge
function! github#api#pulls#Merge(owner,repo,number,msg,user,password) abort
return github#api#util#Get(join(['repos', a:owner, a:repo, 'pulls', a:number, 'merge'], '/'),
\ ['-X', 'PUT',
\ '-d', json_encode(a:msg),
\ '-u', a:user . ':' . a:password])
endfunction

View File

@ -0,0 +1,21 @@
function! github#api#repos#Response() abort
let l:keys = ['owner', 'git_url', 'collaborators_url', 'fork', 'notifications_url', 'languages_url', 'size', 'name', 'clone_url',
\'created_at', 'tags_url', 'pushed_at', 'language', 'ssh_url', 'git_tags_url', 'has_pages', 'open_issues_count',
\'mirror_url', 'description', 'events_url', 'has_wiki', 'deployments_url', 'has_issues', 'milestones_url',
\'compare_url', 'releases_url', 'updated_at', 'forks', 'blobs_url', 'subscription_url', 'trees_url',
\'watchers', 'keys_url', 'full_name', 'contents_url', 'issue_comment_url', 'teams_url', 'assignees_url',
\'default_branch', 'url', 'has_downloads', 'comments_url', 'labels_url', 'commits_url', 'open_issues',
\'archive_url', 'git_commits_url', 'merges_url', 'issues_url', 'issue_events_url', 'watchers_count',
\'downloads_url', 'html_url', 'id', 'hooks_url', 'subscribers_url', 'svn_url', 'branches_url', 'pulls_url',
\'private', 'forks_count', 'homepage', 'stargazers_count', 'forks_url', 'contributors_url', 'statuses_url',
\'stargazers_url', 'git_refs_url']
return l:keys
endfunction
""
" Get a single repository
" @public
" GET /repos/:owner/:repo
function! github#api#repos#get_repo(owner, repo) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo, [])
endfunction

View File

@ -0,0 +1,54 @@
""
" @public
" Create an release
"
" Input: >
" {
" "tag_name": "v1.0.0",
" "target_commitish": "master",
" "name": "v1.0.0",
" "body": "Description of the release",
" "draft": false,
" "prerelease": false
" }
" <
" Github API: POST /repos/:owner/:repo/releases
function! github#api#repos#releases#Create(owner,repo,user,password, release) abort
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/releases',
\ ['-X', 'POST', '-d', json_encode(a:release),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Get the latest release
"
" Github API: GET /repos/:owner/:repo/releases/latest
function! github#api#repos#releases#latest(owner, repo)
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/releases/latest', [])
endfunction
""
" @public
" List assets for a release
"
" Github API: GET /repos/:owner/:repo/releases/:id/assets
function! github#api#repos#releases#list_assets(owner, repo, release_id)
return github#api#util#Get('repos/' . a:owner . '/' . a:repo . '/releases/' . a:release_id . '/assets', [])
endfunction
" TODO Get a single release
" TODO Get a release by tag name
" TODO Edit a release
" TODO Delete a release
" TODO Upload a release asset
" TODO List releases for a repository
" TODO Get a single release asset
" TODO Edit a release asset
" TODO Delete a release asset

View File

@ -0,0 +1,192 @@
""
" @public
" Search for repos, for how to {sort} result, you can use `stars`,`forks` and
" `updated`. and for {order} you can use `asc` and `desc`.for {q} see:
" Input: >
" {
" 'in' : 'name,description',
" 'size' : '',
" 'forks' : '',
" 'fork' : '',
" 'created' : '',
" 'pushed' : '',
" 'user' : '',
" 'language' : '',
" 'stars' : '',
" 'keywords' : ''
" }
" <
"
" Github API : GET /search/repositories
function! github#api#search#SearchRepos(q,sort,order) abort
let url = 'search/repositories'
let _sort = ['stars', 'forks', 'updated']
let _order = ['asc', 'desc']
let url = github#api#util#parserArgs(url, 'sort', a:sort, _sort, '')
if index(_sort, a:sort) != -1
let url = github#api#util#parserArgs(url, 'order', a:order, _order, 'desc')
endif
if stridx(url, '?') == -1
let url .= '?'
else
let url .= '&'
endif
let url .= s:parser(a:q, s:repo_scopes)
return github#api#util#Get(url, [])
endfunction
function! github#api#search#SearchCode(q,sort,order) abort
let url = 'search/code'
let _sort = ['indexed']
let _order = ['asc', 'desc']
let url = github#api#util#parserArgs(url, 'sort', a:sort, _sort, '')
if index(_sort, a:sort) != -1
let url = github#api#util#parserArgs(url, 'order', a:order, _order, 'desc')
endif
if stridx(url, '?') == -1
let url .= '?'
else
let url .= '&'
endif
let url .= s:parser(a:q, s:code_scopes)
return github#api#util#Get(url, [])
endfunction
function! github#api#search#SearchIssues(q,sort,order) abort
let url = 'search/issues'
let _sort = ['comments', 'created', 'updated']
let _order = ['asc', 'desc']
let url = github#api#util#parserArgs(url, 'sort', a:sort, _sort, '')
if index(_sort, a:sort) != -1
let url = github#api#util#parserArgs(url, 'order', a:order, _order, 'desc')
endif
if stridx(url, '?') == -1
let url .= '?'
else
let url .= '&'
endif
let url .= s:parser(a:q, s:issues_scopes)
return github#api#util#Get(url, [])
endfunction
function! github#api#search#SearchUsers(q,sort,order) abort
let url = 'search/users'
let _sort = ['followers', 'repositories', 'joined']
let _order = ['asc', 'desc']
let url = github#api#util#parserArgs(url, 'sort', a:sort, _sort, '')
if index(_sort, a:sort) != -1
let url = github#api#util#parserArgs(url, 'order', a:order, _order, 'desc')
endif
if stridx(url, '?') == -1
let url .= '?'
else
let url .= '&'
endif
let url .= s:parser(a:q, s:users_scopes)
return github#api#util#Get(url, [])
endfunction
" default scopes [valid values, default values]
let s:repo_scopes = {
\ 'in' : [['name', 'description', 'readme'], 'name,description'],
\ 'size' : '',
\ 'forks' : '',
\ 'fork' : '',
\ 'created' : '',
\ 'pushed' : '',
\ 'user' : '',
\ 'language' : '',
\ 'stars' : '',
\ 'keywords' : ''
\ }
let s:code_scopes = {
\ 'in' : 'file',
\ 'path' : '',
\ 'filename' : '',
\ 'extension' : '',
\ 'user' : '',
\ 'size' : '',
\ 'forks' : '',
\ 'fork' : '',
\ 'language' : ''
\ }
" https://help.github.com/articles/searching-issues/
let s:issues_scopes = {
\ 'type' : 'pr,issue',
\ 'in' : 'title,body,comments',
\ 'author' : '',
\ 'assignee' : '',
\ 'mentions' : '',
\ 'commenter' : '',
\ 'involves' : '',
\ 'team' : '',
\ 'state' : '',
\ 'label' : '',
\ 'milestone' : '',
\ 'no' : '',
\ 'language' : '',
\ 'is' : '',
\ 'created' : '',
\ 'updated' : '',
\ 'merged' : '',
\ 'status' : '',
\ 'head' : '',
\ 'base' : '',
\ 'closed' : '',
\ 'comments' : '',
\ 'user' : ''
\ }
let s:users_scopes = {
\ 'type' : 'org,user',
\ 'in' : 'username,email',
\ 'repos' : '',
\ 'location' : '',
\ 'language' : '',
\ 'created' : '',
\ 'followers' : ''
\ }
function! s:parser(q,scopes) abort
let scopes = copy(a:scopes)
" parser q
let rs = ''
if type(a:q) == type({})
if has_key(a:q, 'keywords')
let rs .= 'q=' . get(a:q, 'keywords')
call remove(a:q, 'keywords')
endif
for scope in keys(scopes)
if has_key(a:q, scope) && !empty(get(a:q, scope))
let res = s:getArgv(get(a:q, scope), get(scopes, scope))
if !empty(res)
let rs .= '+' . scope . ':' . res
endif
endif
endfor
elseif type(a:q) == type('')
let rs .= 'q=' . a:q
endif
return rs
endfunction
fu! s:getArgv(args,base) abort
if type(a:base) == type([])
let vars = a:base[0]
let default = a:base[1]
let f = 0
for a in (type(a:args) == type('') ? split(a:args, ',') : a:args)
if index(vars, a) == -1
let f = 1
endif
endfor
if f && !empty(default)
let result = default
elseif f
let result = ''
else
let result = a:args
endif
return result
elseif type(a:base) == type('') && empty(a:base)
return ''
endif
endf

View File

@ -0,0 +1,147 @@
"List who the authenticated user is following:
"GET /user/following
function! github#api#user#ListFollowing(auth) abort
let following = []
for i in range(1,github#api#util#GetLastPage('user/following'))
call extend(following,github#api#util#Get('user/following?page=' . i, ['-H', 'Authorization:' . a:auth]))
endfor
return following
endfunction
""
" @public
" List the authenticated user's followers:
"
" Github API : GET /user/followers
function! github#api#user#GetFollowers(user,password) abort
return github#api#util#Get(join(['user', 'followers'], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Check if you are following a user
"
" Github API : GET /user/following/:username
function! github#api#user#CheckFollowing(username,user,password) abort
return github#api#util#GetStatus(join(['user', 'following', a:username], '/'),
\ ['-u', a:user . ':' . a:password]) == 204
endfunction
""
" @public
" follow a user
"
" Github API : PUT /user/following/:username
function! github#api#user#Follow(username,user,password) abort
return github#api#util#GetStatus(join(['user', 'following', a:username], '/'),
\ ['-X', 'PUT',
\ '-u', a:user . ':' .a:password]) == 204
endfunction
""
" @public
" List all orgs for the auth user.
"
" Github API : GET /user/orgs
function! github#api#user#ListOrgs(auth) abort
return github#api#util#Get(join(['user', 'orgs'], '/'),
\ ['-H', 'Authorization:' . a:auth])
endfunction
""
" @public
" Get your organization membership
"
" Github API : GET /user/memberships/orgs/:org
function! github#api#user#GetOrgMembership(user,password,org) abort
return github#api#util#Get(join(['user', 'memberships', 'orgs', a:org], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Edit your organization membership
"
" Input: >
" {
" "state": "active"
" }
" <
" Github API : PATCH /user/memberships/orgs/:org
function! github#api#user#EditOrgMembership(org,state,user,password) abort
return github#api#util#Get(join(['user', 'memberships', 'org', a:org], '/'),
\ ['-X', 'PATCH',
\ '-d', json_encode(a:state),
\ '-u', a:user . ':' . a:password])
endfunction
"Get the authenticated user
"GET /user
function! github#api#user#GetUser(username,password) abort
return github#api#util#Get('user' , ['-u', a:username . ':' . a:password])
endfunction
""
" @public
" Update the authenticated user
"
" Input >
" {
" "name": "monalisa octocat",
" "email": "octocat@github.com",
" "blog": "https://github.com/blog",
" "company": "GitHub",
" "location": "San Francisco",
" "hireable": true,
" "bio": "There once..."
" }
" <
" Github API : PATCH /user
function! github#api#user#UpdateUser(data,user,password) abort
return github#api#util#Get('user', ['-X', 'PATCH', '-d', a:data, '-u', a:user . ':' . a:password])
endfunction
""
" @public
" List emails for a user
"
" Github API : GET /user/emails
function! github#api#user#ListEmails(user,password) abort
return github#api#util#Get(join(['user', 'emails'], '/'),
\ ['-u', a:user . ':' . a:password])
endfunction
""
" @public
" Add email address(es)
"
" Github API : POST /user/emails
function! github#api#user#AddEmails(user,password,emails) abort
return github#api#util#Get(join(['user', 'emails'], '/'),
\ ['-X', 'POST',
\ '-d', json_encode(a:emails),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Delete email address(es)
"
" Github API : DELETE /user/emails
function! github#api#user#DeleteEmails(user,password,emails) abort
return github#api#util#Get(join(['user', 'emails'], '/'),
\ ['-X', 'DELETE',
\ '-d', json_encode(a:emails),
\ '-u', a:user . ':' . a:password])
endfunction
""
" @public
" Unfollow a user
"
" Github API : DELETE /user/following/:username
function! github#api#user#UnFollow(username,user,password) abort
return github#api#util#GetStatus(join(['user', 'following', a:username], '/'),
\ ['-u', a:user . ':' . a:password]) == 204
endfunction

View File

@ -0,0 +1,75 @@
""
" @public
" Get all users
"
" Github API : GET /users
function! github#api#users#GetAllUsers() abort
return github#api#util#Get('users', [])
endfunction
function! github#api#users#starred(user,page) abort
return json_decode(join(systemlist('curl -s https://api.github.com/users/' .
\a:user . '/starred' . '?page=' . a:page ),"\n"))
endfunction
function! github#api#users#starred_pages(user) abort
let l:i = systemlist('curl -si https://api.github.com/users/' . a:user . '/starred | grep -E "^Link"')[0]
return split(matchstr(l:i,'=\d\+',0,2),'=')[0]
endfunction
function! github#api#users#GetStarred(user) abort
let rel = []
let pages = github#api#users#starred_pages(a:user)
for page in range(1,pages)
let repos = github#api#users#starred(a:user, page)
for repo in repos
call add(rel, repo)
endfor
endfor
return rel
endfunction
" get a single user
" GET /users/:username
function! github#api#users#GetUser(username) abort
return github#api#util#Get('users/' . a:username, [])
endfunction
"List followers of a user
"GET /users/:username/followers
function! github#api#users#ListFollowers(username) abort
let followers = []
for i in range(1,github#api#util#GetLastPage('users/' . a:username . '/followers'))
call extend(followers,github#api#util#Get('users/' . a:username . '/followers?page=' . i, []))
endfor
return followers
endfunction
"List users followed by another user
"GET /users/:username/following
function! github#api#users#ListFollowing(username) abort
let following = []
for i in range(1,github#api#util#GetLastPage('users/' . a:username . '/following'))
call extend(following,github#api#util#Get('users/' . a:username . '/following?page=' . i, []))
endfor
return following
endfunction
""
" @public
" List orgs of a specified user.
"
" Github API : /users/:username/orgs
function! github#api#users#ListAllOrgs(user) abort
return github#api#util#Get(join(['users', a:user, 'orgs'], '/'))
endfunction
""
" @public
" Check if one user follows another
"
" Github API : GET /users/:username/following/:target_user
function! github#api#users#CheckTargetFollow(username,target) abort
return github#api#util#GetStatus(join(['users', a:username, 'following', a:target], '/'),[])
endfunction

View File

@ -0,0 +1,147 @@
function! s:systemlist(cmd) abort
let cmd = ''
let quote = &shellxquote == '"' ? "'" : '"'
if type(a:cmd) == type([]) && !has('nvim')
for argv in a:cmd
if type(argv) == 4
let cmd .= quote . substitute(json_encode(argv), '"', '"""', 'g') . quote . ' '
else
let cmd .= quote . substitute(argv, '"', '"""', 'g') . quote . ' '
endif
endfor
else
let cmd = a:cmd
endif
call github#api#util#log('systemlist cmd : ' . string(cmd))
let result = systemlist(cmd)
if !empty(v:shell_error) && g:githubapi_verbose == 1
echom cmd
echom v:shell_error
echom string(result)
endif
return result
endfunction
function! github#api#util#Get(url,args) abort
let cmd = [g:githubapi_curl_exe, '-s', s:geturl(a:url)]
if len(a:args) > 0
call extend(cmd, a:args)
endif
call github#api#util#log('util#Get cmd : ' . string(cmd))
let result = join(s:systemlist(cmd),"\n")
return empty(result) ? result : json_decode(result)
endfunction
let s:wrapper = {
\ 'result' : '',
\ 'callback' : '',
\ }
function! s:wrapper.on_stdout(id, data, event) abort
let self.result .= join(a:data, "\n")
endfunction
function! s:wrapper.on_exit(id, data, event) abort
if a:data == 0 && a:event ==# 'exit'
if !empty(self.result)
call call(self.callback, [json_decode(self.result)])
endif
endif
endfunction
" async get issue list, the func accept one argv issue_list
function! github#api#util#async_get(url, args, func) abort
let cmd = ['curl', '-s', s:geturl(a:url)]
if len(a:args) > 0
call extend(cmd, a:args)
endif
let opt = deepcopy(s:wrapper)
let opt.callback = a:func
call jobstart(cmd, opt)
endfunction
function! github#api#util#GetLastPage(url) abort
let cmd = ['curl', '-si', s:geturl(a:url)]
call github#api#util#log('util#GetLastPage cmd : ' . string(cmd))
let result = filter(copy(s:systemlist(cmd)), "v:val =~# '^Link'")
let page = 1
if len(result) > 0
let line = result[0]
if !empty(line) && !empty(matchstr(line, 'rel="last"'))
call github#api#util#log(line)
let page = split(matchstr(line,'page=\d\+',0,2),'=')[1]
call github#api#util#log(page)
return page
endif
else
return page
endif
endfunction
function! github#api#util#GetStatus(url,opt) abort
let cmd = ['curl', '-is', s:geturl(a:url)]
if len(a:opt) > 0
call extend(cmd, a:opt)
endif
call github#api#util#log('util#GetStatus cmd : ' . string(cmd))
let result = filter(copy(s:systemlist(cmd)), "v:val =~# '^Status:'")
return matchstr(result[0],'\d\+')
endfunction
""
" @public
" Get current time in a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
function! github#api#util#Get_current_time() abort
return strftime('%Y-%m-%dT%TZ')
endfunction
let s:log = []
function! github#api#util#log(log) abort
call add(s:log, a:log)
endfunction
""
" @public
" view the log of API
function! github#api#util#GetLog() abort
return join(s:log, "\n")
endfunction
""
" @public
"
" Clean up the log of the API
function! github#api#util#CleanLog() abort
let s:log = []
echon "Github-api.vim's log has beed cleaned up!"
endfunction
function! github#api#util#parserArgs(base,name,var,values,default) abort
if empty(a:default) && index(a:values, a:var) == -1
return a:base
endif
let url = a:base . (stridx(a:base, '?') ==# -1 ? '?' : '&')
if index(a:values, a:var) == -1
let url .= a:name . '=' . a:default
else
let url .= a:name . '=' . a:var
endif
return url
endfunction
function! s:geturl(url) abort
let s:clientid = $CLIENTID
let s:clientsecret = $CLIENTSECRET
if !empty(s:clientid) && !empty(s:clientsecret)
let url = a:url
if stridx(a:url, '?') != -1
let url .= '&client_id=' . s:clientid . '&client_secret=' . s:clientsecret
else
let url .= '?client_id=' . s:clientid . '&client_secret=' . s:clientsecret
endif
return g:githubapi_root_url . url
else
return g:githubapi_root_url . a:url
endif
endfunction

View File

@ -0,0 +1,40 @@
" in vim systemlist() and system() can only use string as it's argv.
function! github#api#util#curl#Get(url,opt) abort
let cmd = ['curl', '-q','-s', '-i', a:url, '-k']
call extend(cmd, a:opt)
return s:parser(systemlist(cmd))
endfunction
fu! s:parser(res) abort
let status = 0
let link = {}
let content = []
for line in a:res
if line =~# '^Status:'
let status = matchstr(line,'\d\+')
elseif line =~# '^Link:'
let lastpg = split(matchstr(line,'=\d\+',0,2),'=')[0]
let nextpg = split(matchstr(line,'=\d\+',0,1),'=')[0]
let p1 = stridx(line, '<')
let p2 = stridx(line, '>')
let p3 = stridx(line, '<', p1 + 1)
let p4 = stridx(line, '>', p2 + 1)
let nexturl = strpart(line, p1 + 1, p2 - p1 -1)
let lasturl = strpart(line, p3 + 1, p4 - p3 -1)
let link = {
\ 'nextpg' : nextpg,
\ 'lastpg' : lastpg,
\ 'nexturl' : nexturl,
\ 'lasturl' : lasturl
\}
elseif line ==# '['
let res = remove(a:res, index(a:res, '[') ,- 1)
let content = json_decode(join(res,"\n"))
break
endif
endfor
return {
\ 'status' : status,
\ 'link' : link,
\ 'content' : content
\}
endf

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
if exists('g:GitHub_api_plugin_loaded')
finish
endif
let s:save_cpo = &cpoptions
set cpoptions&vim
""
" Github api root url:
"
" default : https://api.github.com/
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)
""
" Specific the path for curl, by default it is 'curl', in windows you can use
" >
" let g:githubapi_curl_exe = 'D:\Program Files\Neovim\bin\curl.exe'
" <
let g:githubapi_curl_exe = get(g:, 'githubapi_curl_exe', 'curl')
let g:GitHub_api_plugin_loaded = 1
let &cpoptions = s:save_cpo
unlet s:save_cpo

View File

@ -0,0 +1,3 @@
Execute ( Github.vim : plugin ):
source plugin/github.vim
AssertEqual g:githubapi_root_url, 'https://api.github.com/'

View File

@ -0,0 +1,17 @@
Execute ( issues: Get a single issue ):
AssertEqual github#api#issues#Get_issue('wsdjeg', 'Github.vim', 2).title, 'How to remove new lines?'
Execute ( issues: Lists all the available assignees ):
AssertEqual github#api#issues#List_assignees('wsdjeg', 'Github.vim')[0].login, 'wsdjeg'
Execute ( issues: Check assignee ):
AssertEqual github#api#issues#Check_assignee('wsdjeg', 'Github.vim', 'wsdjeg'), 1
Execute ( issues: List issues for a repository ):
let g:last_time = github#api#repos#releases#latest('wsdjeg', 'Github.vim').created_at
AssertEqual github#api#issues#List_All_for_Repo('wsdjeg', 'Github.vim',
\ {
\ 'since' : g:last_time,
\ 'state' : 'all'
\ }
\ )[-1].number, github#api#issues#Get_issue('wsdjeg', 'Github.vim', 13).number

View File

@ -0,0 +1,2 @@
Execute ( repos/releases: Get the latest release ):
AssertEqual github#api#repos#releases#latest('SpaceVim', 'SpaceVim').tag_name, '0.5.0'

View File

@ -0,0 +1,6 @@
filetype off
set rtp+=build/vader
set rtp+=.
set rtp+=after
filetype plugin indent on
syntax enable