Skip to content

private repositories#3

Closed
durka wants to merge 1 commit into
josegonzalez:masterfrom
durka:patch-1
Closed

private repositories#3
durka wants to merge 1 commit into
josegonzalez:masterfrom
durka:patch-1

Conversation

@durka

@durka durka commented Nov 25, 2014

Copy link
Copy Markdown

I couldn't get github-backup to see my private repositories. It seems the /users/$user/repos API endpoint refuses to show them. So I changed it to use the /user/repos endpoint when authenticated. After that, I couldn't get it to correctly clone the private repositories, so I changed that part to use the SSH url instead of the HTTPS url. Now it Works On My Machine (tm).

@josegonzalez

Copy link
Copy Markdown
Owner

A couple things:

  • Would be good to make the ssh vs https an option, defaulting to https (though I prefer ssh personally). BC compatibility and all.
  • Have you tried seeing what happens when you use your token against that user in /users/$USER/repos? Pretty sure that should work.

@durka

durka commented Nov 25, 2014

Copy link
Copy Markdown
Author
  • True. I can rework the PR to do that.
  • Well, that's what the documentation says, indeed, but it doesn't seem to work:
$ curl -H "Authorization: token $(cat token.secret)" https://api.github.com/users/durka/repos?type=all 2>/dev/null | grep '"private"' | sort | uniq
    "private": false,

@josegonzalez

Copy link
Copy Markdown
Owner

Thats so odd...

@durka

durka commented Nov 25, 2014

Copy link
Copy Markdown
Author

Actually, reading that doc again, it says /users/:username/repos lists only the public repositories. So to get the private ones you have to use /user/repos.

@durka

durka commented Nov 25, 2014

Copy link
Copy Markdown
Author

PR updated with some more changes, including the option for SSH. I added some consistency checks so you can't pass -u and -t that don't match, and you can't pass -P if the authentication doesn't match USER.

- check the real username when an auth token is provided (error if
  it doesn't match)
    - this caused an infinite loop between get_auth/retrieve_data,
      so I added a parameter to retrieve_data to escape that
- error if you pass -P but someone else's username
- optionally use SSH instead of HTTPS to clone

changes to better support private repos:
    - only check the authentication once!
    - check the real username when an auth token is provided (error if
      it doesn't match)
        - this caused an infinite loop between get_auth/retrieve_data,
          so I added a parameter to retrieve_data to escape that
    - error if you pass -P but someone else's username
    - optionally use SSH instead of HTTPS to clone
@durka

durka commented Nov 25, 2014

Copy link
Copy Markdown
Author

One more update: I realized that retrieve_data calls get_auth every time, and since I added an API call to get_auth that's not a good idea. So I memoized get_auth.

@josegonzalez

Copy link
Copy Markdown
Owner

I'll take a closer look at this tonight, thanks for the pull request :)

@josegonzalez josegonzalez self-assigned this Nov 25, 2014
@josegonzalez

Copy link
Copy Markdown
Owner

This should work now - tested against my own account and an organization. If not, please reopen against master.

@durka

durka commented Sep 5, 2015

Copy link
Copy Markdown
Author

I ran the following command

github-backup -u durka -t $REDACTED -o test --repositories -P durka

and it did not include my private repositories. That token has permissions repo, gist, read:org, user. I'm assuming I made some simple mistake...

whwright pushed a commit to whwright/python-github-backup that referenced this pull request Jun 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants