GitTools / GitLink

Making .NET open source accessible!
MIT License
554 stars 86 forks source link

Slash problem in custom URL #211

Closed Ducatel closed 5 years ago

Ducatel commented 5 years ago

Hi everyone,

I'm trying to use GitLink with gitlab. For doing that I'm using the custom URL provider.

Gitlab API v4 allow to get raw file with call like

$gitlabBaseUrl/api/v4/projects/$gitlabProjectId/repository/files/{filename}/raw?ref={revision}&private_token=$yourReadOnlyToken

I have testing this with HTTP and Powershell method but both fail with a HTTP 404 error code. This is due to the replacement of {filename} (or %var2% in the srcsrv file) by source file path which can contains / when it under folder.

So I have updated by test srcsvr file and rewrite it to pdb with pdbstr.exe

The original file

SRCSRV: ini ------------------------------------------------
VERSION=2
SRCSRV: variables ------------------------------------------
RAWURL=http://gitlab.com/api/v4/projects/42/repository/files/%var2%/raw?ref=dfd8a4bb5614f8303231zzzzz0f3335e1ccce1f2&private_token=superToken
TRGFILE=%fnbksl%(%targ%%var2%)
SRCSRVTRG=%TRGFILE%
SRCSRVCMD=powershell invoke-command -scriptblock {$webClient = New-Object System.Net.WebClient; $webClient.UseDefaultCredentials = $true; $webClient.DownloadFile('%RAWURL%', '%TRGFILE%');}
SRCSRV: source files ---------------------------------------
C:\src\lzmaSdk\C\7z.h*lzmaSdk/C/7z.h
C:\src\lzmaSdk\C\7zAlloc.c*lzmaSdk/C/7zAlloc.c

The updated one (file path after * is URL encoded)

SRCSRV: ini ------------------------------------------------
VERSION=2
SRCSRV: variables ------------------------------------------
RAWURL=http://gitlab.com/api/v4/projects/42/repository/files/%var2%/raw?ref=dfd8a4bb5614f8303231zzzzz0f3335e1ccce1f2&private_token=superToken
TRGFILE=%fnbksl%(%targ%%var2%)
SRCSRVTRG=%TRGFILE%
SRCSRVCMD=powershell invoke-command -scriptblock {$webClient = New-Object System.Net.WebClient; $webClient.UseDefaultCredentials = $true; $webClient.DownloadFile('%RAWURL%', '%TRGFILE%');}
SRCSRV: source files ---------------------------------------
C:\src\lzmaSdk\C\7z.h*lzmaSdk%2fC%2f7z.h
C:\src\lzmaSdk\C\7zAlloc.c*lzmaSdk%2fC%2f7zAlloc.c

Like that it's working

Feature description

Add {urlencoded_filename} token which will be replaced by url encoded filename.

That sounds possible ? Thanks ;)

GeertvanHorrik commented 5 years ago

Looks good, thanks for the PR.

Note that we recommend to use SourceLink nowadays (built into VS, supported by MS, etc). I did accept the PR and will release an alpha to nuget / chocolatye, but if you are able to, I recommend you use portable pdb with sourcelink.

Ducatel commented 5 years ago

Ok, I will check SourceLink ;) Thanks

Ducatel commented 5 years ago

Maybe you should add a note in readme which redirect user to sourceLink if it's the recommended way now. After some research, SourceLink cannot handle my case (Gitlab private repo)