Skip to content

Commit 39811c2

Browse files
authored
Merge pull request #1 from anhpt379/git-open-pull-request
Add vim_git_browse#GitOpenPullRequest function
2 parents a1472e0 + 9260ec3 commit 39811c2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

autoload/vim_git_browse.vim

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ function! vim_git_browse#GitPullRequest() abort
195195
let l:git_root_path = s:GetGitRootPath()
196196
if l:git_root_path is v:null
197197
echo '[vim-git-browse] Please use in git project'
198-
return
198+
return 0
199199
endif
200200

201201
let l:branch_name = s:GetCurrentBranchName()
202202
let l:latest_commit_hash = s:GetLatestCommitHashRemote(l:branch_name)
203203
if l:latest_commit_hash is v:null
204204
echo '[vim-git-browse] Could not find remote branch ' . l:branch_name
205-
return
205+
return 0
206206
endif
207207
let l:git_remote_url = s:GetGitRemoteUrl()
208208
let l:merge_request_url = v:null
@@ -214,29 +214,30 @@ function! vim_git_browse#GitPullRequest() abort
214214
let l:merge_request_url = s:GetGithubPullRequestUrl(l:git_remote_url, l:latest_commit_hash)
215215
else
216216
echo '[vim-git-browse] Git site not supported'
217-
return
217+
return 0
218218
endif
219219

220220
if l:merge_request_url is v:null
221-
echo '[vin-git-browse] Could not find pull/merge request for branch ' . l:branch_name
222-
return
221+
echo '[vim-git-browse] Could not find pull/merge request for branch ' . l:branch_name
222+
return 0
223223
endif
224224

225225
call s:OpenUrl(l:merge_request_url)
226+
return 1
226227
endfunction
227228

228229
function! vim_git_browse#GitCreatePullRequest() abort
229230
echo '[vim-git-browse] Creating pull request...'
230231
let l:git_root_path = s:GetGitRootPath()
231232
if l:git_root_path is v:null
232233
echo '[vim-git-browse] Please use in git project'
233-
return
234+
return 0
234235
endif
235236

236237
let l:branch_name = s:GetCurrentBranchName()
237238
if l:branch_name == g:vim_git_browse_target_branch
238239
echo '[vim-git-browse] Source branch can not be the same as target branch'
239-
return
240+
return 0
240241
endif
241242

242243
let l:git_remote_url = s:GetGitRemoteUrl()
@@ -249,10 +250,17 @@ function! vim_git_browse#GitCreatePullRequest() abort
249250
let l:create_merge_request_url = l:git_remote_url . '/compare/' . g:vim_git_browse_target_branch . '...' . l:branch_name
250251
else
251252
echo '[vim-git-browse] Git site not supported'
252-
return
253+
return 0
253254
endif
254255

255256
call s:OpenUrl(l:create_merge_request_url)
257+
return 1
258+
endfunction
259+
260+
function! vim_git_browse#GitOpenPullRequest() abort
261+
if !vim_git_browse#GitPullRequest()
262+
call vim_git_browse#GitCreatePullRequest()
263+
endif
256264
endfunction
257265

258266
let &cpo = s:cpo_save

0 commit comments

Comments
 (0)