Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ type Client struct {
SubIssue *SubIssueService
Teams *TeamsService
Users *UsersService
Callback func()
}

type service struct {
Expand Down Expand Up @@ -465,6 +466,7 @@ func (c *Client) initialize() {
c.SubIssue = (*SubIssueService)(&c.common)
c.Teams = (*TeamsService)(&c.common)
c.Users = (*UsersService)(&c.common)
c.Callback = nil
}

// copy returns a copy of the current client. It must be initialized before use.
Expand Down Expand Up @@ -1022,6 +1024,14 @@ func (c *Client) bareDoUntilFound(ctx context.Context, req *http.Request, maxRed
return nil, response, err
}

// WithCallback schedules a callback that can be executed later just before Client.bareDo.
// Returns the same Client instance to allow method chaining.
// Callback function must return a func().
func (c *Client) WithCallback(callbackfunction func()) *Client {
c.Callback = callbackfunction
return c
}

// Do sends an API request and returns the API response. The API response is
// JSON decoded and stored in the value pointed to by v, or returned as an
// error if an API error has occurred. If v implements the io.Writer interface,
Expand All @@ -1033,6 +1043,10 @@ func (c *Client) bareDoUntilFound(ctx context.Context, req *http.Request, maxRed
// The provided ctx must be non-nil, if it is nil an error is returned. If it
// is canceled or times out, ctx.Err() will be returned.
func (c *Client) Do(ctx context.Context, req *http.Request, v any) (*Response, error) {
// run callback function if passed, during Client.bareDo
if c.Callback != nil {
c.Callback()
}
resp, err := c.BareDo(ctx, req)
if err != nil {
return resp, err
Expand Down
Loading