Open a file directly from a GitLab private repository

前端 未结 3 811
终归单人心
终归单人心 2020-12-25 14:51

I have a private repository on a GitLab server and using the SSH I can pull a project using git clone.

But I want to run a script on linux command line directly from

3条回答
  •  醉酒成梦
    2020-12-25 15:04

    Update 2018-12-25:

    as long as you're not downloading huge files, this should work:

    curl -s -H "Private-Token: " "https://gitlab.com/api/v4/projects//repository/files//raw?ref="
    

    , a real example, downloading the file /README.md from the private repository https://gitlab.com/divinity76/Yur17, where the web download url is https://gitlab.com/divinity76/Yur17/raw/master/README.md?inline=false, is:

    curl -s -H "Private-Token: afF2s1xgk6xcwXHy3J4C" "https://gitlab.com/api/v4/projects/divinity76%2Fyur17/repository/files/README%2Emd/raw?ref=master"
    

    take special note of how the gitlab_username/repo_name was url-encoded, eg / became %2F (you can check how your username & repo name is as url-encoded by opening your browser javascript terminal and write encodeURIComponent("your_username/repo_name"); in the terminal and press enter.)

    thanks to Jonathan Hall @ gitlab at mg.gitlab.com, and https://docs.gitlab.com/ee/api/repository_files.html , and tvl for helping reach a solution.



    Update 2018-12-11: this method no longer works, now it just serves the login page, with a message saying need to log in to continue, even using HTTP 200 OK (shame on them), will update if i find out why ( @XavierStuvw claims it's security concerns related)



    i found a much easier way to do it than @tvl 's answer,

    first create an access token with API access here: https://gitlab.com/profile/personal_access_tokens , then do:

    wget --header 'PRIVATE-TOKEN: ' 'https://gitlab.com///raw/master/path/to/file.ext'

    i found the solution here.

提交回复
热议问题