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

fix: format of webhooks #10

Merged
merged 5 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
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 @@

[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 @@ -68,13 +69,13 @@
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 72 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 72 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);

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
Loading