コード例 #1
0
        public Update Should(string repo, IEnumerable <GitTeam> repoTeams, GitTeam targetTeam, Permission targetPermission)
        {
            // If there is no :only filter specified, then we have to assume it's included
            var isIncluded = this.only.Any() ? this.only.Any(t => t.Equals(repo, StringComparison.CurrentCultureIgnoreCase)) : true;
            var isExcluded = this.not.Any(t => t.Equals(repo, StringComparison.CurrentCultureIgnoreCase));

            if (!isIncluded || isExcluded)
            {
                return(Update.Skip);
            }

            var repoTeam = repoTeams.SingleOrDefault(t => t.Name.Equals(targetTeam.Name));

            if (repoTeam == null)
            {
                return(Update.Add);
            }

            if ((int)repoTeam.Permission > (int)targetPermission)
            {
                return(Update.UpdatePermission);
            }

            return(Update.Nothing);
        }
コード例 #2
0
            public async Task <bool> UpdateTeamPermissionAsync(string reponame, GitTeam target, Permission targetPermission)
            {
                bool updated = false;
                var  removed = await wrapper.client.Organization.Team.RemoveRepository(target.Id, Config.Github.Org, reponame);

                if (removed)
                {
                    updated = await wrapper.client.Organization.Team.AddRepository(target.Id, Config.Github.Org, reponame, new RepositoryPermissionRequest(targetPermission));
                }

                return(updated);
            }
コード例 #3
0
        public override async Task Check(List <Repository> all_repos, Repository repo)
        {
            // Figure out the team id, this only has to happen once (and this function get repeated)
            if (team == null)
            {
                team = await Wrapper.GetTeamAsync(teamname);
            }
            var repo_teams = await Wrapper.Repo.GetTeamsAsync(repo.Name);

            var repo_team = repo_teams.SingleOrDefault(t => t.Name.Equals(team.Name));

            var action = Should(repo.Name, repo_teams, team, permission);

            switch (action)
            {
            case Update.Skip:
                l($"[SKIP] {repo.Name} doesn't need this action applied.", 2);
                break;

            case Update.Nothing:
                l($"[OK] {team.Name} is already a collaborator of {repo.Name}", 2);
                break;

            case Update.Add:
                l($"[UPDATE] will add {team.Name} to {repo.Name} as {this.permission}", 2);
                break;

            case Update.UpdatePermission:
                l($"[UPDATE] {team.Name} is not at {this.permission} (but is {repo_team.Permission}) for {repo.Name}", 2);
                break;
            }

            if (new [] { Update.Add, Update.UpdatePermission }.Contains(action))
            {
                all_repos.Add(repo);
            }
        }