1

Context: I have a node app with a mongo db attached to it. The db includes 2 structures, representing a file/folder system. Basically, have the tree structure representing the folders, and a contents structure representing the files.

The idea is to put this into GitHub using a js wrapper API for GitHub api (hopefully).

Question: I don't really get how GitHub API would accept this information.

  • (a) When using the Git cli, I start with the git init, which sets up the git to begin with.
    Where is this step?
  • (b) Looking here, a repo can be programmatically created. Awesome.
    So, is the idea that files and folders (metaphorically) get pushed up into this repo now, without the need of the git init step?
  • (c) I get that what is getting pushed up are not files and folders, but rather commits. And that what is going up is content-addressable key pairs.

Can someone explain how this maps to a workflow that looks something like this:

  1. New project => create repo
  2. Setup some files and folders => push up changes
  3. Make some update => push up changes ...

The bit about how folders works is what is confusing me.
Any pointers would be most appreciated.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283

2 Answers2

0

The idea behind a DVCS (Decentralized VCS) is that you need to publish local commits to a remote repo.

So while you would need the GitHub API to create a remote repo, you would need only Git (not GitHub API) to add and commit locally, then push to the remote.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Apologies, I might not have been clear above. As this is all happening inside an application, there is no local git object. So there are no local commits, instead, I have to track everything within a mongo db. So I can't, add and commit locally. This is the question pretty much. – zaYZNXhT ZLCpve6R Jan 30 '17 at 23:48
  • @TathagatBanerjee Then this application needs to create a local repo, generate the right files in it, add, commit and push. – VonC Jan 31 '17 at 05:13
  • this is incorrect. Please see below. I specifically had the use case where I could not create a local repo. This is for a application that sits in the cloud. – zaYZNXhT ZLCpve6R Feb 02 '17 at 07:49
  • @TathagatBanerjee your answer addresses a new repo creation on GitHub. Mine addresses the publication of data inside that new repo: through a local clone (clone that can be done in your cloud environment) – VonC Feb 02 '17 at 07:54
  • Respectfully, I disagree. Using a local clone would cause problems. - First off where would you put the local clone in the cloud? In the public folder? the app is sitting in cloud, the public folder may get wiped. - Also, and then do the git init sequence, depending on env you may not have access to the cli? - Would you manually check the local repo everytime? Or download the now created repo from github, initialise it into the public folder? If I did not phrase my question properly to begin with, apologies for that. Appreciate you looking at the question originally. – zaYZNXhT ZLCpve6R Feb 02 '17 at 08:04
  • I confirm: I do not understand your question. Or your answer. – VonC Feb 02 '17 at 08:06
  • I appreciate your edit. I've been thinking about why my question seems vague to you. I'm trying to understand the question/answer better. See below: I am building a webapp. The stack is react, meteor, mongodb deploy is via meteor framework. Sitting in front of this is an nginx server, which also hosts the website. This app needs to save db contents to github. But there is no local file system. I think I was not clear about it being a webapp maybe. Maybe you assumed a desktop app. Please let me know, it is important to me to understand this. Thank you for your assistance. – zaYZNXhT ZLCpve6R Feb 02 '17 at 13:39
  • "This app needs to save db contents to github": stange: you will find tons of answers on SO explaining why Git (and by extension GitHub) is ill-suited for database content. – VonC Feb 02 '17 at 13:49
  • I understand what you are saying now. I was not aware of these issues. Very much appreciate you pointing this out. Did some research on this topic. Was quite interesting. Probably still going to use github for our specific use case, but move to some type of large file storage in a bit. – zaYZNXhT ZLCpve6R Feb 06 '17 at 00:23
0

Creating a repo using GitHub API Notes

  • The simple answer is that there are no folder's so to speak in GitHub, hence cannot be created.
  • The fancy answer is that github is a content addressable key value system, hence no folders per say.
  • No files either, it should be noted, everything is a commit-able blob basically.

How to use the above info: (1) Create a new repo, from Meteor (my use case).


    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) This looks like:


    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) And will return a 201 like so: https://developer.github.com/v3/repos/#response-2

(4) Delete is also quite simple. Please note that authorisations are (pretty obvious really) in the api relating to the token, as per this comment. This caused me some issues as I kept trying to change permissions of the owner, when what needed to happen was change permissions of the authorisation token. Ignore the below settings, and don't try to set them in the createRepo call.

Community
  • 1
  • 1