public static bool IsMarkerTeam(this CachedTeam team) { var org = team.Org; return(team == org.GetMicrosoftTeam() || team == org.GetMicrosoftBotsTeam() || team == org.GetBotsTeam()); }
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); }
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); }
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)); } }
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()); }
public static CachedAccessReason FromTeam(CachedTeam team) { return(new CachedAccessReason(isOwner: false, isCollaborator: false, team)); }
private CachedAccessReason(bool isOwner, bool isCollaborator, CachedTeam team) { IsOwner = isOwner; IsCollaborator = isCollaborator; Team = team; }
public static bool IsOwnedByMicrosoft(this CachedTeam team) { var microsoftTeam = team.Org.GetMicrosoftTeam(); return(team.AncestorsAndSelf().Any(t => t == microsoftTeam)); }
public static string Markdown(this CachedTeam team) { return($"[{team.Name}]({team.Url})"); }