-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrootpage.html
242 lines (218 loc) · 8.66 KB
/
rootpage.html
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<html lang="en-us"><head>
<meta charset="utf-8">
<title>VSO Git</title>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<br><p ><h1>Construct better Azure DevOps Raw Urls</h1><br> Either:
<ol>
<lI> enter in your current DevOps/VSO URL</lI>
<li> manually construct it in the below table.</li></ol></p>
<p>Two things to Note</p>
<ul>
<li>Directory paths should end in a '/' and files paths should not </li>
<ul>
<li>If copying a path that is not a file from DevOps/VSO URL, you need to remove the trailing '/'
<ul><li> '/' is auto added when the last location does not contain a '.' in the filename</li></ul></li></ul>
<li>You need to specify an access token.</li>
</ul>
<div id="advancedOptions">
Azure DevOps URL: <input type="text" id="vsoInput" size="120" value="https://oneeyedelf1.visualstudio.com/project3/_git/vso_git_demo">
<table>
<tbody><tr>
<th>Option</th>
<th>Values</th>
</tr>
<tr>
<td>
<label for="organizationInput">Organization</label>
</td>
<td>
<input type="text" id="organizationInput" size="120" value="">
</td>
</tr>
<tr>
<td>
<label for="projectInput">Project</label>
</td>
<td>
<input type="text" id="projectInput" size="120" value="">
</td>
</tr>
<tr>
<td>
<label for="repositoryInput">Repository</label>
</td>
<td>
<input type="text" size="120" id="repositoryInput" value="">
</td>
</tr>
<tr>
<td>
<label for="versionType">VersionType</label>
</td>
<td>
<input type="radio" id="versionTypeBranch" name="versionType" value="branch" checked> branch<br>
<input type="radio" id="versionTypeCommit" name="versionType" value="commit"> commit<br>
<input type="radio" id="versionTypeTag" name="versionType" value="tag"> tag
</td>
</tr>
<tr>
<td>
<label for="branchInput">Version</label>
</td>
<td>
<input type="text" size="120" id="branchInput" value="">
</td>
</tr>
<tr>
<td>
<label for="pathInRepositoryInput">Path (in repository)</label>
</td>
<td>
<input type="text" size="120" id="pathInRepositoryInput" value="/">
</td>
</tr>
<tr>
<td>
<label for="accessTokenInput">Access Token</label>
</td>
<td>
<input type="text" size="120" id="accessTokenInput" value="lcwfr46dwkx6vkxv3jxwkjwfqedawf7a243ngnjoggytt37xgdja">
</td>
</tr>
</tbody></table>
<p>Raw url: <a id="rawUrl" href=""></a></p>
<p>Website url: <a id="normalUrl" href=""></a></p>
<br>
<br>
<p>For source see <a href="https://github.com/KnicKnic/vso_git">https://github.com/KnicKnic/vso_git</a></p>
</div>
<script type="module">
// various html elements
let vsoInput = document.getElementById("vsoInput");
let organizationInput = document.getElementById("organizationInput")
let projectInput = document.getElementById("projectInput");
let repositoryInput = document.getElementById("repositoryInput");
let branchInput = document.getElementById("branchInput");
let pathInRepositoryInput = document.getElementById("pathInRepositoryInput");
let accessTokenInput = document.getElementById('accessTokenInput');
let rawUrl = document.getElementById('rawUrl');
let normalUrl = document.getElementById("normalUrl");
let versionTypeBranch = document.getElementById("versionTypeBranch");
let versionTypeCommit = document.getElementById("versionTypeCommit");
let versionTypeTag = document.getElementById("versionTypeTag");
let azureCodeToVersionType = {"GB": "branch", "GC": "commit", "GT": "tag"}
let getVersionType = function(){
if(versionTypeBranch.checked){
return "branch"
}
if(versionTypeCommit.checked){
return "commit"
}
if(versionTypeTag.checked){
return "tag"
}
return "branch"
}
// GB GC or GT for branch, commit or tag
let setVersionType = function(versionType){
versionTypeBranch.checked = versionType == "branch"
versionTypeCommit.checked = versionType == "commit"
versionTypeTag.checked = versionType == "tag"
}
// deal with input urls
{
let host = window.location.host;
let protocol = 'https://'
if(host == ''){
host = 'localhost:8080'
}
if(host =="localhost:8080"){
protocol = 'http://'
}
let calculateShareUrls = function(){
let normalPath = "/" + accessTokenInput.value + "/" + getVersionType() + '/' + organizationInput.value + "/" + projectInput.value + "/" + repositoryInput.value + "/" + encodeURIComponent(branchInput.value) + pathInRepositoryInput.value
let rawPath = "/raw" + normalPath
rawUrl.href=protocol + host + rawPath
rawUrl.innerText = rawUrl.href
normalUrl.href=protocol + host + normalPath
normalUrl.innerText = normalUrl.href
}
organizationInput.oninput = calculateShareUrls;
projectInput.oninput = calculateShareUrls;
repositoryInput.oninput = calculateShareUrls;
branchInput.oninput = calculateShareUrls;
pathInRepositoryInput.oninput = calculateShareUrls;
accessTokenInput.oninput = calculateShareUrls;
versionTypeBranch.oninput = calculateShareUrls;
versionTypeCommit.oninput = calculateShareUrls;
versionTypeTag.oninput = calculateShareUrls;
let parseVsoUrl = function(){
let inputUrl = new URL(vsoInput.value)
let org = ''
let project = ''
let repo = ''
let path = '/'
let branch = 'master'
let versionType = 'branch'
if(inputUrl.host =="dev.azure.com"){
let pathChunks = inputUrl.pathname.split('/')
org = pathChunks[1]
if(pathChunks.length == 4){
project = pathChunks[3]
repo = project
} else{
project = pathChunks[2]
repo = pathChunks[4]
}
}
else if (inputUrl.host.includes(".visualstudio.com")){
let pathChunks = inputUrl.pathname.split('/')
org = inputUrl.host.split('.')[0]
if(pathChunks.length == 3){
project = pathChunks[2]
repo = project
} else{
project = pathChunks[1]
repo = pathChunks[3]
}
}
if(inputUrl.searchParams){
if(inputUrl.searchParams.get("version")){
branch = inputUrl.searchParams.get("version")
versionType = azureCodeToVersionType[branch.substr(0,2).toUpperCase()]
branch = branch.substr(2)
}
if(inputUrl.searchParams.get("path")){
path = inputUrl.searchParams.get("path")
}
}
setVersionType(versionType)
let chunkedPath = path.split('/')
let lastChunkedPath = chunkedPath[chunkedPath.length-1]
if(!lastChunkedPath.includes('.')){
if(path[path.length-1] != '/'){
path = path + '/'
}
}
organizationInput.value = org
projectInput.value = project
repositoryInput.value = repo
branchInput.value = branch
pathInRepositoryInput.value = path
calculateShareUrls()
}
vsoInput.oninput = parseVsoUrl
parseVsoUrl();
}
//generate zips
</script>
</body></html>