dependabot-nuget 0.276.0 → 0.278.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +42 -0
  3. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +1 -0
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Run.cs +132 -0
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +11 -6
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/DependencyFinder.cs +2 -2
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +9 -4
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +2 -1
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/AllowedUpdate.cs +6 -0
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/CreatePullRequest.cs +18 -0
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyFile.cs +18 -0
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/IncrementMetric.cs +7 -0
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +49 -0
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobFile.cs +6 -0
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobSource.cs +11 -0
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/MarkAsProcessed.cs +9 -0
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/ReportedDependency.cs +16 -0
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/ReportedRequirement.cs +9 -0
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/RequirementSource.cs +7 -0
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/UpdatedDependencyList.cs +7 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/HttpApiHandler.cs +59 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/IApiHandler.cs +11 -0
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunResult.cs +13 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +283 -0
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/LockFileUpdater.cs +28 -0
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +16 -4
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +34 -0
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +223 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +60 -0
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/TestApiHandler.cs +35 -0
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs +69 -0
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/PathHelperTests.cs +22 -0
  33. data/lib/dependabot/nuget/file_fetcher.rb +17 -0
  34. metadata +29 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbad6797ed312b229980246a81f96e7820b511542f77e10c9eae64a1d6410955
4
- data.tar.gz: fd2d203b41a13ce9a5b5c9b9fe8054773bc1579efcb7a315a7721992d696bafb
3
+ metadata.gz: d29298584fd13989b51d63574bc462c199b1db8144a2a28b6c893ae90bf41dec
4
+ data.tar.gz: f2fc3a71de6471f5cca05fe294ce492bb4dbb1837ce2feb03bf40cfcec9ff4cb
5
5
  SHA512:
6
- metadata.gz: 362f0baccef540bfbbd899bcf3ff2415fd8db0b73aa712ca96d1b2c6f6521a5f1a57cc64c37c423337f92bfcaba87c156f1a6c9d3a394a344c77e7394410b73b
7
- data.tar.gz: 1f43136d55a7a4b2d5058ec80e71479e645de9ab4e9a37de4acab9808e2f5c09c577c18c39bb39cb6ba8ba9cf15b01df5e37ec1a30ccc50aba74227275138a7f
6
+ metadata.gz: 80ad942cbaf12ad2bec0eacf04124a26cb37b4a8f54cda4f3290f9a4b8c776f16a907cd963099634be43d925c64f0bef54ef5247632360954e9e28064bcda676
7
+ data.tar.gz: f413dfafd425032365e31d9c0969a94c6c8ac8195efe0de8b922ab464575fac246276012a6ceca8b1f9f55b10e3d8fb49d9cd5c4390f281674782a04a91b15ca
@@ -0,0 +1,42 @@
1
+ using System.CommandLine;
2
+
3
+ using NuGetUpdater.Core;
4
+ using NuGetUpdater.Core.Run;
5
+
6
+ namespace NuGetUpdater.Cli.Commands;
7
+
8
+ internal static class RunCommand
9
+ {
10
+ internal static readonly Option<FileInfo> JobPathOption = new("--job-path") { IsRequired = true };
11
+ internal static readonly Option<DirectoryInfo> RepoContentsPathOption = new("--repo-contents-path") { IsRequired = true };
12
+ internal static readonly Option<Uri> ApiUrlOption = new("--api-url") { IsRequired = true };
13
+ internal static readonly Option<string> JobIdOption = new("--job-id") { IsRequired = true };
14
+ internal static readonly Option<FileInfo> OutputPathOption = new("--output-path") { IsRequired = true };
15
+ internal static readonly Option<string> BaseCommitShaOption = new("--base-commit-sha") { IsRequired = true };
16
+ internal static readonly Option<bool> VerboseOption = new("--verbose", getDefaultValue: () => false);
17
+
18
+ internal static Command GetCommand(Action<int> setExitCode)
19
+ {
20
+ Command command = new("run", "Runs a full dependabot job.")
21
+ {
22
+ JobPathOption,
23
+ RepoContentsPathOption,
24
+ ApiUrlOption,
25
+ JobIdOption,
26
+ OutputPathOption,
27
+ BaseCommitShaOption,
28
+ VerboseOption
29
+ };
30
+
31
+ command.TreatUnmatchedTokensAsErrors = true;
32
+
33
+ command.SetHandler(async (jobPath, repoContentsPath, apiUrl, jobId, outputPath, baseCommitSha, verbose) =>
34
+ {
35
+ var apiHandler = new HttpApiHandler(apiUrl.ToString(), jobId);
36
+ var worker = new RunWorker(apiHandler, new Logger(verbose));
37
+ await worker.RunAsync(jobPath, repoContentsPath, baseCommitSha, outputPath);
38
+ }, JobPathOption, RepoContentsPathOption, ApiUrlOption, JobIdOption, OutputPathOption, BaseCommitShaOption, VerboseOption);
39
+
40
+ return command;
41
+ }
42
+ }
@@ -17,6 +17,7 @@ internal sealed class Program
17
17
  DiscoverCommand.GetCommand(setExitCode),
18
18
  AnalyzeCommand.GetCommand(setExitCode),
19
19
  UpdateCommand.GetCommand(setExitCode),
20
+ RunCommand.GetCommand(setExitCode),
20
21
  };
21
22
  command.TreatUnmatchedTokensAsErrors = true;
22
23
 
@@ -0,0 +1,132 @@
1
+ using System.Text;
2
+ using System.Text.Json;
3
+
4
+ using NuGetUpdater.Core.Run;
5
+ using NuGetUpdater.Core.Run.ApiModel;
6
+ using NuGetUpdater.Core.Test;
7
+ using NuGetUpdater.Core.Test.Update;
8
+
9
+ using Xunit;
10
+
11
+ namespace NuGetUpdater.Cli.Test;
12
+
13
+ using TestFile = (string Path, string Content);
14
+
15
+ public partial class EntryPointTests
16
+ {
17
+ public class Run
18
+ {
19
+ [Fact]
20
+ public async Task Run_Simple()
21
+ {
22
+ // verify we can pass command line arguments and hit the appropriate URLs
23
+ await RunAsync(
24
+ packages:
25
+ [
26
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"),
27
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0"),
28
+ ],
29
+ files:
30
+ [
31
+ ("src/project.csproj", """
32
+ <Project Sdk="Microsoft.NET.Sdk">
33
+ <PropertyGroup>
34
+ <TargetFramework>net8.0</TargetFramework>
35
+ </PropertyGroup>
36
+ <ItemGroup>
37
+ <PackageReference Include="Some.Package" Version="1.0.0" />
38
+ </ItemGroup>
39
+ </Project>
40
+ """)
41
+ ],
42
+ job: new Job()
43
+ {
44
+ PackageManager = "nuget",
45
+ AllowedUpdates = [
46
+ new()
47
+ {
48
+ UpdateType = "all"
49
+ }
50
+ ],
51
+ Source = new()
52
+ {
53
+ Provider = "github",
54
+ Repo = "test",
55
+ Directory = "src",
56
+ }
57
+ },
58
+ expectedUrls:
59
+ [
60
+ "/update_jobs/TEST-ID/update_dependency_list",
61
+ "/update_jobs/TEST-ID/increment_metric",
62
+ "/update_jobs/TEST-ID/create_pull_request",
63
+ "/update_jobs/TEST-ID/mark_as_processed",
64
+ ]
65
+ );
66
+ }
67
+
68
+ private static async Task RunAsync(TestFile[] files, Job job, string[] expectedUrls, MockNuGetPackage[]? packages = null)
69
+ {
70
+ using var tempDirectory = new TemporaryDirectory();
71
+
72
+ // write test files
73
+ foreach (var testFile in files)
74
+ {
75
+ var fullPath = Path.Join(tempDirectory.DirectoryPath, testFile.Path);
76
+ var directory = Path.GetDirectoryName(fullPath)!;
77
+ Directory.CreateDirectory(directory);
78
+ await File.WriteAllTextAsync(fullPath, testFile.Content);
79
+ }
80
+
81
+ // write job file
82
+ var jobPath = Path.Combine(tempDirectory.DirectoryPath, "job.json");
83
+ await File.WriteAllTextAsync(jobPath, JsonSerializer.Serialize(new { Job = job }, RunWorker.SerializerOptions));
84
+
85
+ // save packages
86
+ await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, tempDirectory.DirectoryPath);
87
+
88
+ var actualUrls = new List<string>();
89
+ using var http = TestHttpServer.CreateTestStringServer(url =>
90
+ {
91
+ actualUrls.Add(new Uri(url).PathAndQuery);
92
+ return (200, "ok");
93
+ });
94
+ var args = new List<string>()
95
+ {
96
+ "run",
97
+ "--job-path",
98
+ jobPath,
99
+ "--repo-contents-path",
100
+ tempDirectory.DirectoryPath,
101
+ "--api-url",
102
+ http.BaseUrl,
103
+ "--job-id",
104
+ "TEST-ID",
105
+ "--output-path",
106
+ Path.Combine(tempDirectory.DirectoryPath, "output.json"),
107
+ "--base-commit-sha",
108
+ "BASE-COMMIT-SHA",
109
+ "--verbose"
110
+ };
111
+
112
+ var output = new StringBuilder();
113
+ // redirect stdout
114
+ var originalOut = Console.Out;
115
+ Console.SetOut(new StringWriter(output));
116
+ int result = -1;
117
+ try
118
+ {
119
+ result = await Program.Main(args.ToArray());
120
+ }
121
+ catch
122
+ {
123
+ // restore stdout
124
+ Console.SetOut(originalOut);
125
+ throw;
126
+ }
127
+
128
+ Assert.True(result == 0, output.ToString());
129
+ Assert.Equal(expectedUrls, actualUrls);
130
+ }
131
+ }
132
+ }
@@ -33,6 +33,12 @@ public partial class AnalyzeWorker
33
33
  {
34
34
  var discovery = await DeserializeJsonFileAsync<WorkspaceDiscoveryResult>(discoveryPath, nameof(WorkspaceDiscoveryResult));
35
35
  var dependencyInfo = await DeserializeJsonFileAsync<DependencyInfo>(dependencyPath, nameof(DependencyInfo));
36
+ var analysisResult = await RunAsync(repoRoot, discovery, dependencyInfo);
37
+ await WriteResultsAsync(analysisDirectory, dependencyInfo.Name, analysisResult, _logger);
38
+ }
39
+
40
+ public async Task<AnalysisResult> RunAsync(string repoRoot, WorkspaceDiscoveryResult discovery, DependencyInfo dependencyInfo)
41
+ {
36
42
  var startingDirectory = PathHelper.JoinPath(repoRoot, discovery.Path);
37
43
 
38
44
  _logger.Log($"Starting analysis of {dependencyInfo.Name}...");
@@ -61,7 +67,7 @@ public partial class AnalyzeWorker
61
67
  bool isProjectUpdateNecessary = IsUpdateNecessary(dependencyInfo, projectsWithDependency);
62
68
  var isUpdateNecessary = isProjectUpdateNecessary || dotnetToolsHasDependency || globalJsonHasDependency;
63
69
  using var nugetContext = new NuGetContext(startingDirectory);
64
- AnalysisResult result;
70
+ AnalysisResult analysisResult;
65
71
  try
66
72
  {
67
73
  if (isUpdateNecessary)
@@ -134,7 +140,7 @@ public partial class AnalyzeWorker
134
140
  // should track the dependenciesToUpdate as they have already been analyzed.
135
141
  }
136
142
 
137
- result = new AnalysisResult
143
+ analysisResult = new AnalysisResult
138
144
  {
139
145
  UpdatedVersion = updatedVersion?.ToNormalizedString() ?? dependencyInfo.Version,
140
146
  CanUpdate = updatedVersion is not null,
@@ -146,7 +152,7 @@ public partial class AnalyzeWorker
146
152
  when (ex.StatusCode == HttpStatusCode.Unauthorized || ex.StatusCode == HttpStatusCode.Forbidden)
147
153
  {
148
154
  // TODO: consolidate this error handling between AnalyzeWorker, DiscoveryWorker, and UpdateWorker
149
- result = new AnalysisResult
155
+ analysisResult = new AnalysisResult
150
156
  {
151
157
  ErrorType = ErrorType.AuthenticationFailure,
152
158
  ErrorDetails = "(" + string.Join("|", nugetContext.PackageSources.Select(s => s.Source)) + ")",
@@ -156,9 +162,8 @@ public partial class AnalyzeWorker
156
162
  };
157
163
  }
158
164
 
159
- await WriteResultsAsync(analysisDirectory, dependencyInfo.Name, result, _logger);
160
-
161
165
  _logger.Log($"Analysis complete.");
166
+ return analysisResult;
162
167
  }
163
168
 
164
169
  private static bool IsUpdateNecessary(DependencyInfo dependencyInfo, ImmutableArray<ProjectDiscoveryResult> projectsWithDependency)
@@ -393,7 +398,7 @@ public partial class AnalyzeWorker
393
398
 
394
399
  // Create distinct list of dependencies taking the highest version of each
395
400
  var dependencyResult = await DependencyFinder.GetDependenciesAsync(
396
- workspacePath,
401
+ repoRoot,
397
402
  projectPath,
398
403
  projectFrameworks,
399
404
  packageIds,
@@ -8,7 +8,7 @@ namespace NuGetUpdater.Core.Analyze;
8
8
  internal static class DependencyFinder
9
9
  {
10
10
  public static async Task<ImmutableDictionary<NuGetFramework, ImmutableArray<Dependency>>> GetDependenciesAsync(
11
- string workspacePath,
11
+ string repoRoot,
12
12
  string projectPath,
13
13
  IEnumerable<NuGetFramework> frameworks,
14
14
  ImmutableHashSet<string> packageIds,
@@ -26,7 +26,7 @@ internal static class DependencyFinder
26
26
  foreach (var framework in frameworks)
27
27
  {
28
28
  var dependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(
29
- workspacePath,
29
+ repoRoot,
30
30
  projectPath,
31
31
  framework.ToString(),
32
32
  packages,
@@ -30,7 +30,7 @@ public partial class DiscoveryWorker
30
30
  _logger = logger;
31
31
  }
32
32
 
33
- public async Task RunAsync(string repoRootPath, string workspacePath, string outputPath)
33
+ public async Task<WorkspaceDiscoveryResult> RunAsync(string repoRootPath, string workspacePath)
34
34
  {
35
35
  MSBuildHelper.RegisterMSBuild(Environment.CurrentDirectory, repoRootPath);
36
36
 
@@ -102,11 +102,16 @@ public partial class DiscoveryWorker
102
102
  };
103
103
  }
104
104
 
105
- await WriteResultsAsync(repoRootPath, outputPath, result);
106
-
107
105
  _logger.Log("Discovery complete.");
108
-
109
106
  _processedProjectPaths.Clear();
107
+
108
+ return result;
109
+ }
110
+
111
+ public async Task RunAsync(string repoRootPath, string workspacePath, string outputPath)
112
+ {
113
+ var result = await RunAsync(repoRootPath, workspacePath);
114
+ await WriteResultsAsync(repoRootPath, outputPath, result);
110
115
  }
111
116
 
112
117
  /// <summary>
@@ -21,7 +21,8 @@
21
21
  </ItemGroup>
22
22
 
23
23
  <ItemGroup>
24
- <InternalsVisibleTo Include="NuGetUpdater.Core.Test"/>
24
+ <InternalsVisibleTo Include="NuGetUpdater.Cli.Test" />
25
+ <InternalsVisibleTo Include="NuGetUpdater.Core.Test" />
25
26
  </ItemGroup>
26
27
 
27
28
  </Project>
@@ -0,0 +1,6 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed record AllowedUpdate
4
+ {
5
+ public string UpdateType { get; init; } = "all";
6
+ }
@@ -0,0 +1,18 @@
1
+ using System.Text.Json.Serialization;
2
+
3
+ namespace NuGetUpdater.Core.Run.ApiModel;
4
+
5
+ public sealed record CreatePullRequest
6
+ {
7
+ public required ReportedDependency[] Dependencies { get; init; }
8
+ [JsonPropertyName("updated-dependency-files")]
9
+ public required DependencyFile[] UpdatedDependencyFiles { get; init; }
10
+ [JsonPropertyName("base-commit-sha")]
11
+ public required string BaseCommitSha { get; init; }
12
+ [JsonPropertyName("commit-message")]
13
+ public required string CommitMessage { get; init; }
14
+ [JsonPropertyName("pr-title")]
15
+ public required string PrTitle { get; init; }
16
+ [JsonPropertyName("pr-body")]
17
+ public required string PrBody { get; init; }
18
+ }
@@ -0,0 +1,18 @@
1
+ using System.Text.Json.Serialization;
2
+
3
+ namespace NuGetUpdater.Core.Run.ApiModel;
4
+
5
+ public sealed record DependencyFile
6
+ {
7
+ public required string Name { get; init; }
8
+ public required string Content { get; init; }
9
+ public required string Directory { get; init; }
10
+ public string Type { get; init; } = "file"; // TODO: enum
11
+ [JsonPropertyName("support_file")]
12
+ public bool SupportFile { get; init; } = false;
13
+ [JsonPropertyName("content_encoding")]
14
+ public string ContentEncoding { get; init; } = "utf-8";
15
+ public bool Deleted { get; init; } = false;
16
+ public string Operation { get; init; } = "update"; // TODO: enum
17
+ public string? Mode { get; init; } = null; // TODO: what is this?
18
+ }
@@ -0,0 +1,7 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed record IncrementMetric
4
+ {
5
+ public required string Metric { get; init; }
6
+ public Dictionary<string, string> Tags { get; init; } = new();
7
+ }
@@ -0,0 +1,49 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed record Job
4
+ {
5
+ public required string PackageManager { get; init; }
6
+ public AllowedUpdate[]? AllowedUpdates { get; init; } = null;
7
+ public bool Debug { get; init; } = false;
8
+ public object[]? DependencyGroups { get; init; } = null;
9
+ public object[]? Dependencies { get; init; } = null;
10
+ public string? DependencyGroupToRefresh { get; init; } = null;
11
+ public object[]? ExistingPullRequests { get; init; } = null;
12
+ public object[]? ExistingGroupPullRequests { get; init; } = null;
13
+ public Dictionary<string, object>? Experiments { get; init; } = null;
14
+ public object[]? IgnoreConditions { get; init; } = null;
15
+ public bool LockfileOnly { get; init; } = false;
16
+ public string? RequirementsUpdateStrategy { get; init; } = null;
17
+ public object[]? SecurityAdvisories { get; init; } = null;
18
+ public bool SecurityUpdatesOnly { get; init; } = false;
19
+ public required JobSource Source { get; init; }
20
+ public bool UpdateSubdependencies { get; init; } = false;
21
+ public bool UpdatingAPullRequest { get; init; } = false;
22
+ public bool VendorDependencies { get; init; } = false;
23
+ public bool RejectExternalCode { get; init; } = false;
24
+ public bool RepoPrivate { get; init; } = false;
25
+ public object? CommitMessageOptions { get; init; } = null;
26
+ public object[]? CredentialsMetadata { get; init; } = null;
27
+ public int MaxUpdaterRunTime { get; init; } = 0;
28
+
29
+ public IEnumerable<string> GetAllDirectories()
30
+ {
31
+ var returnedADirectory = false;
32
+ if (Source.Directory is not null)
33
+ {
34
+ returnedADirectory = true;
35
+ yield return Source.Directory;
36
+ }
37
+
38
+ foreach (var directory in Source.Directories ?? [])
39
+ {
40
+ returnedADirectory = true;
41
+ yield return directory;
42
+ }
43
+
44
+ if (!returnedADirectory)
45
+ {
46
+ yield return "/";
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,6 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed record JobFile
4
+ {
5
+ public required Job Job { get; init; }
6
+ }
@@ -0,0 +1,11 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed class JobSource
4
+ {
5
+ public required string Provider { get; init; }
6
+ public required string Repo { get; init; }
7
+ public string? Directory { get; init; } = null;
8
+ public string[]? Directories { get; init; } = null;
9
+ public string? Hostname { get; init; } = null;
10
+ public string? ApiEndpoint { get; init; } = null;
11
+ }
@@ -0,0 +1,9 @@
1
+ using System.Text.Json.Serialization;
2
+
3
+ namespace NuGetUpdater.Core.Run.ApiModel;
4
+
5
+ public sealed record MarkAsProcessed
6
+ {
7
+ [JsonPropertyName("base-commit-sha")]
8
+ public required string BaseCommitSha { get; init; }
9
+ }
@@ -0,0 +1,16 @@
1
+ using System.Text.Json.Serialization;
2
+
3
+ namespace NuGetUpdater.Core.Run.ApiModel;
4
+
5
+ public sealed record ReportedDependency
6
+ {
7
+ public required string Name { get; init; }
8
+ public required string? Version { get; init; }
9
+ public required ReportedRequirement[] Requirements { get; init; }
10
+ [JsonPropertyName("previous-version")]
11
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
12
+ public string? PreviousVersion { get; init; } = null;
13
+ [JsonPropertyName("previous-requirements")]
14
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
15
+ public ReportedRequirement[]? PreviousRequirements { get; init; } = null;
16
+ }
@@ -0,0 +1,9 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed record ReportedRequirement
4
+ {
5
+ public required string Requirement { get; init; }
6
+ public required string File { get; init; }
7
+ public string[] Groups { get; init; } = Array.Empty<string>();
8
+ public RequirementSource? Source { get; init; } = null;
9
+ }
@@ -0,0 +1,7 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed record RequirementSource
4
+ {
5
+ public required string? SourceUrl { get; init; }
6
+ public string Type { get; init; } = "nuget_repo";
7
+ }
@@ -0,0 +1,7 @@
1
+ namespace NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ public sealed record UpdatedDependencyList
4
+ {
5
+ public required ReportedDependency[] Dependencies { get; init; }
6
+ public required string[] DependencyFiles { get; init; }
7
+ }
@@ -0,0 +1,59 @@
1
+ using System.Text;
2
+ using System.Text.Json;
3
+ using System.Text.Json.Serialization;
4
+
5
+ using NuGetUpdater.Core.Run.ApiModel;
6
+
7
+ namespace NuGetUpdater.Core.Run;
8
+
9
+ public class HttpApiHandler : IApiHandler
10
+ {
11
+ private static readonly HttpClient HttpClient = new();
12
+
13
+ public static readonly JsonSerializerOptions SerializerOptions = new()
14
+ {
15
+ PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
16
+ Converters = { new JsonStringEnumConverter() },
17
+ };
18
+
19
+ private readonly string _apiUrl;
20
+ private readonly string _jobId;
21
+
22
+ public HttpApiHandler(string apiUrl, string jobId)
23
+ {
24
+ _apiUrl = apiUrl.TrimEnd('/');
25
+ _jobId = jobId;
26
+ }
27
+
28
+ public async Task UpdateDependencyList(UpdatedDependencyList updatedDependencyList)
29
+ {
30
+ await PostAsJson("update_dependency_list", updatedDependencyList);
31
+ }
32
+
33
+ public async Task IncrementMetric(IncrementMetric incrementMetric)
34
+ {
35
+ await PostAsJson("increment_metric", incrementMetric);
36
+ }
37
+
38
+ public async Task CreatePullRequest(CreatePullRequest createPullRequest)
39
+ {
40
+ await PostAsJson("create_pull_request", createPullRequest);
41
+ }
42
+
43
+ public async Task MarkAsProcessed(MarkAsProcessed markAsProcessed)
44
+ {
45
+ await PostAsJson("mark_as_processed", markAsProcessed);
46
+ }
47
+
48
+ private async Task PostAsJson(string endpoint, object body)
49
+ {
50
+ var wrappedBody = new
51
+ {
52
+ Data = body,
53
+ };
54
+ var payload = JsonSerializer.Serialize(wrappedBody, SerializerOptions);
55
+ var content = new StringContent(payload, Encoding.UTF8, "application/json");
56
+ var response = await HttpClient.PostAsync($"{_apiUrl}/update_jobs/{_jobId}/{endpoint}", content);
57
+ var _ = response.EnsureSuccessStatusCode();
58
+ }
59
+ }
@@ -0,0 +1,11 @@
1
+ using NuGetUpdater.Core.Run.ApiModel;
2
+
3
+ namespace NuGetUpdater.Core.Run;
4
+
5
+ public interface IApiHandler
6
+ {
7
+ Task UpdateDependencyList(UpdatedDependencyList updatedDependencyList);
8
+ Task IncrementMetric(IncrementMetric incrementMetric);
9
+ Task CreatePullRequest(CreatePullRequest createPullRequest);
10
+ Task MarkAsProcessed(MarkAsProcessed markAsProcessed);
11
+ }
@@ -0,0 +1,13 @@
1
+ using System.Text.Json.Serialization;
2
+
3
+ using NuGetUpdater.Core.Run.ApiModel;
4
+
5
+ namespace NuGetUpdater.Core.Run;
6
+
7
+ public sealed record RunResult
8
+ {
9
+ [JsonPropertyName("base64_dependency_files")]
10
+ public required DependencyFile[] Base64DependencyFiles { get; init; }
11
+ [JsonPropertyName("base_commit_sha")]
12
+ public required string BaseCommitSha { get; init; }
13
+ }