Problem
We're tracking scanned repositories and their results in a database, but the implementation has issues:
- Multiple pagination searches - After creating/updating issues or PRs, we search through all issues/PRs again to find the URL
- Test failures - Tests crash with nil pointer errors
- Verbose error handling - Database save functions require verbose error handling at every call site
Solution
Use Go's context pattern to communicate action results (issue/PR URLs) from the action functions back to the caller.
Implementation Progress
✅ Completed
-
Created context helper - pkg/policies/action/actionresult.go
WithActionResult(ctx) - wraps context to track results
SetActionURL(ctx, url) - stores URL in context
GetActionResult(ctx) - retrieves stored URL
-
Updated issue package - pkg/issue/issue.go - calls action.SetActionURL() after creating/updating issues
-
Updated pullrequest package - pkg/pullrequest/pullrequest.go - calls action.SetActionURL() after creating/updating PRs
-
Updated enforce.go - wraps context, retrieves URL from context, deleted getIssueURL() and getPRURL() functions
-
Enhanced database logging - both save functions now log errors internally
🔄 In Progress
Simplify database error handling - Remove verbose error handling at 6+ call sites in pkg/enforce/enforce.go
Lines to fix: 162, 222, 388, 419, 468, 505
⏳ Remaining
Update tests - Fix test mocks in pkg/enforce/enforce_test.go
Files Modified
- ✅
pkg/policies/action/actionresult.go - new file
- ✅
pkg/issue/issue.go
- ✅
pkg/pullrequest/pullrequest.go
- ✅
pkg/enforce/enforce.go - partial
- 🔄
pkg/enforce/enforce.go - error handling cleanup needed
- ⏳
pkg/enforce/enforce_test.go - mocks need updating
Problem
We're tracking scanned repositories and their results in a database, but the implementation has issues:
Solution
Use Go's context pattern to communicate action results (issue/PR URLs) from the action functions back to the caller.
Implementation Progress
✅ Completed
Created context helper -
pkg/policies/action/actionresult.goWithActionResult(ctx)- wraps context to track resultsSetActionURL(ctx, url)- stores URL in contextGetActionResult(ctx)- retrieves stored URLUpdated issue package -
pkg/issue/issue.go- callsaction.SetActionURL()after creating/updating issuesUpdated pullrequest package -
pkg/pullrequest/pullrequest.go- callsaction.SetActionURL()after creating/updating PRsUpdated enforce.go - wraps context, retrieves URL from context, deleted
getIssueURL()andgetPRURL()functionsEnhanced database logging - both save functions now log errors internally
🔄 In Progress
Simplify database error handling - Remove verbose error handling at 6+ call sites in
pkg/enforce/enforce.goLines to fix: 162, 222, 388, 419, 468, 505
⏳ Remaining
Update tests - Fix test mocks in
pkg/enforce/enforce_test.goFiles Modified
pkg/policies/action/actionresult.go- new filepkg/issue/issue.gopkg/pullrequest/pullrequest.gopkg/enforce/enforce.go- partialpkg/enforce/enforce.go- error handling cleanup neededpkg/enforce/enforce_test.go- mocks need updating