直接从 GitLab 私有存储库打开文件 [英] Open a file directly from a GitLab private repository

查看:23
本文介绍了直接从 GitLab 私有存储库打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GitLab 服务器上有一个私有存储库,我可以使用 SSH 使用 git clone 拉取项目.

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

但我想直接从服务器(更具体地说,一个 Drupal/Drush .make 文件)在 linux 命令行上运行一个脚本

But I want to run a script on linux command line directly from the server (more specific, a Drupal / Drush .make file)

我尝试使用原始文件运行它:

I tried to run it using the raw file:

drush make http://server.com/user/project/raw/master/file.make

(为了方便非 Drupal 用户,我们假设)

(for the convenience of non Drupal users let’s say)

curl http://server.com/user/project/raw/master/file.make

没有成功.当然,它会返回登录页面.

Without success. Of course, it returns me the login page.

有可能吗?

推荐答案

Chris 的宝贵帮助下,这里是如何从 GitLab 服务器运行脚本(在我的例子中是 drupal .make 文件).(可能它适用于 GitHub,但我没有测试它.也许语法会有点不同).(当然这适用于任何类型的脚本)

With Chris's valuable help, here is how you can run a script (drupal .make file in my case) from a GitLab server. (Probably it works for GitHub but I didn't test it. Maybe the syntax will be a bit different). (Of course this works for any type of script)

可以使用身份验证令牌来完成.这里是 GitLab 的 API 文档这里是 GitHub 的 API

It can be done using the authentication tokens. Here is the documentation of the GitLab's API and here is the GitHub's API

为方便起见,我将使用 https://gitlab.com 作为示例服务器.

For convenient I will use the https://gitlab.com as the example server.

  • Go to https://gitlab.com/profile/account and find your "Private token"

然后打印项目列表,找到你要找的项目的id

Then print the list of the projects and find the id of your project you are looking for

curl https://gitlab.com/api/v3/projects?private_token=

或使用您的浏览器去那里(json 查看器 将有很大帮助)

or go there with your browser (a json viewer will help a lot)

然后打印此项目中的文件列表并找到您要查找的文件的 id

Then print the list of the files that are on this project and find the id of your file you are looking for

curl https://gitlab.com/api/v3/projects//repository/tree?private_token=

最后获取/运行文件!

curl https://gitlab.com/api/v3/projects//repository/raw_blobs/?private_token=

如果你想运行脚本(drupal .make)

In case you want to run the script (drupal .make)

drush make https://gitlab.com/api/v3/projects//repository/raw_blobs/?private_token=

(如果您在这里寻找一个工作流程来将 GitLab 与 Aegir .make 平台集成而不使用令牌(也许是 SSH?),请创建一个线程并将链接粘贴到此处.)

(If you are here looking for a workflow to integrate GitLab with Aegir .make platforms without using tokens (maybe SSH?) please make a thread and paste here the link.)

编辑

您可以使用编码项目名称获取没有project_id的文件.例如 my-user-name/my-project 将变成:my-user-name%2Fmy-project

You can get the file without the project_id by using the encoded project name. For example the my-user-name/my-project will become: my-user-name%2Fmy-project

这篇关于直接从 GitLab 私有存储库打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆