Search code examples
gitlabibm-clouddevops-services

How do I download a raw file from my IBM Cloud Git Repos and Issue Tracking repository?


I'm trying to download a raw file from one of my IBM Cloud Git Repos and Issue Tracking repositories. I had a script that was able to fetch raw file contents using the following curl command:

curl -H "Private-Token: $PERSONAL_ACCESS_TOKEN" https://git.ng.bluemix.net/:owner/:repo/raw/:branch/:filename

but it recently started failing with a 302 response that is redirecting to a UI login page.

Is there a supported way to download raw file contents from an IBM Cloud Git Repos and Issue Tracking repository?


Solution

  • The curl request above is attempting to use a personal access token to authenticate to a UI endpoint. There was a security fix in GitLab 11.3.11 that limited the scope of personal access tokens to API calls only. That would explain why personal access tokens are no longer working on that request.

    The supported method of downloading raw file contents would be to call the repository files API.

    For example, to fetch myFolder/myFile.txt from the master branch of myRepo, owned by myUser, you can make a curl call like this:

    curl -H "Private-Token: $PERSONAL_ACCESS_TOKEN" https://git.ng.bluemix.net/api/v4/projects/myUser%2FmyRepo/repository/files/myFolder%2FmyFile.txt/raw?ref=master