FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-pull-request-github/src/github/createPRLinkProvider.ts at main · moovy2/vscode-pull-request-github · GitHub
moovy2
/
vscode-pull-request-github
Public
forked from
microsoft/vscode-pull-request-github
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
vscode-pull-request-github
/
src
/
github
/
createPRLinkProvider.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
117 lines (101 loc) · 3.75 KB
Breadcrumbs
vscode-pull-request-github
/
src
/
github
/
createPRLinkProvider.ts
Copy path
File metadata and controls
117 lines (101 loc) · 3.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'vscode'
;
import
{
FolderRepositoryManager
}
from
'./folderRepositoryManager'
;
import
{
PR_SETTINGS_NAMESPACE
,
TERMINAL_LINK_HANDLER
}
from
'../common/settingKeys'
;
import
{
ReviewManager
}
from
'../view/reviewManager'
;
interface
GitHubCreateTerminalLink
extends
vscode
.
TerminalLink
{
url
:
string
;
}
export
class
GitHubCreatePullRequestLinkProvider
implements
vscode
.
TerminalLinkProvider
{
constructor
(
private
readonly
reviewManager
:
ReviewManager
,
private
readonly
folderRepositoryManager
:
FolderRepositoryManager
,
)
{
}
private
static
getSettingsValue
(
)
{
return
vscode
.
workspace
.
getConfiguration
(
PR_SETTINGS_NAMESPACE
)
.
get
<
'vscode'
|
'github'
|
undefined
>
(
TERMINAL_LINK_HANDLER
)
;
}
static
registerProvider
(
reviewManager
:
ReviewManager
,
folderManager
:
FolderRepositoryManager
)
:
vscode
.
Disposable
{
return
vscode
.
window
.
registerTerminalLinkProvider
(
new
GitHubCreatePullRequestLinkProvider
(
reviewManager
,
folderManager
)
,
)
;
}
provideTerminalLinks
(
context
:
vscode
.
TerminalLinkContext
,
_token
:
vscode
.
CancellationToken
,
)
:
vscode
.
ProviderResult
<
GitHubCreateTerminalLink
[
]
>
{
const
startIndex
=
context
.
line
.
indexOf
(
'https://github.com'
)
;
if
(
startIndex
===
-
1
)
{
return
[
]
;
}
/**
* When a branch is published, a line like the following is written to the terminal:
* remote: https://github.com/RMacfarlane/pullrequest-demo/pull/new/rmacfarlane/testbranch3
*/
const
url
=
context
.
line
.
substring
(
startIndex
)
;
const
regex
=
new
RegExp
(
/
h
t
t
p
s
:
\/
\/
g
i
t
h
u
b
\.
c
o
m
\/
(
.
*
)
\/
(
.
*
)
\/
p
u
l
l
\/
n
e
w
\/
(
.
*
)
/
)
;
const
result
=
url
.
match
(
regex
)
;
if
(
result
&&
result
.
length
===
4
)
{
const
owner
=
result
[
1
]
;
const
repositoryName
=
result
[
2
]
;
const
branchName
=
result
[
3
]
;
const
hasMatchingGitHubRepo
=
this
.
folderRepositoryManager
.
gitHubRepositories
.
findIndex
(
repo
=>
repo
.
remote
.
owner
===
owner
&&
repo
.
remote
.
repositoryName
===
repositoryName
,
)
>
-
1
;
// The create flow compares against the current branch, so check that the published branch is this branch
if
(
hasMatchingGitHubRepo
&&
this
.
reviewManager
.
repository
.
state
.
HEAD
?.
name
===
branchName
)
{
return
[
{
startIndex
,
length
:
context
.
line
.
length
-
startIndex
,
tooltip
:
vscode
.
l10n
.
t
(
'Create a Pull Request'
)
,
url
,
}
,
]
;
}
}
return
[
]
;
}
private
openLink
(
link
:
GitHubCreateTerminalLink
)
{
return
vscode
.
env
.
openExternal
(
vscode
.
Uri
.
parse
(
link
.
url
)
)
;
}
handleTerminalLink
(
link
:
GitHubCreateTerminalLink
)
:
vscode
.
ProviderResult
<
void
>
{
const
defaultHandler
=
GitHubCreatePullRequestLinkProvider
.
getSettingsValue
(
)
;
if
(
defaultHandler
===
'github'
)
{
this
.
openLink
(
link
)
;
return
;
}
if
(
defaultHandler
===
'vscode'
)
{
this
.
reviewManager
.
createPullRequest
(
)
;
return
;
}
const
yes
=
'Yes'
;
const
neverShow
=
'Don\'t Show Again'
;
vscode
.
window
.
showInformationMessage
(
'Do you want to create a pull request using the GitHub Pull Requests and Issues extension?'
,
yes
,
'No, continue to github.com'
,
neverShow
)
.
then
(
notificationResult
=>
{
switch
(
notificationResult
)
{
case
yes
:
{
this
.
reviewManager
.
createPullRequest
(
)
;
break
;
}
case
neverShow
:
{
vscode
.
workspace
.
getConfiguration
(
PR_SETTINGS_NAMESPACE
)
.
update
(
TERMINAL_LINK_HANDLER
,
'github'
,
vscode
.
ConfigurationTarget
.
Global
)
;
this
.
openLink
(
link
)
;
break
;
}
default
:
this
.
openLink
(
link
)
;
}
}
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL