Skip to content

Commit

Permalink
fix: format of webhooks (#10)
Browse files Browse the repository at this point in the history
* Fix build pipeline
* Continue on error
* Sleep only when successful
* Fix webhook format
  • Loading branch information
vbreuss authored Mar 30, 2024
1 parent b3415bb commit 22d484e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 77 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ jobs:
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
continue-on-error: true
run: |
Invoke-WebRequest -Uri http://testably.com/lifetime/quit -Method POST
Start-Sleep -Seconds 5
try {
(Invoke-WebRequest -Uri https://testably.org/lifetime/quit -Method POST -ErrorAction Stop).BaseResponse
Write-Information "The server was shutdown"
Start-Sleep -Seconds 5
} catch [System.Net.WebException] {
Write-Warning "An exception was caught: $($_.Exception.Message)"
}
- name: Upload ftp
uses: sebastianpopp/ftp-action@releases/v2
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ public PullRequestStatusCheckController(

[HttpPost]
public async Task<IActionResult> OnPullRequestChanged(
[FromBody] WebhookModel<PullRequestWebhookModel> pullRequestModel,
[FromBody] PullRequestWebhookModel pullRequestModel,
CancellationToken cancellationToken)
{
if (pullRequestModel.Event != "pull_request")
if (!HttpContext.Request.Headers.TryGetValue("x-github-event", out var value) ||
value != "pull_request")
{
return Ok("Ignore all events except 'pull_request'.");
}

if (pullRequestModel.Payload.Repository.Private ||
pullRequestModel.Payload.Repository.Owner.Login != RepositoryOwner)
if (pullRequestModel.Repository.Private ||
pullRequestModel.Repository.Owner.Login != RepositoryOwner)
{
return BadRequest($"Only public repositories from '{RepositoryOwner}' are supported!");
}
Expand All @@ -72,9 +73,9 @@ public async Task<IActionResult> OnPullRequestChanged(
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", bearerToken);

var owner = pullRequestModel.Payload.Repository.Owner.Login;
var repo = pullRequestModel.Payload.Repository.Name;
var prNumber = pullRequestModel.Payload.Number;
var owner = pullRequestModel.Repository.Owner.Login;
var repo = pullRequestModel.Repository.Name;
var prNumber = pullRequestModel.Number;
var requestUri = $"https://api.github.com/repos/{owner}/{repo}/pulls/{prNumber}";
_logger.LogInformation("Try reading '{RequestUri}'", requestUri);
var response = await client
Expand Down
Loading

0 comments on commit 22d484e

Please sign in to comment.