-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Updater login into separate class.
Move various enums and interfaces to organized subdirectories under Models and Interfaces namespaces. Extract the update logic from the Program class into a new, dedicated Updater class to improve code modularity and maintainability. Also, update affected import statements accordingly.
- Loading branch information
Showing
17 changed files
with
109 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...DependencyUpdated.Core/IProjectUpdater.cs → ...pdated.Core/Interfaces/IProjectUpdater.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...ndencyUpdated.Core/IRepositoryProvider.cs → ...ed.Core/Interfaces/IRepositoryProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pendencyUpdated.Core/DependencyDetails.cs → ...yUpdated.Core/Models/DependencyDetails.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
namespace DependencyUpdated.Core; | ||
namespace DependencyUpdated.Core.Models; | ||
|
||
public record DependencyDetails(string Name, Version Version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace DependencyUpdated.Core.Models.Enums; | ||
|
||
public enum ProjectType | ||
{ | ||
DotNet = 1, | ||
} |
2 changes: 1 addition & 1 deletion
2
src/DependencyUpdated.Core/RepositoryType.cs → ...dated.Core/Models/Enums/RepositoryType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace DependencyUpdated.Core; | ||
namespace DependencyUpdated.Core.Models.Enums; | ||
|
||
public enum RepositoryType | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
...pendencyUpdated.Core/VersionUpdateType.cs → ...ed.Core/Models/Enums/VersionUpdateType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/DependencyUpdated.Core/UpdateResult.cs → ...ndencyUpdated.Core/Models/UpdateResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
namespace DependencyUpdated.Core; | ||
namespace DependencyUpdated.Core.Models; | ||
|
||
public record UpdateResult(string PackageName, string OldVersion, string NewVersion); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using DependencyUpdated.Core.Config; | ||
using DependencyUpdated.Core.Interfaces; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using System.IO.Enumeration; | ||
|
||
namespace DependencyUpdated.Core; | ||
|
||
public sealed class Updater(IServiceProvider serviceProvider, IOptions<UpdaterConfig> config) | ||
{ | ||
public async Task DoUpdate() | ||
{ | ||
var repositoryProvider = | ||
serviceProvider.GetRequiredKeyedService<IRepositoryProvider>(config.Value.RepositoryType); | ||
var repositoryPath = Environment.CurrentDirectory; | ||
repositoryProvider.SwitchToDefaultBranch(repositoryPath); | ||
|
||
foreach (var configEntry in config.Value.Projects) | ||
{ | ||
var updater = serviceProvider.GetRequiredKeyedService<IProjectUpdater>(configEntry.Type); | ||
|
||
foreach (var directory in configEntry.Directories) | ||
{ | ||
if (!Path.Exists(directory)) | ||
{ | ||
throw new FileNotFoundException("Search path not found", directory); | ||
} | ||
|
||
var projectFiles = updater.GetAllProjectFiles(directory); | ||
var allDependenciesToUpdate = | ||
await updater.ExtractAllPackagesThatNeedToBeUpdated(projectFiles, configEntry); | ||
|
||
if (allDependenciesToUpdate.Count == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
var uniqueListOfDependencies = allDependenciesToUpdate.DistinctBy(x => x.Name).ToList(); | ||
var projectName = ResolveProjectName(configEntry, directory); | ||
foreach (var group in configEntry.Groups) | ||
{ | ||
var matchesForGroup = uniqueListOfDependencies | ||
.Where(x => FileSystemName.MatchesSimpleExpression(group, x.Name)).ToArray(); | ||
if (matchesForGroup.Length == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
uniqueListOfDependencies.RemoveAll(x => FileSystemName.MatchesSimpleExpression(group, x.Name)); | ||
repositoryProvider.SwitchToUpdateBranch(repositoryPath, projectName, group); | ||
|
||
var allUpdates = updater.HandleProjectUpdate(projectFiles, matchesForGroup); | ||
if (allUpdates.Count == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
repositoryProvider.CommitChanges(repositoryPath, projectName, group); | ||
await repositoryProvider.SubmitPullRequest(allUpdates.DistinctBy(x => x.PackageName).ToArray(), | ||
projectName, group); | ||
repositoryProvider.SwitchToDefaultBranch(repositoryPath); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static string ResolveProjectName(Project project, string directory) | ||
{ | ||
if (!project.EachDirectoryAsSeparate) | ||
{ | ||
return project.Name; | ||
} | ||
|
||
return Path.GetFileName(directory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/DependencyUpdated.Repositories.AzureDevOps/ConfigureServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
tests/DependencyUpdated.Projects.DotNet.UnitTests/DotNetUpdaterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters