-
Notifications
You must be signed in to change notification settings - Fork 7
fix(github): serialise empty PR author instead of omitting it #1020
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
base: main
Are you sure you want to change the base?
Changes from all commits
4148eb6
c1fe9ac
0f85124
36f817e
ec85bb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||
| package github | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||
| "encoding/json" | ||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -152,6 +153,33 @@ func TestBuildPREvidence_RecordsCommitSignature(t *testing.T) { | |||||||||||||||||||||||
| require.Equal(t, "VALID", *c.SignatureState) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // TestBuildPREvidence_EmptyAuthorIsPreserved verifies that when the PR | ||||||||||||||||||||||||
| // creator's GitHub account has been deleted (Author.Login = ""), the empty | ||||||||||||||||||||||||
| // string is preserved and serialised as "" rather than omitted, allowing the | ||||||||||||||||||||||||
| // server to accept it directly. | ||||||||||||||||||||||||
| func TestBuildPREvidence_EmptyAuthorIsPreserved(t *testing.T) { | ||||||||||||||||||||||||
| evidence, err := buildPREvidence( | ||||||||||||||||||||||||
| "https://github.com/kosli-dev/cli/pull/671", | ||||||||||||||||||||||||
| "0e723254516c841126e81f76100be57258ff1386", | ||||||||||||||||||||||||
| "MERGED", | ||||||||||||||||||||||||
| "", // empty author — PR creator account deleted | ||||||||||||||||||||||||
| "2026-03-01T09:00:00Z", | ||||||||||||||||||||||||
| "2026-03-01T12:00:00Z", | ||||||||||||||||||||||||
| "Fix something", | ||||||||||||||||||||||||
| "fix-branch", | ||||||||||||||||||||||||
| "main", | ||||||||||||||||||||||||
| nil, nil, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||
| require.Equal(t, "", evidence.Author, | ||||||||||||||||||||||||
| "empty PR author login must be preserved so it is serialised as an empty string, not omitted") | ||||||||||||||||||||||||
|
Comment on lines
+173
to
+175
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion doesn't guard the fix it's named for. The fix is entirely the struct-tag change in Assert on the marshaled JSON so the
Suggested change
Requires adding |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| b, err := json.Marshal(evidence) | ||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||
| require.Contains(t, string(b), `"author":""`, | ||||||||||||||||||||||||
| "empty author must be serialised, not omitted") | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+170
to
+181
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't guard the actual fix. The fix lives in To actually pin the behavior, assert on the marshaled JSON so the b, err := json.Marshal(evidence)
require.NoError(t, err)
require.Contains(t, string(b), `"author":""`,
"empty author must be serialised, not omitted") |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // TestBuildPREvidence_UnsignedCommitHasNoSignatureFields verifies an unsigned | ||||||||||||||||||||||||
| // commit (no signature node) leaves verified/signature_state nil, so "unsigned" | ||||||||||||||||||||||||
| // stays distinct from "present-but-invalid" (verified=false). | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ type PREvidence struct { | |
| URL string `json:"url"` | ||
| State string `json:"state"` | ||
| Approvers []any `json:"approvers"` | ||
| Author string `json:"author,omitempty"` | ||
| Author string `json:"author"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good, targeted fix — removing Follow-up on @mbevc1's note about the same bug class for reviewers: |
||
| CreatedAt int64 `json:"created_at,omitempty"` | ||
| MergedAt int64 `json:"merged_at,omitempty"` | ||
| Title string `json:"title,omitempty"` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion still doesn't guard the actual fix (raised in the earlier review, not yet addressed).
The fix is purely the JSON struct-tag change in
types.go(droppingomitempty). ButbuildPREvidenceassignsAuthor: authorverbatim (github.go:316), sorequire.Equal(t, "", evidence.Author, …)is trivially true regardless of the struct tag — it stays green even if someone re-addsomitempty, which would re-introduce the exact bug this PR fixes.To pin the behavior, assert on the marshaled JSON so the
authorkey is proven present when empty:(requires adding
"encoding/json"to the import block.)Fix this →