diff --git a/server/Tingle.Dependabot.Tests/Workflow/UpdateRunnerTests.cs b/server/Tingle.Dependabot.Tests/Workflow/UpdateRunnerTests.cs index 890a1253..899ef754 100644 --- a/server/Tingle.Dependabot.Tests/Workflow/UpdateRunnerTests.cs +++ b/server/Tingle.Dependabot.Tests/Workflow/UpdateRunnerTests.cs @@ -29,7 +29,6 @@ public void MakeExtraCredentials_Works_1() var configuration = deserializer.Deserialize(reader); Assert.NotNull(configuration); var registries = UpdateRunner.MakeExtraCredentials(configuration.Registries.Values, new Dictionary()); - Assert.NotNull(registries); Assert.Equal(11, registries.Count); // composer-repository diff --git a/server/Tingle.Dependabot/Models/UpdateJobResponse.cs b/server/Tingle.Dependabot/Models/UpdateJobResponse.cs index 0ab27e3e..aee056f3 100644 --- a/server/Tingle.Dependabot/Models/UpdateJobResponse.cs +++ b/server/Tingle.Dependabot/Models/UpdateJobResponse.cs @@ -7,12 +7,8 @@ namespace Tingle.Dependabot.Models; public sealed record UpdateJobResponse(UpdateJobData Data); public sealed record UpdateJobData(UpdateJobAttributes Attributes); -public sealed record UpdateJobAttributes() +public sealed class UpdateJobAttributes { - public UpdateJobAttributes(UpdateJob job) : this() - { - } - [JsonPropertyName("allowed-updates")] public required IEnumerable AllowedUpdates { get; set; } @@ -65,7 +61,7 @@ public UpdateJobAttributes(UpdateJob job) : this() public bool? Debug { get; set; } } -public sealed record UpdateJobAttributesSource +public sealed class UpdateJobAttributesSource { [JsonPropertyName("provider")] public required string Provider { get; set; } diff --git a/server/Tingle.Dependabot/Workflow/UpdateRunner.cs b/server/Tingle.Dependabot/Workflow/UpdateRunner.cs index bec03032..adf2c0c9 100644 --- a/server/Tingle.Dependabot/Workflow/UpdateRunner.cs +++ b/server/Tingle.Dependabot/Workflow/UpdateRunner.cs @@ -206,31 +206,36 @@ internal IDictionary CreateVariables(Repository repository, Repo { static string? ToJson(T? entries) => entries is null ? null : JsonSerializer.Serialize(entries, serializerOptions); // null ensures we do not add to the values - var jobDirectory = Path.Join(options.WorkingDirectory, job.Id); + // Prepare extra credentials with replaced secrets + var secrets = new Dictionary(options.Secrets) { ["DEFAULT_TOKEN"] = options.ProjectToken!, }; + var registries = update.Registries?.Select(r => repository.Registries[r]).ToList(); + var credentials = ToJson(MakeExtraCredentials(registries, secrets)); // add source credentials when running the in v2 - // TODO: write the job definition file (find out if it is YAML/JSON) + var jobDirectory = Path.Join(options.WorkingDirectory, job.Id); - // var attr = new UpdateJobAttributes(job) + //var attr = new UpdateJobAttributes + //{ + // AllowedUpdates = Array.Empty(), + // CredentialsMetadata = Array.Empty(), + // Dependencies = Array.Empty(), + // Directory = job.Directory!, + // ExistingPullRequests = Array.Empty(), + // IgnoreConditions = Array.Empty(), + // PackageManager = job.PackageEcosystem!, + // RepoName = job.RepositorySlug!, + // SecurityAdvisories = Array.Empty(), + // Source = new UpdateJobAttributesSource // { - // AllowedUpdates = Array.Empty(), - // CredentialsMetadata = Array.Empty(), - // Dependencies = Array.Empty(), // Directory = job.Directory!, - // ExistingPullRequests = Array.Empty(), - // IgnoreConditions = Array.Empty(), - // PackageManager = job.PackageEcosystem, - // RepoName = job.RepositorySlug!, - // SecurityAdvisories = Array.Empty(), - // Source = new UpdateJobAttributesSource - // { - // Directory = job.Directory!, - // Provider = "azure", - // Repo = job.RepositorySlug!, - // Branch = job.Branch, - // Hostname = , - // ApiEndpoint =, - // }, - // }; + // Provider = "azure", + // Repo = job.RepositorySlug!, + // Branch = update.TargetBranch, + // Hostname = , + // ApiEndpoint =, + // }, + //}; + + // TODO: write the job definition file (find out if it is YAML/JSON) // Add compulsory values var values = new Dictionary @@ -243,6 +248,8 @@ internal IDictionary CreateVariables(Repository repository, Repo ["DEPENDABOT_PACKAGE_MANAGER"] = job.PackageEcosystem!, ["DEPENDABOT_DIRECTORY"] = update.Directory!, ["DEPENDABOT_OPEN_PULL_REQUESTS_LIMIT"] = update.OpenPullRequestsLimit!.Value.ToString(), + + ["DEPENDABOT_EXTRA_CREDENTIALS"] = credentials!, }; // Add optional values @@ -264,8 +271,6 @@ internal IDictionary CreateVariables(Repository repository, Repo .AddIfNotDefault("DEPENDABOT_MILESTONE", update.Milestone?.ToString()) .AddIfNotDefault("DEPENDABOT_FAIL_ON_EXCEPTION", options.FailOnException.ToString().ToLowerInvariant()); - var secrets = new Dictionary(options.Secrets) { ["DEFAULT_TOKEN"] = options.ProjectToken!, }; - // Add values for Azure DevOps var url = options.ProjectUrl!.Value; values.AddIfNotDefault("AZURE_HOSTNAME", url.Hostname) @@ -278,15 +283,13 @@ internal IDictionary CreateVariables(Repository repository, Repo .AddIfNotDefault("AZURE_MERGE_STRATEGY", options.AutoCompleteMergeStrategy?.ToString()) .AddIfNotDefault("AZURE_AUTO_APPROVE_PR", (options.AutoApprove ?? false).ToString().ToLowerInvariant()); - // Add extra credentials with replaced secrets - var registries = update.Registries?.Select(r => repository.Registries[r]).ToList(); - values.AddIfNotDefault("DEPENDABOT_EXTRA_CREDENTIALS", ToJson(MakeExtraCredentials(registries, secrets))); - return values; } - internal static IList>? MakeExtraCredentials(ICollection? registries, IDictionary secrets) + internal static IList> MakeExtraCredentials(ICollection? registries, IDictionary secrets) { - return registries?.Select(v => + if (registries is null) return Array.Empty>(); + + return registries.Select(v => { var type = v.Type?.Replace("-", "_") ?? throw new InvalidOperationException("Type should not be null");