Skip to content

Instantly share code, notes, and snippets.

@cherryramatisdev
Created September 28, 2023 00:19
Show Gist options
  • Save cherryramatisdev/0e7d4f907b31cf0245bde35e1f735d2b to your computer and use it in GitHub Desktop.
Save cherryramatisdev/0e7d4f907b31cf0245bde35e1f735d2b to your computer and use it in GitHub Desktop.
function! s:ReturnProjectRoot() abort
" TODO: This doesn't work on non git projects
return system('git rev-parse --show-toplevel')->substitute('\n', '', '')
endfunction
function! github#pr#CreatePr() abort
let l:template_path = s:ReturnProjectRoot() . '/.github/pull_request_template.md'
call execute('tabe ' . tempname())
if filereadable(l:template_path)
call setline(1, readfile(l:template_path))
setlocal filetype=markdown
endif
endfunction
function! github#pr#SubmitPr() abort
let l:filepath = expand('%')
let l:base_branch = 'main'
let l:reviewers = getenv('REVIEWERS')
let l:gh_pr_cmd = '!gh pr -a @me create -B ' . l:base_branch . ' -r ' . l:reviewers . ' -F "' . l:filepath . '"'
execute 'Dispatch ' . l:gh_pr_cmd
endfunction
function! github#pr#OpenPr() abort
Dispatch !gh pr view -w
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment