Skip to content

Commit

Permalink
Fix IFileProvider Namespace (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored May 25, 2024
1 parent 617cc49 commit 19ce783
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Runner.Server/Controllers/MessageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3162,7 +3162,7 @@ private HookResponse AzureDevopsMain(string fileRelativePath, string content, st
workflowContext.Flags = flags;
List<JobItem> jobgroup = new List<JobItem>();
List<JobItem> dependentjobgroup = new List<JobItem>();
var fileProvider = new DefaultInMemoryFileProviderFileProvider(workflows, (a, b) => {
var fileProvider = new Azure.Devops.DefaultInMemoryFileProviderFileProvider(workflows, (a, b) => {
return TryGetFile(runid, a, out var content, b) ? content : null;
});
var rootVariables = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Expand Down
11 changes: 7 additions & 4 deletions src/Sdk/AzurePipelines/DefaultFileProvider.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Threading.Tasks;

public class DefaultFileProvider : IFileProvider
{
public Task<string> ReadFile(string repositoryAndRef, string path)
namespace Runner.Server.Azure.Devops {

public class DefaultFileProvider : IFileProvider
{
return Task.FromResult(System.IO.File.ReadAllText(path));
public Task<string> ReadFile(string repositoryAndRef, string path)
{
return Task.FromResult(System.IO.File.ReadAllText(path));
}
}
}
7 changes: 5 additions & 2 deletions src/Sdk/AzurePipelines/IFileProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Threading.Tasks;

public interface IFileProvider {
Task<string> ReadFile(string repositoryAndRef, string path);
namespace Runner.Server.Azure.Devops {

public interface IFileProvider {
Task<string> ReadFile(string repositoryAndRef, string path);
}
}
33 changes: 18 additions & 15 deletions src/Sdk/AzurePipelines/InMemoryFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
using System;
using System.Threading.Tasks;

public class DefaultInMemoryFileProviderFileProvider : IFileProvider
{
public DefaultInMemoryFileProviderFileProvider(KeyValuePair<string, string>[] workflows, Func<string, string, string> readFile = null) {
Workflows = workflows.ToDictionary(kv => kv.Key, kv => kv.Value);
this.readFile = readFile;
}

private Func<string, string, string> readFile;
public Dictionary<string, string> Workflows { get; private set; }
namespace Runner.Server.Azure.Devops {

public Task<string> ReadFile(string repositoryAndRef, string path)
public class DefaultInMemoryFileProviderFileProvider : IFileProvider
{
if(repositoryAndRef == null && Workflows.TryGetValue(path, out var content)) {
return Task.FromResult(content);
} else if(readFile != null) {
return Task.FromResult(readFile(path, repositoryAndRef));
public DefaultInMemoryFileProviderFileProvider(KeyValuePair<string, string>[] workflows, Func<string, string, string> readFile = null) {
Workflows = workflows.ToDictionary(kv => kv.Key, kv => kv.Value);
this.readFile = readFile;
}

private Func<string, string, string> readFile;
public Dictionary<string, string> Workflows { get; private set; }

public Task<string> ReadFile(string repositoryAndRef, string path)
{
if(repositoryAndRef == null && Workflows.TryGetValue(path, out var content)) {
return Task.FromResult(content);
} else if(readFile != null) {
return Task.FromResult(readFile(path, repositoryAndRef));
}
return Task.FromResult<string>(null);
}
return Task.FromResult<string>(null);
}
}

0 comments on commit 19ce783

Please sign in to comment.