Skip to content

Add utility methods for modifying files via the Git API #1052

Closed

Description

@parkr

Recently, I ran into a size limit with the Contents API: the blob I was trying to update exceeded 1MB. To fix this, GitHub recommends the following:

As an example, if you wanted to commit a change to a file in your repository, you would:

  1. Get the current commit object
  2. Retrieve the tree it points to
  3. Retrieve the content of the blob object that tree has for that particular file path
  4. Change the content somehow and post a new blob object with that new content, getting a blob SHA back
  5. Post a new tree object with that file path pointer replaced with your new blob SHA getting a tree SHA back
  6. Create a new commit object with the current commit SHA as the parent and the new tree SHA, getting a commit SHA back
  7. Update the reference of your branch to point to the new commit SHA

It seems to me that a fairly common use of this library is to update contents of a blob. I do it in several projects (this morning, in sourcegraph/checkup). To get around the size restriction of the Contents API, the user must jump through these hoops each time. It's not ideal.

What do you think about shipping a series of utility methods which allow users to Create, Update, and Delete files using the Git API?

While the above description is fairly straightforward, it can seem complicated and overwhelming for something that is so transparent to the end user. I'd love to implement this once, in this library, and never have to think about implementing it again. 😄

Activity

  1. gmlewis commented on Nov 15, 2018

    @gmlewis
    Collaborator

    Hmmm... this sounds interesting... and I've got mixed feelings. The purist in me thinks that the Git API should stay out of a GitHub API repo. The pragmatist in me thinks that this might be a handy place to have that functionality.

    I'm thinking that the purist in me is winning... and that a separate "companion" repo could handle the details of the Git API.

    Thoughts from other contributors or users? Let's keep this open a while for discussion.

  2. NeenuAVarghese commented on Mar 30, 2020

    @NeenuAVarghese

    I'd be interested in getting to a solution to this issue as well. My use case is not as complex as the above but the core issue remains the same i.e that the contents API does not support returning file contents for file sizes more than 1 MB.
    My use case is to simply get content of certain files from a Git repo and stick the file into another Git repo.
    I tried using the Git Data API to get the blob: https://developer.github.com/v3/git/blobs/#get-a-blob. I need the file sha to get the blob. The easy way to get SHA as far as I know is through https://developer.github.com/v3/repos/contents/#get-the-readme which does not allow file sizes more than 1 MB. Another way could be to

    1. Get the current commit object
    2. Retrieve the tree it points to
    3. Retrieve the content of the blob object that tree has for that particular file path
    4. USE SHA to make https://developer.github.com/v3/git/blobs/#get-a-blob API request to finally get a base encoded version of the content.

    Any other suggestions ?

  3. gmlewis commented on Mar 30, 2020

    @gmlewis
    Collaborator

    Have either of you tried using go-git or go.git-scm in conjunction with this GitHub API client library?

    If so, could you please post the results here (pros/cons, if it worked or not, etc.)?

  4. alexellis commented on Oct 20, 2020

    @alexellis
    Contributor

    For anyone else landing here, go-git has moved to https://github.com/go-git/go-git

  5. gmlewis commented on Aug 6, 2021

    @gmlewis
    Collaborator

    Closing issue for lack of activity/interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions