Skip to content

Commit 8be1fc1

Browse files
author
Calin Lupas
authored
Merge branch 'main' into feature/add-telemetry-and-feature-flags
2 parents f2fc52e + 067ce4e commit 8be1fc1

18 files changed

Lines changed: 752 additions & 663 deletions

src/DevExcelerateApi/Core/Extensions/ServiceExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ internal static IServiceCollection AddAppServices(this IServiceCollection servic
9595
services.AddSingleton<IDevExPullRequestEventProcessorService, DevExPullRequestEventProcessorService>();
9696
services.AddSingleton<WebhookEventProcessor, DevExWebhookEventProcessorService>();
9797
services.AddSingleton<IRepositoryService, RepositoryService>();
98+
services.AddSingleton<ITeamService, TeamService>();
9899
services.AddSingleton<IIssueService, IssueService>();
99100

100101
return services;

src/DevExcelerateApi/Core/Extensions/StringExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public static bool IsIssueRejected(this string data)
3838

3939
private static readonly Regex InvalidCharsRegex = new(@"[^a-zA-Z0-9\-_.]", RegexOptions.Compiled);
4040

41-
public static string SanitizeRepositoryName(this string repositoryName)
41+
public static string SanitizeResourceName(this string name)
4242
{
43-
if (string.IsNullOrEmpty(repositoryName))
43+
if (string.IsNullOrEmpty(name))
4444
{
45-
throw new ArgumentException("Repository name cannot be null or empty.", nameof(repositoryName));
45+
throw new ArgumentException("Repository name cannot be null or empty.", nameof(name));
4646
}
4747

48-
return InvalidCharsRegex.Replace(repositoryName, string.Empty);
48+
return InvalidCharsRegex.Replace(name, string.Empty);
4949
}
5050
}
5151
}

src/DevExcelerateApi/Models/Constants.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@ public static class Constants
88
// GitHub Policies
99
public const string GitHubPoliciesFolderPath = ".github/policies/";
1010
public const string GitHubInventoryReposFolderPath = "repositories/";
11+
public const string GitHubInventoryTeamsFolderPath = "teams/";
1112
public const string GitHubDefaultBranch = "main";
1213
public const string GitHubPullRequestTitleIssueNumber = "Issue#";
1314

1415
// Constants for the different types of messages that can be sent
16+
17+
// Repository related constants
1518
public const string ERROR_REPO_CREATION = "ERROR_REPO_CREATION";
1619
public const string ERROR_REPO_EXISTS = "ERROR_REPO_EXISTS";
1720
public const string ERROR_REPO_TEAM_DOES_NOT_EXISTS = "ERROR_REPO_TEAM_DOES_NOT_EXISTS";
1821
public const string ERROR_REPO_RULESET_DOES_NOT_EXISTS = "ERROR_REPO_RULESET_DOES_NOT_EXISTS";
19-
public const string ERROR_REPO_PR_CREATION = "ERROR_REPO_PR_CREATION";
20-
public const string ERROR_REPO_PR_NO_CHANGES = "ERROR_REPO_PR_NO_CHANGES";
22+
23+
// Repository PR related constants
24+
public const string ERROR_PR_CREATION = "ERROR_REPO_PR_CREATION";
25+
public const string ERROR_PR_NO_CHANGES = "ERROR_REPO_PR_NO_CHANGES";
26+
27+
// Team related constants
28+
public const string ERROR_TEAM_CREATION = "ERROR_TEAM_CREATION";
29+
public const string ERROR_TEAM_EXISTS = "ERROR_TEAM_EXISTS";
30+
public const string ERROR_PARENT_TEAM_DOES_NOT_EXISTS = "ERROR_PARENT_TEAM_DOES_NOT_EXISTS";
31+
public const string ERROR_TEAM_MEMBER_DOES_NOT_EXISTS = "ERROR_TEAM_MEMBER_DOES_NOT_EXISTS";
32+
2133
public const string VALIDATION_PASSED = "VALIDATION_PASSED";
2234
public const string ISSUE_APPROVED = "ISSUE_APPROVED";
2335
public const string ISSUE_COMPLETED = "ISSUE_COMPLETED";

src/DevExcelerateApi/Models/CreateRepositoryRequestModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class CreateRepositoryRequestModel : DevExIssueRequestModel
4343
{
4444
RequestType = DevExIssueRequestModel.Parse(values).RequestType,
4545
RepositoryOwner = repositoryOwner?.ToString(),
46-
RepositoryName = repositoryName?.ToString()?.SanitizeRepositoryName(),
46+
RepositoryName = repositoryName?.ToString()?.SanitizeResourceName(),
4747
RepositoryVisibility = repositoryVisibility?.ToString(),
4848
RepositoryClassification = repositoryClassification?.ToString(),
4949
RepositoryDescription = repositoryDescription?.ToString(),
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using DevExcelerateApi.Core.Extensions;
2+
using DevExcelerateApi.Helpers;
3+
4+
namespace DevExcelerateApi.Models
5+
{
6+
public class CreateTeamRequestModel : DevExIssueRequestModel
7+
{
8+
public string? TeamOwner { get; set; } // will be inherited from issue
9+
10+
public string? TeamName { get; set; }
11+
12+
public string? TeamDescription { get; set; }
13+
14+
public string? ParentTeamName { get; set; }
15+
16+
public string? TeamIdentityProviderGroup { get; set; }
17+
18+
// TeamPrivacy: secret, closed (visible to all members of the organization.)
19+
public string? TeamVisibility { get; set; }
20+
21+
public string? TeamMaintainers { get; set; } // will be inherited from issue
22+
23+
public string? TeamMembers { get; set; }
24+
25+
public static new CreateTeamRequestModel Parse(IDictionary<string, object?> values)
26+
{
27+
ArgumentNullException.ThrowIfNull(values);
28+
29+
values.TryGetValue("team_owner", out var teamOwner);
30+
values.TryGetValue("team_name", out var teamName);
31+
values.TryGetValue("team_description", out var teamDescription);
32+
values.TryGetValue("parent_team_name", out var parentTeamName);
33+
values.TryGetValue("team_identity_provider_group", out var teamIdentityProviderGroup);
34+
values.TryGetValue("team_visibility", out var teamVisibility);
35+
values.TryGetValue("team_maintainers", out var teamMaintainers);
36+
values.TryGetValue("team_members", out var teamMembers);
37+
38+
return new CreateTeamRequestModel
39+
{
40+
RequestType = DevExIssueRequestModel.Parse(values).RequestType,
41+
TeamOwner = teamOwner?.ToString(),
42+
TeamName = teamName?.ToString()?.SanitizeResourceName(),
43+
TeamDescription = teamDescription?.ToString(),
44+
ParentTeamName = parentTeamName?.ToString(),
45+
TeamIdentityProviderGroup = teamIdentityProviderGroup?.ToString(),
46+
TeamVisibility = teamVisibility?.ToString(),
47+
TeamMaintainers = teamMaintainers?.ToString(),
48+
TeamMembers = teamMembers?.ToString(),
49+
};
50+
}
51+
52+
public bool IsValid()
53+
{
54+
return !string.IsNullOrEmpty(TeamName) &&
55+
!string.IsNullOrEmpty(TeamDescription) &&
56+
!string.IsNullOrEmpty(TeamVisibility);
57+
}
58+
59+
public string SerializeToYaml()
60+
{
61+
return YamlHelpers.Serialize(this);
62+
}
63+
64+
public static CreateTeamRequestModel DeserializeFromYaml(string yamlContent)
65+
{
66+
ArgumentNullException.ThrowIfNull(yamlContent);
67+
return YamlHelpers.Deserialize<CreateTeamRequestModel>(yamlContent);
68+
}
69+
}
70+
}

src/DevExcelerateApi/Models/DevExIssueRequestModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static DevExIssueRequestModel Parse(IDictionary<string, object?> values)
3131

3232
public enum RequestType
3333
{
34-
CREATE_REPOSITORY = 1
34+
CREATE_REPOSITORY = 1,
35+
CREATE_TEAM = 2
3536
}
3637
}

src/DevExcelerateApi/Models/DevExPolicies.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ public enum DevExPolicies
77
[Description("Repository Metadata")]
88
Repository_Metadata = 1,
99
[Description("Repository Protection")]
10-
Repository_Protection
10+
Repository_Protection,
11+
[Description("Team Metadata")]
12+
Team_Metadata
1113
}
1214

1315
public static class DevExPoliciesExtensions
@@ -18,6 +20,7 @@ public static string GetPolicyYamlFileName(this DevExPolicies policy)
1820
{
1921
DevExPolicies.Repository_Metadata => "repository-metadata.yml",
2022
DevExPolicies.Repository_Protection => "repository-protection.yml",
23+
DevExPolicies.Team_Metadata => "team-metadata.yml",
2124
_ => throw new ArgumentOutOfRangeException(nameof(policy), policy, null)
2225
};
2326
}

src/DevExcelerateApi/Resources/Models.TicketStatus.fr.resx

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)