New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add remote upstream repository #9
Comments
This is an interesting idea! I need to see if the upstream URL is available in the JSON returned by GitHub's API. I don't see it in the So this is possible (but might require extra API requests for each repo). Would you be interested in preparing a pull request? |
Yessss I'm a python newbie. But i think that would not be too complicate. If i got stuck I'll put some questions here! |
I did not found any endpoint on Github that shows me the upstream nor a git command. But it is found on github repository page in 2 places:
I have filtered this link using curl 'https://github.com/edumco/ghcloneall' -so - | \
grep 'forked from <' | \
grep -iPo '(?<=href=")(.*)(?=">)' Result So dig into the code and found that on So added the following code: def get_github_url(self, remote_url):
""""
Turns a remote url into the normal Github URL:
Receives: git@github.com:edumco/ghcloneall.git
Returns: https:github.com/edumco/ghcloneall
"""
return (
remote_url.replace(".git", "").replace(":", "/").replace("git@", "https:")
)
def get_upstream(self, dir):
"""
Gets the remote url from the original "upstream" repository.
Receives: repo dir (".../repo")
Returns: the upstream url (git@github.com:user/repo.git)
"""
github_url = get_github_url(get_remote_url(dir))
# curl github_url -so - | \
# grep 'forked from <' | \
# grep -iPo '(?<=href=")(.*)(?=">)'
curl_upstream = [ "curl", github_url, "-so", "-", "|",
"grep", "'forked from <'", "|",
"grep", "-I", "P", "o", "'(?<=href=")(.*)(?=">)'" ]
upstream = self.check_output(curl_upstream, cwd=dir).strip()
## clean the first slash before return
return "git@github.com:".join(upstream).join(".git") I have 2 questions:
|
Ah, no. The GitHub API I linked to does provide this information, but calls it
I think it would be easiest to modify Lines 371 to 376 in 0db5163
You need Add another Repo attribute and Now when Then, in RepoTask.clone(), you can add another call inside the if: Lines 587 to 592 in 0db5163
something like self.check_call(['git', 'remote', 'add', 'upsteam', repo.upstream_url]) maybe guarded by (RepoTask.options is the RepoWrangler instance, which seems daft! If I did this today, I'd introduce a new Options class.) You know what worries me? If a separate API request is needed for each repository, then ghcloneall on an organization with 380+ repositories (like zopefoundation, my primary use case for ghcloneall) is going to issue 380+ API requests in short order. This may bump into anonymous API access rate limits. |
Idea for reducing GitHub API pressure:
This would be easy but not helpful at all for the initial 380+ repo clone.
But I think that always requires an authentication token, and I like that ghcloneall can run with zero setup or auth steps needed.
This would need to be combined with option 1, so additional requests happen only if you explicitly request them. |
Thanks for the helpful answer!
This is exactly what i was looking for! If I understood correctly i should use only the parent and only when it is a fork.
I completely agree with you about that! The first impression is the most important!
The option I will try this way and when I have some progress I show you again 👷 |
That sounds like a good idea, and adding support for authenticating with a ticket would also help with #8. (I would suggest not tackling everything at once: it may be better to add token authentication support in a separate PR.) |
Add remote upstream repository to the forked projects after cloning
Could be possible to add the upstream original repository for the forked repositories?
Every time I fork a project on Github I have to manually execute the following command:
This way I can keep the fork synchronized with the original repo.
I think it could be possible to add an option:
What do you think about it?
The text was updated successfully, but these errors were encountered: