How to get a list of all forks of a GitHub repo?
Asked Answered
T

3

6

I would like to get a list of all forks of a GitHub repo (e.g. https://github.com/eternicode/bootstrap-datepicker), however I am unable to find out how to do it using octokit.net.

I want also get a renamed repositories, I could not just search a name of a repository.

Any hints?

CLARIFICATION: The rest api is described here https://developer.github.com/v3/repos/forks/, but how to do it with octokit.net?

Telly answered 12/1, 2015 at 10:15 Comment(1)
@YuvalItzchakov github.com/octokit/octokit.net/search?utf8=%E2%9C%93&q=fork but for forks just for Gists (not git repos). Do you know how to do it?Telly
O
2

The functionality has been added to octokit.net recently: https://github.com/octokit/octokit.net/blob/b07ce6e11a1b286dda0a65ee427bda3b8abcefb8/Octokit.Reactive/Clients/ObservableRepositoryForksClient.cs#L31

    /// <summary>
    /// Gets the list of forks defined for a repository
    /// </summary>
    /// <remarks>
    /// See <a href="http://developer.github.com/v3/repos/forks/#list-forks">API documentation</a> for more information.
    /// </remarks>
    /// <param name="owner">The owner of the repository</param>
    /// <param name="name">The name of the repository</param>
    public IObservable<Repository> GetAll(string owner, string name)
    {
        Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
        Ensure.ArgumentNotNullOrEmptyString(name, "name");

        return GetAll(owner, name, ApiOptions.None);
    }

Similar functions exist for other ways to specify repository.

Please feel free to edit in the full code for this use case here.

Orissa answered 16/7, 2016 at 13:22 Comment(0)
C
12

You can achieve that by visiting:

https://api.github.com/repos/<Author>/<Repo>/forks

Make sure to replace Author and Repo with suitable values.

Carmody answered 2/3, 2022 at 17:7 Comment(1)
Note that this will only give you the first 30 forks. For more, you need to paginate with page (or modify per_page). See docs.github.com/en/rest/repos/forks?apiVersion=2022-11-28Foster
O
2

The functionality has been added to octokit.net recently: https://github.com/octokit/octokit.net/blob/b07ce6e11a1b286dda0a65ee427bda3b8abcefb8/Octokit.Reactive/Clients/ObservableRepositoryForksClient.cs#L31

    /// <summary>
    /// Gets the list of forks defined for a repository
    /// </summary>
    /// <remarks>
    /// See <a href="http://developer.github.com/v3/repos/forks/#list-forks">API documentation</a> for more information.
    /// </remarks>
    /// <param name="owner">The owner of the repository</param>
    /// <param name="name">The name of the repository</param>
    public IObservable<Repository> GetAll(string owner, string name)
    {
        Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
        Ensure.ArgumentNotNullOrEmptyString(name, "name");

        return GetAll(owner, name, ApiOptions.None);
    }

Similar functions exist for other ways to specify repository.

Please feel free to edit in the full code for this use case here.

Orissa answered 16/7, 2016 at 13:22 Comment(0)
P
0

Threads a bit old but in case someone else ends up here from google thought Id necro it.

        private static IReadOnlyList<Octokit.Repository> retrieveGitHubRepos()
    {
        Task<IReadOnlyList<Octokit.Repository>> getRepoList = null;
        string appname = System.AppDomain.CurrentDomain.FriendlyName;
        Octokit.GitHubClient client = new Octokit.GitHubClient(new Octokit.ProductHeaderValue(ConnectionDetails.appName));
        client.Credentials = new Octokit.Credentials(ConnectionDetails.username, ConnectionDetails.password);
        Task.Run(() => getRepoList = client.Repository.GetAllForUser(ConnectionDetails.username)).Wait();
        return getRepoList.Result;
    }
Parole answered 11/5, 2015 at 9:19 Comment(1)
According to the name (GetAllForUser), it does not return all forks.Telly

© 2022 - 2024 — McMap. All rights reserved.