Skip to content

refactor!: Rename CodeScanningAlertState and DependabotAlertState to ...Request and pass them by value - #4617

Merged
gmlewis merged 4 commits into
google:masterfrom
JamBalaya56562:refactor/3644-alert-state-request-types
Oct 25, 2026
Merged

gmlewis merged 4 commits into
google:masterfrom
JamBalaya56562:refactor/3644-alert-state-request-types

Conversation

@JamBalaya56562

Copy link
Copy Markdown
Contributor

Updates #3644.

BREAKING CHANGE: CodeScanningAlertState and DependabotAlertState are renamed to UpdateCodeScanningAlertRequest and UpdateDependabotAlertRequest and are passed by value to CodeScanningService.UpdateAlert and DependabotService.UpdateAlert; their State fields are now *string.

This PR converts the request body types of the two "update an alert" endpoints. Both request schemas are anyOf: [{required: [state]}, {required: [assignees]}], so state is not always required, and neither Go type had assignees.

Old New Method Endpoint
*CodeScanningAlertState UpdateCodeScanningAlertRequest CodeScanningService.UpdateAlert PATCH /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}
*DependabotAlertState UpdateDependabotAlertRequest DependabotService.UpdateAlert PATCH /repos/{owner}/{repo}/dependabot/alerts/{alert_number}

Three commits:

  1. feat - Add the response fields missing from the alert schemas: Alert.Assignees, Alert.DismissalApprovedBy, Alert.LinkedPullRequests, DependabotAlert.Assignees, and DependabotAlert.DismissalRequest (with a new DependabotAlertDismissalRequest type).
  2. feat! - Follow the anyOf request schemas: State becomes *string with omitempty, and both types get Assignees []string with omitzero (an empty slice is sent as [], which the API documents as removing all assignees). Also add create_request (CreateRequest) to the code scanning type and agent_assignment (AgentAssignment, new DependabotAlertAgentAssignment type) to the Dependabot type. testJSONMarshal tests fix the JSON for the state-only, assignees-only, and empty-assignees cases.
  3. refactor! - Rename both types to ...Request and pass them by value. Both entries are removed from body-allowed-pointer-types, and the test variables are named body.

The method names already match the GitHub docs operation names ("Update a code scanning alert", "Update a Dependabot alert"), so no methods are renamed.

Verified locally: go build ./..., go vet -tags integration ./test/integration/, example module build, go test ./..., generated files idempotent, custom-gcl 0 issues, and script/check-schema-fields.sh reports no new issues.

@gmlewis gmlewis added NeedsReview PR is awaiting a review before merging. Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). labels Oct 13, 2026
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (70b9759) to head (87d718f).
⚠️ Report is 22 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4617      +/-   ##
==========================================
+ Coverage   98.61%   98.63%   +0.01%     
==========================================
  Files         199      201       +2     
  Lines       18693    18912     +219     
==========================================
+ Hits        18435    18653     +218     
- Misses        258      259       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @JamBalaya56562!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @Not-Dhananjay-Mishra - @jvm986

Comment thread github/code_scanning_test.go Outdated
Comment on lines +775 to +795
func TestUpdateCodeScanningAlertRequest_Marshal(t *testing.T) {
t.Parallel()

dismissInput := UpdateCodeScanningAlertRequest{
State: new("dismissed"),
DismissedReason: new("false positive"),
CreateRequest: new(true),
}
testJSONMarshal(t, dismissInput, `{"state":"dismissed","dismissed_reason":"false positive","create_request":true}`)

assignInput := UpdateCodeScanningAlertRequest{
Assignees: []string{"octocat"},
}
testJSONMarshal(t, assignInput, `{"assignees":["octocat"]}`)

unassignInput := UpdateCodeScanningAlertRequest{
Assignees: []string{},
}
testJSONMarshal(t, unassignInput, `{"assignees":[]}`)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We write _Marshal tests only for structs that implement custom Unmarshal/Marshal logic.
#4253 (comment)

Suggested change
func TestUpdateCodeScanningAlertRequest_Marshal(t *testing.T) {
t.Parallel()
dismissInput := UpdateCodeScanningAlertRequest{
State: new("dismissed"),
DismissedReason: new("false positive"),
CreateRequest: new(true),
}
testJSONMarshal(t, dismissInput, `{"state":"dismissed","dismissed_reason":"false positive","create_request":true}`)
assignInput := UpdateCodeScanningAlertRequest{
Assignees: []string{"octocat"},
}
testJSONMarshal(t, assignInput, `{"assignees":["octocat"]}`)
unassignInput := UpdateCodeScanningAlertRequest{
Assignees: []string{},
}
testJSONMarshal(t, unassignInput, `{"assignees":[]}`)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Removed in 87d718f.

Comment thread github/dependabot_alerts_test.go Outdated
Comment on lines +179 to +202

func TestUpdateDependabotAlertRequest_Marshal(t *testing.T) {
t.Parallel()

dismissInput := UpdateDependabotAlertRequest{
State: new("dismissed"),
DismissedReason: new("no_bandwidth"),
}
testJSONMarshal(t, dismissInput, `{"state":"dismissed","dismissed_reason":"no_bandwidth"}`)

assignInput := UpdateDependabotAlertRequest{
Assignees: []string{"copilot-swe-agent[bot]"},
AgentAssignment: &DependabotAlertAgentAssignment{
CustomInstructions: new("Upgrade the dependency"),
Model: new("m"),
},
}
testJSONMarshal(t, assignInput, `{"assignees":["copilot-swe-agent[bot]"],"agent_assignment":{"custom_instructions":"Upgrade the dependency","model":"m"}}`)

unassignInput := UpdateDependabotAlertRequest{
Assignees: []string{},
}
testJSONMarshal(t, unassignInput, `{"assignees":[]}`)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Suggested change
func TestUpdateDependabotAlertRequest_Marshal(t *testing.T) {
t.Parallel()
dismissInput := UpdateDependabotAlertRequest{
State: new("dismissed"),
DismissedReason: new("no_bandwidth"),
}
testJSONMarshal(t, dismissInput, `{"state":"dismissed","dismissed_reason":"no_bandwidth"}`)
assignInput := UpdateDependabotAlertRequest{
Assignees: []string{"copilot-swe-agent[bot]"},
AgentAssignment: &DependabotAlertAgentAssignment{
CustomInstructions: new("Upgrade the dependency"),
Model: new("m"),
},
}
testJSONMarshal(t, assignInput, `{"assignees":["copilot-swe-agent[bot]"],"agent_assignment":{"custom_instructions":"Upgrade the dependency","model":"m"}}`)
unassignInput := UpdateDependabotAlertRequest{
Assignees: []string{},
}
testJSONMarshal(t, unassignInput, `{"assignees":[]}`)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Removed in 87d718f.

@Not-Dhananjay-Mishra Not-Dhananjay-Mishra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gmlewis

gmlewis commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Thank you, @JamBalaya56562 and @Not-Dhananjay-Mishra!
Merging.

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Oct 25, 2026
@gmlewis
gmlewis merged commit a636dc9 into google:master Oct 25, 2026
15 checks passed
@JamBalaya56562
JamBalaya56562 deleted the refactor/3644-alert-state-request-types branch October 25, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants