Skip to content

Commit 72c0cd8

Browse files
calin-lupas_dsamcapscalin-lupas_dsamcaps
authored andcommitted
#41 Update repository feature
- Updated `GitHubClientExtensions` to modify existing pull requests instead of returning the first one found. - Added new constants in `Constants.cs` for better error handling. - Enhanced `RepositoryRequestModel` with an `Update` method for property updates and list management. - Improved `IsEmptyResponse` method in `GitHubIssueFormParser.cs` to check for "None". - Added new error messages and corrected translations in French localization files. - Refined validation logic in `RepositoryService` for repository requests, including checks for maintainers and existence. - Updated `TeamService` for better error handling and validation during team creation and updates. - Overall improvements to repository and team management features, enhancing user feedback and robustness.
1 parent f8e5724 commit 72c0cd8

8 files changed

Lines changed: 291 additions & 55 deletions

File tree

src/DevExcelerateApi/Core/Extensions/GitHubClientExtensions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,15 @@ public static async Task<PullRequest> CreatePullRequestAsync(this IGitHubClient
172172

173173
if (pullRequests.Any())
174174
{
175-
// If a pull request already exists, return the first one
176-
return pullRequests[0];
175+
// If a pull request already exists, update its title and body
176+
var existingPr = pullRequests[0];
177+
var update = new PullRequestUpdate
178+
{
179+
Title = title,
180+
Body = body
181+
};
182+
var updatedPr = await gitHubClient.PullRequest.Update(owner, repo, existingPr.Number, update);
183+
return updatedPr;
177184
}
178185

179186
// Step 2: Create a new pull request if none exists

src/DevExcelerateApi/Models/Constants.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ public static class Constants
1212
public const string GitHubDefaultBranch = "main";
1313
public const string GitHubPullRequestTitleIssueNumber = "Issue#";
1414

15-
// Constants for the different types of messages that can be sent
16-
15+
// Constants for the different types of messages that can be sent
16+
1717
// Repository related constants
1818
public const string ERROR_REPO_CREATION = "ERROR_REPO_CREATION";
1919
public const string ERROR_REPO_EXISTS = "ERROR_REPO_EXISTS";
2020
public const string ERROR_REPO_TEAM_DOES_NOT_EXISTS = "ERROR_REPO_TEAM_DOES_NOT_EXISTS";
2121
public const string ERROR_REPO_RULESET_DOES_NOT_EXISTS = "ERROR_REPO_RULESET_DOES_NOT_EXISTS";
2222
public const string ERROR_INVAILD_REPO_NAME = "ERROR_INVAILD_REPO_NAME";
23+
public const string ERROR_REPO_DOES_NOT_EXIST = "ERROR_REPO_DOES_NOT_EXIST";
24+
public const string ERROR_USER_NOT_REPO_MAINTAINER = "ERROR_USER_NOT_REPO_MAINTAINER";
2325

2426
// Repository PR related constants
2527
public const string ERROR_PR_CREATION = "ERROR_PR_CREATION";

src/DevExcelerateApi/Models/RepositoryRequestModel.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,70 @@ public static RepositoryRequestModel DeserializeFromYaml(string yamlContent)
149149
ArgumentNullException.ThrowIfNull(yamlContent);
150150
return YamlHelpers.Deserialize<RepositoryRequestModel>(yamlContent);
151151
}
152+
153+
public void Update(RepositoryRequestModel model)
154+
{
155+
if (string.IsNullOrEmpty(RepositoryDescription)) RepositoryDescription = model.RepositoryDescription;
156+
if (string.IsNullOrEmpty(RepositoryVisibility)) RepositoryVisibility = model.RepositoryVisibility;
157+
if (string.IsNullOrEmpty(RepositoryClassification)) RepositoryClassification = model.RepositoryClassification;
158+
159+
if (MaintainerList == null || MaintainerList.Count == 0)
160+
{
161+
MaintainerList = model.MaintainerList ?? [];
162+
}
163+
else
164+
{
165+
MaintainerList.AddRange(model.MaintainerList ?? []);
166+
}
167+
168+
if (ReaderList == null || ReaderList.Count == 0)
169+
{
170+
ReaderList = model.ReaderList ?? [];
171+
}
172+
else
173+
{
174+
ReaderList.AddRange(model.ReaderList ?? []);
175+
}
176+
177+
if (ContributorList == null || ContributorList.Count == 0)
178+
{
179+
ContributorList = model.ContributorList ?? [];
180+
}
181+
else
182+
{
183+
ContributorList.AddRange(model.ContributorList ?? []);
184+
}
185+
186+
if (RemoveMemberList?.Count > 0)
187+
{
188+
foreach (var member in RemoveMemberList)
189+
{
190+
if (MaintainerList?.Contains(member) == true)
191+
{
192+
MaintainerList.Remove(member);
193+
}
194+
195+
if (ReaderList?.Contains(member) == true)
196+
{
197+
ReaderList.Remove(member);
198+
}
199+
200+
if (ContributorList?.Contains(member) == true)
201+
{
202+
ContributorList.Remove(member);
203+
}
204+
}
205+
}
206+
207+
if (RulesetList == null || RulesetList.Count == 0)
208+
{
209+
RulesetList = model.RulesetList ?? [];
210+
}
211+
212+
MaintainerList = MaintainerList?.Distinct().ToList();
213+
ReaderList = ReaderList?.Distinct().ToList();
214+
ContributorList = ContributorList?.Distinct().ToList();
215+
RulesetList = RulesetList?.Distinct().ToList();
216+
}
152217
}
153218
}

src/DevExcelerateApi/Parsers/GitHubIssueFormParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static ParsedBody ParseIssue(string? issue)
5656
public static bool IsEmptyResponse(string value)
5757
{
5858
return string.Equals(value, "_None_", StringComparison.OrdinalIgnoreCase) ||
59+
string.Equals(value, "None", StringComparison.Ordinal) ||
5960
string.Equals(value, "_No response_", StringComparison.OrdinalIgnoreCase) ||
6061
string.IsNullOrEmpty(value);
6162
}

src/DevExcelerateApi/Resources/Services.LocalizationService.fr.resx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@
153153
<data name="ERROR_REPO_TEAM_DOES_NOT_EXISTS" xml:space="preserve">
154154
<value>L'équipe ou le membre '{0}' n'existe pas.</value>
155155
</data>
156+
<data name="ERROR_REPO_DOES_NOT_EXIST" xml:space="preserve">
157+
<value>Le dépôt '{0}' n'existe pas.</value>
158+
</data>
159+
<data name="ERROR_USER_NOT_REPO_MAINTAINER" xml:space="preserve">
160+
<value>Seuls les responsables désignés du dépôt sont autorisés à mettre à jour le dépôt '{1}'. L'utilisateur '{0}' n'est pas un responsable.</value>
161+
</data>
156162
<data name="APPROVED" xml:space="preserve">
157163
<value>Approuvé</value>
158164
</data>
@@ -262,7 +268,7 @@
262268
<value>description_du_dépôt</value>
263269
</data>
264270
<data name="repository_maintainers" xml:space="preserve">
265-
<value>responsables_du_dépôt</value>
271+
<value>mainteneurs_du_dépôt</value>
266272
</data>
267273
<data name="repository_readers" xml:space="preserve">
268274
<value>lecteurs_du_dépôt</value>
@@ -283,9 +289,9 @@
283289
<value>Privé</value>
284290
</data>
285291
<data name="new_repository_name" xml:space="preserve">
286-
<value />
292+
<value>nouveau_nom_du_dépôt</value>
287293
</data>
288294
<data name="remove_repository_members" xml:space="preserve">
289-
<value />
295+
<value>retirer_des_membres_du_dépôt</value>
290296
</data>
291297
</root>

src/DevExcelerateApi/Resources/Services.LocalizationService.resx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,15 @@
149149
</data>
150150
<data name="ERROR_REPO_RULESET_DOES_NOT_EXISTS" xml:space="preserve">
151151
<value>The '{0}' ruleset does not exist. </value>
152-
</data>
153-
<data name="ERROR_REPO_TEAM_DOES_NOT_EXISTS" xml:space="preserve">
152+
</data> <data name="ERROR_REPO_TEAM_DOES_NOT_EXISTS" xml:space="preserve">
154153
<value>The '{0}' team or member does not exist.</value>
155154
</data>
155+
<data name="ERROR_REPO_DOES_NOT_EXIST" xml:space="preserve">
156+
<value>The repository '{0}' does not exist.</value>
157+
</data>
158+
<data name="ERROR_USER_NOT_REPO_MAINTAINER" xml:space="preserve">
159+
<value>Only designated repository maintainers have permission to update repository '{1}'. User '{0}' is not a maintainer.</value>
160+
</data>
156161
<data name="APPROVED" xml:space="preserve">
157162
<value>Approved</value>
158163
</data>

0 commit comments

Comments
 (0)