Skip to content

Commit

Permalink
add new all workflows view for runner client (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored Sep 16, 2023
1 parent b04e09f commit d94e60b
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 53 deletions.
3 changes: 2 additions & 1 deletion src/Runner.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,8 @@ static int Main(string[] args)
GITHUB_TOKEN = "",
ReturnWithoutResolvingSha = false,
}
}.ToList()
}.ToList(),
DefaultWebUIView = "allworkflows"
};
if(parameters.GitHubConnect) {
rsconfig.ActionDownloadUrls.Add(new {
Expand Down
9 changes: 7 additions & 2 deletions src/Runner.Server/Controllers/MessageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ private HookResponse ConvertYaml(string fileRelativePath, string content, string
run.Ref = _attempt.Ref;
run.Sha = _attempt.Sha;
run.EventName = _attempt.EventName;
run.Owner = owner_name;
run.Repo = repo_name;
Task.Run(() => runevent?.Invoke(owner_name, repo_name, run));
workflowrun?.Invoke(run.Id);
var runid = run.Id;
Expand Down Expand Up @@ -803,6 +805,8 @@ private HookResponse ConvertYamlAzure(string fileRelativePath, string content, s
run.Ref = _attempt.Ref;
run.Sha = _attempt.Sha;
run.EventName = _attempt.EventName;
run.Owner = owner_name;
run.Repo = repo_name;
Task.Run(() => runevent?.Invoke(owner_name, repo_name, run));
workflowrun?.Invoke(run.Id);
var runid = run.Id;
Expand Down Expand Up @@ -2980,6 +2984,8 @@ private static void UpdateWorkflowRun(WorkflowRunAttempt attempt, string reposit
attempt.WorkflowRun.Sha = attempt.Sha;
attempt.WorkflowRun.EventName = attempt.EventName;
var ownerAndRepo = repository_name.Split("/", 2);
attempt.WorkflowRun.Owner = ownerAndRepo[0];
attempt.WorkflowRun.Repo = ownerAndRepo[1];
Task.Run(() => runupdateevent?.Invoke(ownerAndRepo[0], ownerAndRepo[1], attempt.WorkflowRun));
}

Expand Down Expand Up @@ -7242,8 +7248,7 @@ public async Task<IActionResult> GetRepositories([FromQuery] int? page, [FromQue

[HttpGet("workflow/runs")]
public async Task<IActionResult> GetWorkflows([FromQuery] int? page, [FromQuery] string owner, [FromQuery] string repo) {
//var query = (from j in _context.Set<WorkflowRun>() where j.Workflow.Repository.Owner.Name.ToLower() == owner.ToLower() && j.Workflow.Repository.Name.ToLower() == repo.ToLower() orderby j.WorkflowRun.Id descending select j).Select(g => new WorkflowRun() { EventName = from _context.Set<WorkflowRunAttempt>() .EventName, Ref = g.Last().Ref, Sha = g.Last().Sha, Result = g.Last().Result, FileName = g.Last().WorkflowRun.FileName, DisplayName = g.Last().WorkflowRun.DisplayName, Id = g.Last().WorkflowRun.Id});
var query = (from run in _context.Set<WorkflowRun>() from attempt in _context.Set<WorkflowRunAttempt>() where run.Id == attempt.WorkflowRun.Id && attempt.Attempt == (from a in _context.Set<WorkflowRunAttempt>() where run.Id == a.WorkflowRun.Id orderby a.Attempt descending select a.Attempt).First() && run.Workflow.Repository.Owner.Name.ToLower() == owner.ToLower() && run.Workflow.Repository.Name.ToLower() == repo.ToLower() orderby run.Id descending select new WorkflowRun() { EventName = attempt.EventName, Ref = attempt.Ref, Sha = attempt.Sha, Result = attempt.Result, FileName = run.FileName, DisplayName = run.DisplayName, Id = run.Id});
var query = (from run in _context.Set<WorkflowRun>() from attempt in _context.Set<WorkflowRunAttempt>() where run.Id == attempt.WorkflowRun.Id && attempt.Attempt == (from a in _context.Set<WorkflowRunAttempt>() where run.Id == a.WorkflowRun.Id orderby a.Attempt descending select a.Attempt).First() && (string.IsNullOrEmpty(owner) || run.Workflow.Repository.Owner.Name.ToLower() == owner.ToLower()) && (string.IsNullOrEmpty(repo) || run.Workflow.Repository.Name.ToLower() == repo.ToLower()) orderby run.Id descending select new WorkflowRun() { EventName = attempt.EventName, Ref = attempt.Ref, Sha = attempt.Sha, Result = attempt.Result, FileName = run.FileName, DisplayName = run.DisplayName, Id = run.Id, Owner = run.Workflow.Repository.Owner.Name, Repo = run.Workflow.Repository.Name});
return await Ok(page.HasValue ? query.Skip(page.Value * 30).Take(30) : query, true);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Runner.Server/Models/WorkflowRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ public class WorkflowRun {
public String Sha { get; set; }
[NotMapped]
public TaskResult? Result { get; set; }
[NotMapped]
public String Owner { get; set; }
[NotMapped]
public String Repo { get; set; }
}
}
33 changes: 33 additions & 0 deletions src/Runner.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
using Quartz;
using Microsoft.Data.Sqlite;
using System.Reflection;
using Microsoft.AspNetCore.Rewrite;
using System.Net;
using Microsoft.Net.Http.Headers;

namespace Runner.Server
{
Expand Down Expand Up @@ -378,11 +381,41 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApp
endpoints.MapControllers();
});

var defaultWebUIView = Configuration.GetSection("Runner.Server")?.GetValue<string>("DefaultWebUIView");
if(!string.IsNullOrEmpty(defaultWebUIView)) {
var rewriteOptions = new RewriteOptions();
rewriteOptions.Rules.Add(new AllWorlflowsRedirect(defaultWebUIView));
app.UseRewriter(rewriteOptions);
}

DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
}
}

internal class AllWorlflowsRedirect : IRule
{
public AllWorlflowsRedirect(string defaultWebUIView) {
DefaultWebUIView = defaultWebUIView;
}

public string DefaultWebUIView { get; }

public void ApplyRule(RewriteContext context)
{
var request = context.HttpContext.Request;
if (request.Path.Value == null || request.Query.ContainsKey("view") || request.Path != "/")
{
return;
}

var response = context.HttpContext.Response;
response.StatusCode = (int) HttpStatusCode.Moved;
context.Result = RuleResult.EndResponse;
response.Headers[HeaderNames.Location] = "/" + request.QueryString.Add("view", DefaultWebUIView);
}
}
}
Loading

0 comments on commit d94e60b

Please sign in to comment.