//Constructor for a user, storing neccesary info
 public SearchUser(string user, IReadOnlyList <Repository> gitHubRepo, SearchUsersResult result, string url)
 {
     this.GitHubRepositories = gitHubRepo;
     this.Name   = user;
     this.Result = result;
     this.URL    = url;
 }
Exemple #2
0
        private async Task CalculateOrderAndFinalize(SearchUsersResult result, string location)
        {
            _statusService.SetCalculatingOrder(location);

            await SetAllReposAndCommits(location);

            _statusService.SetFinished(location, result.TotalCount);
        }
Exemple #3
0
        public async Task <SearchUsersResult> GetUsersFrom(string location, DateRange dateRange, int page, int rows)
        {
            try
            {
                if (string.IsNullOrEmpty(location))
                {
                    throw (new ArgumentNullException("location is mandatory"));
                }

                if (page <= 0)
                {
                    throw (new ArgumentNullException("page not valid"));
                }

                if (rows <= 0)
                {
                    throw (new ArgumentNullException("rows not valid"));
                }

                if (dateRange == null)
                {
                    throw (new ArgumentNullException("dateRange not valid"));
                }

                SearchUsersResult users = await GetClient.Search.SearchUsers(new SearchUsersRequest("location:" + location)
                {
                    Order        = SortDirection.Descending,
                    SortField    = UsersSearchSort.Repositories,
                    AccountType  = AccountSearchType.User,
                    Repositories = new Range(1, int.MaxValue),
                    PerPage      = rows,
                    Created      = dateRange,
                    Page         = page
                });

                var apiInfo   = GetClient.GetLastApiInfo();
                var rateLimit = apiInfo?.RateLimit;

                if (rateLimit.Remaining == 0)
                {
                    WaitForLimitRequestsPerMinute();
                }

                return(users);
            }
            catch (RateLimitExceededException limit)
            {
                WaitForLimitRequestsPerMinute();
                return(await GetUsersFrom(location, dateRange, page, rows));
            }
            catch (Exception err)
            {
                Debug.WriteLine(err.Message);
                return(new SearchUsersResult());
            }
        }
Exemple #4
0
        public async Task <string> ceva()
        {
            string githubApiToken = "9030077c0ec294b9eaed0e4b68f25afb5ce36fcf";

            var gitHubClient = new GitHubClient(ProductHeaderValue.Parse("proiectLicenta"));

            gitHubClient.Credentials = new Credentials(githubApiToken);

            var request = new SearchUsersRequest("RobertSandu");

            SearchUsersResult result = await gitHubClient.Search.SearchUsers(request);


            return("ceva");
        }
        private static async Task UserExamples(GitHubClient client)
        {
            User user = await client.User.Get("octokit");

            Console.WriteLine($"User.Get: Id={user.Id}");

            SearchUsersResult result = await client.Search.SearchUsers(
                new SearchUsersRequest("oct")
            {
                AccountType = AccountSearchType.User
            });

            Console.WriteLine($"Search.SearchUsers (Simple Search): TotalCount={result.TotalCount}");

            await UserAllFieldsExample(client);
        }
        private async Task <List <UsuarioModel> > ResultadoPesquisa(GitHubClient api, SearchUsersRequest pesquisa)
        {
            SearchUsersResult resultado = await api.Search.SearchUsers(pesquisa);

            List <UsuarioModel> usuarios = new List <UsuarioModel>();

            for (int j = 0; j < resultado.Items.Count(); j++)
            {
                // faz a requisição para buscar todos os dados do usuário
                User user = await api.User.Get(resultado.Items[j].Login);

                // adiciona o usuario a lista a ser retornada
                usuarios.Add(new UsuarioModel(resultado.Items[j].Login,
                                              user.Name,
                                              user.Email,
                                              user.Company,
                                              user.Location,
                                              user.Followers,
                                              user.AvatarUrl));
            }

            return(usuarios);
        }
Exemple #7
0
        private async void GetGithubInformation(CommandMessage command)
        {
            try
            {
                string       username = (command.Arguments.ContainsKey("Username")) ? command.Arguments["Username"] : command.Nick.Nickname;
                GitHubClient github   = new GitHubClient(new ProductHeaderValue("Combot-IRC-Bot"));
                if (GetOptionValue("Token").ToString() != string.Empty)
                {
                    string      token = GetOptionValue("Token").ToString();
                    Credentials creds = new Credentials(token);
                    github.Credentials = creds;
                }
                SearchUsersResult foundUser = await github.Search.SearchUsers(new SearchUsersRequest(username));

                if (foundUser.TotalCount > 0)
                {
                    User user = await github.User.Get(foundUser.Items.First().Login);

                    if (command.Arguments.ContainsKey("Repository"))
                    {
                        string repo = command.Arguments["Repository"];
                        try
                        {
                            Repository foundRepo = await github.Repository.Get(user.Login, repo);

                            if (foundRepo != null)
                            {
                                string repoMessage = string.Format("\u0002{0}\u0002 | Created On \u0002{1}\u0002 | \u0002{2}\u0002 Open Issues | \u0002{3}\u0002 Forks | \u0002{4}\u0002 Stargazers | {5}", foundRepo.FullName, foundRepo.CreatedAt.ToString("d"), foundRepo.OpenIssuesCount, foundRepo.ForksCount, foundRepo.StargazersCount, foundRepo.HtmlUrl);
                                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, repoMessage);
                                if (foundRepo.Description != string.Empty)
                                {
                                    SendResponse(command.MessageType, command.Location, command.Nick.Nickname, foundRepo.Description);
                                }
                            }
                            else
                            {
                                SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "Invalid Repository Name");
                            }
                        }
                        catch (Octokit.NotFoundException ex)
                        {
                            SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "Invalid Repository Name");
                        }
                    }
                    else
                    {
                        string userMessage = string.Format("\u0002{0}\u0002 - \u0002{1}\u0002 Followers - Following \u0002{2}\u0002 Users - \u0002{3}\u0002 Repositories | {4}", user.Login, user.Followers, user.Following, user.PublicRepos, user.HtmlUrl);
                        SendResponse(command.MessageType, command.Location, command.Nick.Nickname, userMessage);
                    }
                }
                else
                {
                    SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("Github user \u0002{0}\u0002 does not exist.", username));
                }
            }
            catch (Octokit.RateLimitExceededException ex)
            {
                ThrowError(ex);
            }
            catch (Octokit.ApiValidationException ex)
            {
                ThrowError(ex);
            }
        }
 //Constructor for when no user is found
 public SearchUser(string user, SearchUsersResult result)
 {
     this.Name   = user;
     this.Result = result;
 }