简体   繁体   English

Gitlab API 从本地文件系统上传整个项目

[英]Gitlab API to upload whole project from local file system

I need to upload using API whole project folder which contains multiple text files, image files, source files, etc.我需要使用 API 上传整个项目文件夹,其中包含多个文本文件、图像文件、源文件等。

I had gone through Gitlab Commits and upload API's but none of them matches requirement.我已经完成了 Gitlab 提交和上传 API,但它们都不符合要求。

Is there any API to upload full project folder form API?是否有任何 API 上传完整的项目文件夹表格 API?

I used below API to create a project我用下面的API创建项目

POST : https://repo.**.com/api/v4/projects
{
    "name": "test",
    "default_branch": "master"
}

After creating new project with gitlab api, eg:使用 gitlab api 创建新项目后,例如:

curl --fail -d '{"name":"test","default_branch": "master"}' -H "Content-Type: application/json" -X POST https://repo.**.com/api/v4/projects?access_token=<your access token> --output project_details.json

You could assume your new project url based on post data name -> https://repo.**.com/<gitlab user or gitlab group>/test.git or you could parse response json with some tool, eg python:您可以根据帖子数据name假设您的新项目 url -> https://repo.**.com/<gitlab user or gitlab group>/test.git或者您可以使用一些工具解析响应 json,例如 python:

http_url_to_repo=$(python -c "import json; print(json.load(open('project_details.json'))['http_url_to_repo'])")

Then you could follow new project instruction for existing folder:然后您可以按照现有文件夹的新项目说明进行操作:

#Push an existing folder
cd existing_folder
git init
git remote add origin $http_url_to_repo
git add .
git commit -m "Initial commit"
git push -u origin master

Where existing_folder is folder with your source files which you want to upload as a commit to new gitlab project.其中existing_folder是包含源文件的文件夹,您要上传这些文件作为对新 gitlab 项目的提交。

You can use repository files API to create files.您可以使用存储库文件 API 来创建文件。

https://docs.gitlab.com/ee/api/repository_files.html#create-new-file-in-repository https://docs.gitlab.com/ee/api/repository_files.html#create-new-file-in-repository

POST /projects/:id/repository/files/:file_path
curl --request POST --header 'PRIVATE-TOKEN: <your_access_token>' --header "Content-Type: application/json" \
  --data '{"branch": "master", "author_email": "author@example.com", "author_name": "Firstname Lastname", \
    "content": "some content", "commit_message": "create a new file"}' \
  'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb'

Had the same problem and ended up walking the folder like this:遇到了同样的问题,最终像这样遍历文件夹:

import os

for (dirpath, dirnames, files) in os.walk(my_folder):
  for file in files:
    # do the api call to commit for dirpath, file 

It works nicely...它工作得很好......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gitlab 'include local' 来自同一项目但不同的目录 - Gitlab 'include local' from same project but different directory 哪个ip要添加到azure防火墙从本地系统上传文件到adls? - Which ip to be added to azure firewall to upload a file to adls from local system? gitlab 的本地实例不响应位于“/gitlab/doc/api/v4”中的 API 文档中的 REST 调用 - Local instance of gitlab does not respond to REST-calls from the API documentation located in "/gitlab/doc/api/v4" 通过 Python 在 Gitlab 项目存储库中添加文件 - Add a file in Gitlab project repository by Python 我在哪里可以找到 GitLab API 的项目 ID? - Where do I find the project ID for the GitLab API? 从另一个项目克隆/使用.ps gitlab - clone / use .ps from another project gitlab 如何通过 GitLab V4 api 列出 gitlab 项目中的所有项目变量 - How to list all the project variables in a gitlab project via GitLab V4 api Gitlab REST API 文件下载到子文件夹 - Gitlab REST API file download in subfolder 如何将本地视频文件上传到 Google Cloud - How to upload local video file to Google Cloud 如何在没有快照的情况下从 Gitlab 发布 maven 项目? - How to release maven project from Gitlab without Snapshot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM