tvl*_*tvl 17 linux git drupal drush gitlab
我在GitLab服务器上有一个私有存储库,使用SSH我可以使用git clone拉一个项目.
但我想直接从服务器上运行linux命令行上的脚本(更具体地说,Drupal/Drush .make文件)
我试图使用原始文件运行它:
drush make http://server.com/user/project/raw/master/file.make
Run Code Online (Sandbox Code Playgroud)
(为了方便非Drupal用户,让我们说)
curl http://server.com/user/project/raw/master/file.make
Run Code Online (Sandbox Code Playgroud)
没有成功.当然,它会返回登录页面.
可能吗?
tvl*_*tvl 24
有了Chris的宝贵帮助,以下是如何从GitLab服务器运行脚本(在我的案例中为drupal .make文件).(可能它适用于GitHub,但我没有测试它.也许语法会有所不同).(当然这适用于任何类型的脚本)
可以使用身份验证令牌来完成.这里是GitLab的API的文档和这里是GitHub的API
为方便起见,我将使用https://gitlab.com作为示例服务器.
转到https://gitlab.com/profile/account并找到您的"私人令牌"
然后打印项目列表并找到您要查找的项目的ID
curl https://gitlab.com/api/v3/projects?private_token=<your_private_token>
或者去你的浏览器(json viewer会帮助很多)
然后打印此项目中的文件列表,并找到您要查找的文件的ID
curl https://gitlab.com/api/v3/projects/<project_id>/repository/tree?private_token=<your_private_token>
最后获取/运行文件!
curl https://gitlab.com/api/v3/projects/<project_id>/repository/raw_blobs/<file_id>?private_token=<your_private_token>
如果你想运行脚本(drupal .make)
drush make https://gitlab.com/api/v3/projects/<project_id>/repository/raw_blobs/<file_id>?private_token=<your_private_token> <drupal_folder>
(如果你在这里寻找一个工作流程来集成GitLab和Aegir .make平台而不使用令牌(也许是SSH?),请在这里创建一个线程并粘贴链接.)
编辑
您可以在不project_id使用编码项目名称的情况下获取文件.例如,my-user-name/my-project将成为:my-user-name%2Fmy-project
更新2018-12-25:
只要你不下载大文件,这应该工作:
curl -s -H "Private-Token: <token>" "https://gitlab.com/api/v4/projects/<urlencode("gitlab_username/project_name")>/repository/files/<path/to/file>/raw?ref=<branch_name>"
Run Code Online (Sandbox Code Playgroud)
一个真实的例子,/README.md从https://gitlab.com/divinity76/Yur17Web下载URL所在的私有存储库下载文件https://gitlab.com/divinity76/Yur17/raw/master/README.md?inline=false是:
curl -s -H "Private-Token: afF2s1xgk6xcwXHy3J4C" "https://gitlab.com/api/v4/projects/divinity76%2Fyur17/repository/files/README%2Emd/raw?ref=master"
Run Code Online (Sandbox Code Playgroud)
特别注意gitlab_username/repo_nameurl编码的方式,例如/成为%2F(你可以通过打开你的浏览器javascript终端并encodeURIComponent("your_username/repo_name");在终端写入并按回车来查看你的用户名和回购名称是如何编码的.)
感谢Jonathan Hallmg.gitlab.com上的@ gitlab和https://docs.gitlab.com/ee/api/repository_files.html以及tvl,以帮助您找到解决方案.
更新2018-12-11:此方法不再有效,现在它只是提供登录页面,并显示一条消息need to log in to continue,即使使用HTTP 200 OK(对它们感到羞耻),如果我找到原因会更新(@XavierStuvw声称它的安全性)关注的问题)
我找到了比@tvl的回答更容易的方法,
首先在这里创建一个具有API访问权限的访问令牌:https://gitlab.com/profile/personal_access_tokens,然后执行:
wget --header 'PRIVATE-TOKEN: <token>' 'https://gitlab.com/<username>/<repo>/raw/master/path/to/file.ext'
| 归档时间: |
|
| 查看次数: |
17169 次 |
| 最近记录: |