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

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

问题描述

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



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



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

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

(为方便非Drupal用户让我们说)

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

没有成功。当然,它返回我的登录页面。



可以吗?

解决方案>

通过 Chris 的宝贵帮助,您可以运行脚本(drupal .make file in my案例)从GitLab服务器。 (可能它适用于GitHub,但是我没有测试它,也许语法会有所不同)。 (当然这适用于任何类型的脚本)



可以使用身份验证令牌来完成。 以下是GitLab API的文档和< a href =https://developer.github.com/v3/ =nofollow noreferrer>这里是GitHub的API



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




  • 转到 https://gitlab.com/profile /帐户,并找到您的私人令牌


  • 然后打印项目列表,并找到您要查找的项目的ID



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



    或使用浏览器去(a json viewer 将h elp很多)


  • 然后打印此项目中的文件列表,并找到您要查找的文件的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


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 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

(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.

Is it possible?

解决方案

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)

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

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"

  • 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=<your_private_token>

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

  • 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/<project_id>/repository/tree?private_token=<your_private_token>

  • Finally get / run the file!

    curl https://gitlab.com/api/v3/projects/<project_id>/repository/raw_blobs/<file_id>?private_token=<your_private_token>

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

drush make https://gitlab.com/api/v3/projects/<project_id>/repository/raw_blobs/<file_id>?private_token=<your_private_token> <drupal_folder>

(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.)

EDIT

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天全站免登陆