Skip to content

Commit 0fcb68d

Browse files
authored
Require pr:declined webhook event with fixture and parser test (#58)
1 parent 536186e commit 0fcb68d

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

scripts/bitbucket_onboarding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"pr:reviewer:needs_work",
8080
"pr:reviewer:updated",
8181
"pr:merged",
82+
"pr:declined",
8283
"pr:deleted",
8384
"repo:refs_changed",
8485
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"eventKey": "pr:declined",
3+
"date": "2026-04-28T10:00:00+0000",
4+
"actor": {
5+
"name": "alice",
6+
"displayName": "Alice Example",
7+
"slug": "alice"
8+
},
9+
"pullRequest": {
10+
"id": 42,
11+
"title": "ABC-123: Add payment retry",
12+
"description": "Fixes ABC-123 and PROJ-9",
13+
"state": "DECLINED",
14+
"closed": true,
15+
"closedDate": 1777370400000,
16+
"fromRef": {
17+
"id": "refs/heads/feature/ABC-123-retries",
18+
"displayId": "feature/ABC-123-retries",
19+
"latestCommit": "abc1234567890abc1234567890abc1234567890a",
20+
"repository": {
21+
"slug": "payments-api",
22+
"project": {"key": "ACME"}
23+
}
24+
},
25+
"toRef": {
26+
"id": "refs/heads/master",
27+
"displayId": "master",
28+
"latestCommit": "0000000000000000000000000000000000000000",
29+
"repository": {
30+
"slug": "payments-api",
31+
"project": {"key": "ACME"}
32+
}
33+
},
34+
"author": {
35+
"user": {
36+
"name": "alice",
37+
"displayName": "Alice Example",
38+
"slug": "alice"
39+
}
40+
}
41+
}
42+
}

tests/test_parsers_bitbucket.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,37 @@ def test_revert_pr_title_marks_is_revert(self) -> None:
5757
assert result.is_revert is True
5858

5959

60+
class TestExtractPrDeclined:
61+
def test_pr_declined_fixture_returns_draft_with_lowercased_join_keys(self) -> None:
62+
# Given
63+
body = _load("bitbucket_pr_declined.json")
64+
65+
# When
66+
result = extract_event(
67+
body,
68+
x_event_key="pr:declined",
69+
x_request_uuid="req-decl",
70+
x_hook_uuid=None,
71+
)
72+
73+
# Then — declined-PRs share the merged payload shape; the parser
74+
# must persist them with full join keys so they show up in
75+
# downstream rollups (e.g. noergler outcome='declined' joins).
76+
assert isinstance(result, BitbucketEventDraft)
77+
assert result.delivery_id == "req-decl"
78+
assert result.event_type == "pr:declined"
79+
assert result.repo_full_name == "acme/payments-api"
80+
assert result.pr_id == 42
81+
assert result.commit_sha == "abc1234567890abc1234567890abc1234567890a"
82+
assert result.branch_name == "feature/abc-123-retries"
83+
assert result.author == "alice"
84+
assert result.is_revert is False
85+
assert result.change_type == "feature"
86+
assert "ABC-123" in result.jira_keys
87+
assert "PROJ-9" in result.jira_keys
88+
assert result.payload is body
89+
90+
6091
class TestExtractRefsChanged:
6192
def test_branch_push_extracts_to_hash_and_branch(self) -> None:
6293
# Given

0 commit comments

Comments
 (0)