-
Notifications
You must be signed in to change notification settings - Fork 256
CodeOwnersParser Team/User lookup #6366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
db5b625
16d03bd
5d04719
def2979
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Azure.Sdk.Tools.CodeOwnersParser | ||
| { | ||
| public class DefaultStorageConstants | ||
| { | ||
| public const string DefaultStorageURI = "https://azuresdkartifacts.blob.core.windows.net/azure-sdk-write-teams/azure-sdk-write-teams-blob"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Azure.Sdk.Tools.CodeOwnersParser | ||
| { | ||
| public class TeamUserHolder | ||
| { | ||
| private string TeamUserStorageURI { get; set; } = DefaultStorageConstants.DefaultStorageURI; | ||
| private Dictionary<string, List<string>>? _teamUserDict = null; | ||
|
|
||
| public Dictionary<string, List<string>> TeamUserDict | ||
| { | ||
| get | ||
| { | ||
| if (_teamUserDict == null) | ||
| { | ||
| _teamUserDict = GetTeamUserData(); | ||
| } | ||
| return _teamUserDict; | ||
| } | ||
| set | ||
| { | ||
| _teamUserDict = value; | ||
| } | ||
| } | ||
|
|
||
| public TeamUserHolder(string? teamUserStorageURI) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(teamUserStorageURI)) | ||
| { | ||
| TeamUserStorageURI = teamUserStorageURI; | ||
| } | ||
| } | ||
|
|
||
| private Dictionary<string, List<string>> GetTeamUserData() | ||
| { | ||
| if (null == _teamUserDict) | ||
| { | ||
| string rawJson = FileHelpers.GetFileOrUrlContents(TeamUserStorageURI); | ||
| var list = JsonSerializer.Deserialize<List<KeyValuePair<string, List<string>>>>(rawJson); | ||
| if (null != list) | ||
| { | ||
| return list.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); | ||
| } | ||
| Console.WriteLine($"Error! Unable to deserialize json team/user data. rawJson={rawJson}"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth including the TeamUserStorageURI as part of the error message as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add this in another commit before I merge. |
||
| return new Dictionary<string, List<string>>(); | ||
| } | ||
| return _teamUserDict; | ||
| } | ||
|
|
||
| public List<string> GetUsersForTeam(string teamName) | ||
| { | ||
| // The teamName in the codeowners file should be in the form <org>/<team>. | ||
| // The dictionary's team names do not contain the org so the org needs to | ||
| // be stripped off. Handle the case where the teamName passed in does and | ||
| // does not being with @org/ | ||
| string teamWithoutOrg = teamName.Trim(); | ||
| if (teamWithoutOrg.Contains('/')) | ||
| { | ||
| teamWithoutOrg = teamWithoutOrg.Split("/")[1]; | ||
| } | ||
| if (TeamUserDict != null) | ||
| { | ||
| if (TeamUserDict.ContainsKey(teamWithoutOrg)) | ||
| { | ||
| Console.WriteLine($"Found team entry for {teamWithoutOrg}"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to think about making this logging configurable or use a logging interface at some point as generally it isn't great for shared libraries to have a bunch of logging.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That won't be part of this PR. I created a new issue to track this. |
||
| return TeamUserDict[teamWithoutOrg]; | ||
| } | ||
| Console.WriteLine($"Warning: TeamUserDictionary did not contain a team entry for {teamWithoutOrg}"); | ||
| } | ||
| return new List<string>(); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.