Skip to content

Refactor: Use context to pass action URLs instead of redundant pagination searchesΒ #762

@maigl

Description

@maigl

Problem

We're tracking scanned repositories and their results in a database, but the implementation has issues:

  1. Multiple pagination searches - After creating/updating issues or PRs, we search through all issues/PRs again to find the URL
  2. Test failures - Tests crash with nil pointer errors
  3. 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

  1. 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
  2. Updated issue package - pkg/issue/issue.go - calls action.SetActionURL() after creating/updating issues

  3. Updated pullrequest package - pkg/pullrequest/pullrequest.go - calls action.SetActionURL() after creating/updating PRs

  4. Updated enforce.go - wraps context, retrieves URL from context, deleted getIssueURL() and getPRURL() functions

  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions