Exemplo n.º 1
0
        public static bool IsMarkerTeam(this CachedTeam team)
        {
            var org = team.Org;

            return(team == org.GetMicrosoftTeam() ||
                   team == org.GetMicrosoftBotsTeam() ||
                   team == org.GetBotsTeam());
        }
Exemplo n.º 2
0
        public static IEnumerable <CachedUser> GetMaintainers(this CachedTeam team)
        {
            var result = team.Maintainers.Where(u => !u.IsBot());

            if (!result.Any())
            {
                return(team.Org.GetOwners());
            }

            return(result);
        }
Exemplo n.º 3
0
 public PolicyViolation(PolicyDescriptor descriptor,
                        string title,
                        string body,
                        CachedOrg org,
                        CachedRepo repo = null,
                        CachedTeam team = null,
                        CachedUser user = null,
                        IReadOnlyCollection <CachedUser> assignees = null)
 {
     Descriptor  = descriptor;
     Fingerprint = ComputeFingerprint(descriptor.DiagnosticId, repo, user, team);
     Title       = title;
     Body        = UnindentAndTrim(body);
     Org         = org;
     Repo        = repo;
     Team        = team;
     User        = user;
     Assignees   = ComputeAssignees(org, repo, team, user, assignees);
 }
Exemplo n.º 4
0
        private static Guid ComputeFingerprint(string diagnosticId, CachedRepo repo, CachedUser user, CachedTeam team)
        {
            using (var fingerprintBytes = new MemoryStream())
                using (var md5 = MD5.Create())
                {
                    using (var writer = new StreamWriter(fingerprintBytes, Encoding.UTF8, 2048, leaveOpen: true))
                    {
                        writer.WriteLine(diagnosticId);
                        writer.WriteLine(repo?.Org.Name);
                        writer.WriteLine(repo?.Name);
                        writer.WriteLine(user?.Login);
                        writer.WriteLine(team?.Name);
                    }

                    fingerprintBytes.Position = 0;

                    var hashBytes = md5.ComputeHash(fingerprintBytes);
                    return(new Guid(hashBytes));
                }
        }
Exemplo n.º 5
0
        private static IReadOnlyCollection <CachedUser> ComputeAssignees(CachedOrg org, CachedRepo repo, CachedTeam team, CachedUser user, IReadOnlyCollection <CachedUser> assignees)
        {
            if (assignees != null && assignees.Count > 0)
            {
                return(assignees);
            }

            if (repo != null)
            {
                return(repo.GetAdministrators().ToArray());
            }

            if (team != null)
            {
                return(team.GetMaintainers().ToArray());
            }

            if (user != null)
            {
                return new[] { user }
            }
            ;

            return(org.GetOwners().ToArray());
        }
Exemplo n.º 6
0
 public static CachedAccessReason FromTeam(CachedTeam team)
 {
     return(new CachedAccessReason(isOwner: false, isCollaborator: false, team));
 }
Exemplo n.º 7
0
 private CachedAccessReason(bool isOwner, bool isCollaborator, CachedTeam team)
 {
     IsOwner        = isOwner;
     IsCollaborator = isCollaborator;
     Team           = team;
 }
Exemplo n.º 8
0
        public static bool IsOwnedByMicrosoft(this CachedTeam team)
        {
            var microsoftTeam = team.Org.GetMicrosoftTeam();

            return(team.AncestorsAndSelf().Any(t => t == microsoftTeam));
        }
Exemplo n.º 9
0
 public static string Markdown(this CachedTeam team)
 {
     return($"[{team.Name}]({team.Url})");
 }