如何使用GitHub-API添加文件夹?

时间:2017-01-30 15:37:29

标签: git github-api

上下文:我有一个附加了mongo db的节点应用程序。 db包括2个结构,表示文件/文件夹系统。基本上,具有表示文件夹的树结构,以及表示文件的内容结构。

我的想法是使用js包装器为GitHub api(希望如此)将它放入GitHub。

问题:我不太了解GitHub API如何接受这些信息。

  • (a)使用Git cli时,我从git init开始,设置git开始。
    这一步在哪里?
  • (b)查看here,可以以编程方式创建回购。真棒。
    那么,文件和文件夹(隐喻地)现在被推到这个仓库中的想法是什么,而不需要git init步骤?
  • (c)我知道推送的内容不是文件和文件夹,而是提交。而正在发生的是内容可寻址的密钥对。

有人可以解释这是如何映射到看起来像这样的工作流程:

  1. 新项目=>创建回购
  2. 设置一些文件和文件夹=>推高变革
  3. 制作一些更新=>推高变革 ...
  4. 关于文件夹如何工作的一点让我感到困惑 任何指针都将非常受欢迎。

2 个答案:

答案 0 :(得分:0)

DVCS (Decentralized VCS)背后的想法是你需要将本地提交发布到远程仓库。

因此,虽然您需要GitHub API来创建远程仓库,但您只需要Git(而不是GitHub API)在本地添加和提交,然后push to the remote

答案 1 :(得分:0)

使用GitHub API创建存储库 备注

  • 简单的答案是没有文件夹可以这么说 因此无法创建GitHub。
  • 花哨的答案是github是内容可寻址键值 系统,因此没有文件夹。
  • 也没有文件,应该注意,一切都是可提交的blob 基本上

如何使用以上信息: (1)从Meteor(我的用例)创建一个新的仓库。


    export const insertRepo = new ValidatedMethod({
      name: 'repos.insert',
      validate: RepoSchema.validator(),
      run({
        repoGeneralSettings,
      }) {
        if (Meteor.isServer) {
          const method = 'POST';
          const url = 'https://api.github.com/user/repos';
          const token = Meteor.settings.private.github.token;

          const headers = {
            'User-Agent': 'Meteor/1.0',
            'Authorization': token,
          };

          const data = repoGeneralSettings;

          return HTTP.call(method, url, { headers, data });
        }
      },
    });

(2)这看起来像:


    POST /user/repos HTTP/1.1
    Host: api.github.com
    Authorization: 
    Cache-Control: no-cache
    Postman-Token: 39be029f-817e-62fb-c07b-3fedf69200d4

    {
      "name": "TestRepo1",
      "description": "This is a test repository",
      "homepage": "https://www.example.com",
      "private": false,
      "has_issues": false,
      "has_wiki": false,
      "has_downloads": true,
      "auto_init": true
    }

(3)并将返回201,如此:https://developer.github.com/v3/repos/#response-2

(4)删除也很simple。请注意,根据此comment,与令牌相关的api中的授权(非常明显)。这导致了一些问题,因为我一直在尝试更改所有者的权限,当需要发生的是授权令牌的更改权限时。忽略以下设置,不要尝试在createRepo调用中设置它们。