示例#1
0
        /// <summary>
        /// Finds three repos per username per run. I.e: if runs is set to 1 finds 3 repos that belong to the initial username.
        /// If runs is set to 2, finds 3 repos that follow the initial username and then 3 repos that belong to each of those repos 3 stargazers.
        /// </summary>
        /// <param name="username"> username that all repos stem from </param>
        /// <param name="runs"> One-indexed value for how deep the runs go (max 3 required by project) </param>
        /// <returns> A list of repos that follow the username, sometimes indirectly (repos from stargazers of repos of the username) </returns>
        public async Task <IEnumerable <Repo> > FindReposByUsername(string username, int runs)
        {
            var repos          = new List <Repo>();
            var loginsToSearch = new List <string> {
                username
            };

            for (int i = 0; i < runs; i++)
            {
                var reposFound = new List <Repo>();

                foreach (var login in loginsToSearch)
                {
                    reposFound.AddRange(await _api.FindThreeReposByUsername(login));
                }

                loginsToSearch = new List <string>(); // reset the logins to search here
                foreach (var repo in reposFound)
                {
                    var stargazers = (await _api.FindThreeStargazersByRepoAndUsername(repo.Name, repo.Owner.Login))
                                     .ToList();
                    repo.Stargazers = stargazers;
                    loginsToSearch.AddRange(stargazers.Select(x =>
                                                              x.Login)); // as we grab the logins, add them to the logins to be searched
                }

                repos.AddRange(reposFound);
            }

            return(repos);
        }