Exemplo n.º 1
0
        private static async Task LoadOwnersAsync(GitHubClient client, CachedOrg cachedOrg)
        {
            var owners = await client.Organization.Member.GetAll(cachedOrg.Name, OrganizationMembersFilter.All, OrganizationMembersRole.Admin, ApiOptions.None);

            foreach (var owner in owners)
            {
                cachedOrg.Owners.Add(owner.Login);
            }
        }
Exemplo n.º 2
0
        private static async Task <CachedOrg> LoadCachedOrgAsync(GitHubClient client, string orgName)
        {
            var cachedOrg = await CachedOrg.LoadAsync(orgName);

            if (cachedOrg == null)
            {
                cachedOrg = await LoadCachedOrgFromGitHubAsync(client, orgName);

                await cachedOrg.SaveAsync();
            }

            return(cachedOrg);
        }
Exemplo n.º 3
0
        private static async Task <CachedOrg> LoadCachedOrgFromGitHubAsync(GitHubClient client, string orgName)
        {
            Console.WriteLine("Loading org data from GitHub...");

            var cachedOrg = new CachedOrg();

            cachedOrg.Name = orgName;

            await LoadOwnersAsync(client, cachedOrg);
            await LoadTeamsAsync(client, cachedOrg);
            await LoadReposAndCollaboratorsAsync(client, cachedOrg);

            cachedOrg.Initialize();

            return(cachedOrg);
        }
Exemplo n.º 4
0
        private static async Task LoadTeamsAsync(GitHubClient client, CachedOrg cachedOrg)
        {
            var teams = await client.Organization.Team.GetAll(cachedOrg.Name);

            var i = 0;

            foreach (var team in teams)
            {
                PrintRateLimit(client);
                PrintPercentage(i++, teams.Count, team.Name);

                var cachedTeam = new CachedTeam
                {
                    Id       = team.Id.ToString(),
                    ParentId = team.Parent?.Id.ToString(),
                    Name     = team.Name
                };
                cachedOrg.Teams.Add(cachedTeam);

                var request = new TeamMembersRequest(TeamRoleFilter.All);
                var members = await client.Organization.Team.GetAllMembers(team.Id, request);

                foreach (var member in members)
                {
                    cachedTeam.Members.Add(member.Login);
                }

                foreach (var repo in await client.Organization.Team.GetAllRepositories(team.Id))
                {
                    var permissionLevel = repo.Permissions.Admin
                                            ? CachedPermission.Admin
                                            : repo.Permissions.Push
                                                ? CachedPermission.Push
                                                : CachedPermission.Pull;

                    var cachedRepoAccess = new CachedTeamAccess
                    {
                        RepoName   = repo.Name,
                        Permission = permissionLevel
                    };
                    cachedTeam.Repos.Add(cachedRepoAccess);
                }
            }
        }
Exemplo n.º 5
0
        private static async Task LoadReposAndCollaboratorsAsync(GitHubClient client, CachedOrg cachedOrg)
        {
            var repos = await client.Repository.GetAllForOrg(cachedOrg.Name);

            var i = 0;

            foreach (var repo in repos)
            {
                PrintRateLimit(client);
                PrintPercentage(i++, repos.Count, repo.FullName);

                var cachedRepo = new CachedRepo
                {
                    Name      = repo.Name,
                    IsPrivate = repo.Private,
                    LastPush  = repo.PushedAt ?? repo.CreatedAt
                };
                cachedOrg.Repos.Add(cachedRepo);

                foreach (var user in await client.Repository.Collaborator.GetAll(repo.Owner.Login, repo.Name))
                {
                    var permission = user.Permissions.Admin
                                        ? CachedPermission.Admin
                                        : user.Permissions.Push
                                            ? CachedPermission.Push
                                            : CachedPermission.Pull;

                    var cachedCollaborator = new CachedUserAccess
                    {
                        RepoName   = cachedRepo.Name,
                        User       = user.Login,
                        Permission = permission
                    };
                    cachedOrg.Collaborators.Add(cachedCollaborator);
                }
            }
        }