-
Notifications
You must be signed in to change notification settings - Fork 186
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
CodeOwnersParser Team/User lookup #6366
Changes from all 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 from {TeamUserStorageURI}. rawJson={rawJson}"); | ||
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}"); | ||
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. 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>(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weshaggard, I had to add another command line option to RetrieveCodeOwners to allow writing the json output to the file. The fact is, the get-codeowners.lib.ps1 was incorrectly assuming any/all output from the executable was nothing more than a json codeowner entry. Using CodeOwnersParser FileHelper GetUrlContents to fetch the blob, will cause output that'll break this assumption. The correct fix for this is the add the option to write the entry to a file. The problem here is because of locked version in the eng/common/get-codeowners.lib.ps1 script, I can't make the changes, to use the file instead of output, to the script until this is checked in and another version has been published.
@konrad-jamrozik and I already chatted about this and both agreed this was the correct way to fix this.