1 0
exe 'set nocp'
2 0
set rtp+=/build/GitHub.vim
3 0
set rtp+=/API
4 0
so /build/GitHub.vim/plugin/github.vim
5 0
let s:LIST = SpaceVim#api#import('data#list')
6 0
let s:log = filereadable('build_log') ? system('cat build_log') : ''
7 0
let g:githubapi_verbose = 1
8 0
function! s:update_log(log, summary, new_log) abort
9 0
  let log = split(a:log, "\n")
10 0
  let begin = -1
11 0
  let end = -1
12 0
  for i in range(len(log))
13 0
    if log[i] =~ a:summary
14 0
      let begin = i
15
    endif
16 0
    if begin != -1 && log[i] ==# '</details>'
17 0
      let end = i
18
    endif
19
  endfor
20 0
  if begin != -1 && end != -1
21 0
    return s:LIST.replace(log, begin, end, split(a:new_log, "\n"))
22 0
  else
23 0
    return a:log . "\n" . a:new_log
24
  endif
25

26
endfunction
27 0
if !empty(s:log)
28 0
  if $LINT ==# 'vader'
29 0
    let s:summary = $VIM . ' ' . $LINT . ' build log'
30 0
  else
31 0
    let s:summary = $LINT . ' build log'
32
  endif
33 0
  let s:log = '<details><summary>' . s:summary . "</summary>\n" . s:log . "\n</details>"
34 0
  let s:comments = github#api#issues#List_comments('SpaceVim', 'SpaceVim',$TRAVIS_PULL_REQUEST ,'')
35 0
  if empty(s:comments)
36 0
    call github#api#issues#Create_comment('SpaceVim','SpaceVim', $TRAVIS_PULL_REQUEST, {'body': s:log}, 'SpaceVimBot', $BOTSECRET)
37 0
  else
38 0
    let s:nr = 0
39 0
    for s:comment in s:comments
40 0
      if s:comment.user.login ==# 'SpaceVimBot'
41 0
        let s:nr = s:comment.id
42 0
        break
43
      endif
44
    endfor
45 0
    if s:nr == 0
46 0
      call github#api#issues#Create_comment('SpaceVim','SpaceVim', $TRAVIS_PULL_REQUEST, {'body': s:log}, 'SpaceVimBot', $BOTSECRET)
47 0
    else
48 0
      call github#api#issues#Edit_comment('SpaceVim','SpaceVim', s:nr,
49 0
            \ {'body': s:update_log(s:comment.body, s:summary, s:log)}, 'SpaceVimBot', $BOTSECRET)
50
    endif
51
  endif
52 0
else
53 0
  if $LINT ==# 'vader'
54 0
    let s:summary = $VIM . ' ' . $LINT . ' build log'
55 0
  else
56 0
    let s:summary = $LINT . ' build log'
57
  endif
58 0
  let s:log = '<details><summary>' . s:summary . "</summary>\n" . s:log . "\n</details>"
59 0
  let s:comments = github#api#issues#List_comments('SpaceVim', 'SpaceVim',$TRAVIS_PULL_REQUEST ,'')
60 0
  if !empty(s:comments)
61 0
    let s:nr = 0
62 0
    for s:comment in s:comments
63 0
      if s:comment.user.login ==# 'SpaceVimBot'
64 0
        let s:nr = s:comment.id
65 0
        break
66
      endif
67
    endfor
68 0
    if s:nr != 0
69 0
      call github#api#issues#Edit_comment('SpaceVim','SpaceVim', s:nr,
70 0
            \ {'body': s:update_log(s:comment.body, s:summary, s:log)}, 'SpaceVimBot', $BOTSECRET)
71
    endif
72
  endif
73
endif
74 0
echom v:shell_error
75 0
quit

Read our documentation on viewing source code .

Loading