Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ public sealed record TagPushed(string Tag, string CommitSha) : GitWebhookEvent;
/// <param name="Number">The pull request number.</param>
/// <param name="SourceReference">The source branch.</param>
/// <param name="TargetReference">The target branch.</param>
/// <param name="SourceHeadSha">
/// The head commit SHA of the source branch, when the provider reports it —
/// CI/CD consumers need it to build or deploy the exact proposed revision.
/// </param>
public sealed record PullRequestChanged(
string Action,
int Number,
string SourceReference,
string TargetReference) : GitWebhookEvent;
string TargetReference,
string? SourceHeadSha = null) : GitWebhookEvent;

/// <summary>
/// A pipeline run reached a terminal state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ private static GitWebhookEvent TranslatePullRequest(JsonElement root, string del
var pr = GetProperty(root, "pull_request");
var action = GetString(root, "action") ?? string.Empty;
var number = GetInt(root, "number") ?? GetInt(pr, "number") ?? 0;
var source = GetString(GetProperty(pr, "head"), "ref") ?? string.Empty;
var head = GetProperty(pr, "head");
var source = GetString(head, "ref") ?? string.Empty;
var targetRef = GetString(GetProperty(pr, "base"), "ref") ?? string.Empty;
var headSha = GetString(head, "sha");

return new GitWebhookEvent.PullRequestChanged(action, number, source, targetRef)
return new GitWebhookEvent.PullRequestChanged(action, number, source, targetRef, headSha)
{
DeliveryId = deliveryId,
Repository = repository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void Parse_TagPush_ProducesATagPushedEvent()
public void Parse_PullRequest_ProducesAPullRequestChangedEvent()
{
var body = """
{"action":"opened","number":42,"pull_request":{"head":{"ref":"feature"},"base":{"ref":"main"}},
{"action":"opened","number":42,"pull_request":{"head":{"ref":"feature","sha":"headsha42"},"base":{"ref":"main"}},
"repository":{"full_name":"acme/billing"}}
""";

Expand All @@ -106,6 +106,21 @@ public void Parse_PullRequest_ProducesAPullRequestChangedEvent()
pr.Number.Should().Be(42);
pr.SourceReference.Should().Be("feature");
pr.TargetReference.Should().Be("main");
pr.SourceHeadSha.Should().Be("headsha42");
}

[Fact]
public void Parse_PullRequestWithoutHeadSha_LeavesSourceHeadShaNull()
{
var body = """
{"action":"opened","number":7,"pull_request":{"head":{"ref":"feature"},"base":{"ref":"main"}},
"repository":{"full_name":"acme/billing"}}
""";

var result = _ingestor.Parse(Delivery("pull_request", body), Secret);

var pr = result.Value.Should().BeOfType<GitWebhookEvent.PullRequestChanged>().Subject;
pr.SourceHeadSha.Should().BeNull();
}

[Fact]
Expand Down
Loading