Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add and use lifetime controller #9

Merged
merged 3 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
run: dotnet test --no-build --verbosity normal
- name: Publish
run: dotnet publish -c Release --output /home/runner/work/Testably.Server/Testably.Server/publish/ Source/Testably.Server/Testably.Server.csproj
- name: Shutdown webpage
shell: pwsh
run: |
Invoke-WebRequest -Uri http://testably.com/lifetime/quit -Method POST
Start-Sleep -Seconds 5
- name: Upload ftp
uses: sebastianpopp/ftp-action@releases/v2
with:
Expand Down
17 changes: 17 additions & 0 deletions Source/Testably.Server/Controllers/LifetimeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Testably.Server.Controllers;

[ApiController]
[Route("lifetime")]
[AllowAnonymous]
public class LifetimeController(IHostApplicationLifetime applicationLifetime) : ControllerBase
{
[HttpPost("quit")]
public IActionResult Quit()
{
applicationLifetime.StopApplication();
return NoContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
return Ok("Ignore all events except 'pull_request'.");
}

_logger.LogInformation("Received {PullRequestWebhookModel}", pullRequestModel);

if (pullRequestModel.Payload.Repository.Private ||
pullRequestModel.Payload.Repository.Owner.Login != RepositoryOwner)
{
Expand All @@ -70,7 +68,7 @@
var bearerToken = _configuration.GetValue<string>("GithubBearerToken");
using var client = _clientFactory.CreateClient("Proxied");
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Testably",
Assembly.GetExecutingAssembly().GetName().Version.ToString()));

Check warning on line 71 in Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 71 in Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", bearerToken);

Expand All @@ -78,6 +76,7 @@
var repo = pullRequestModel.Payload.Repository.Name;
var prNumber = pullRequestModel.Payload.Number;
var requestUri = $"https://api.github.com/repos/{owner}/{repo}/pulls/{prNumber}";
_logger.LogInformation("Try reading '{RequestUri}'", requestUri);
var response = await client
.GetAsync(requestUri, cancellationToken);

Expand Down Expand Up @@ -108,6 +107,7 @@
}

var title = titleProperty.GetString()!;
_logger.LogInformation("Validate title for PR #{PullRequest}: '{Title}'", prNumber, title);
var commitSha = shaProperty.GetString();
var statusUri = $"https://api.github.com/repos/{owner}/{repo}/statuses/{commitSha}";
var hasValidTitle = ValidateTitle(title);
Expand Down
6 changes: 5 additions & 1 deletion Source/Testably.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ public static void Main(string[] args)

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
#if DEBUG
builder.Services.AddHttpClient("Proxied");
#else
// https://www.ionos.de/hilfe/index.php?id=4426
var webProxy = new WebProxy("http://winproxy.server.lan:3128");
// Add services to the container.
builder.Services.AddHttpClient("Proxied")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
{
Proxy = webProxy
});
#endif
builder.Services.AddRazorPages();
builder.Services.AddControllers()
.AddJsonOptions(o
Expand Down
Loading