From 3354b46b08e44ae78a93b3c89221076ac1bde65d Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Sat, 16 Aug 2025 14:54:13 +0530 Subject: [PATCH 1/3] Added WithCallback Feature --- github/github.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/github/github.go b/github/github.go index bb81b00c104..7bf26f3c86b 100644 --- a/github/github.go +++ b/github/github.go @@ -228,6 +228,7 @@ type Client struct { SubIssue *SubIssueService Teams *TeamsService Users *UsersService + Callback func() } type service struct { @@ -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. @@ -1022,6 +1024,15 @@ func (c *Client) bareDoUntilFound(ctx context.Context, req *http.Request, maxRed return nil, response, err } +// WithCallback assigns a callback function to the Client instance. +// The callback can be executed later jsut 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, @@ -1033,6 +1044,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 From fdb9a58f2e5e24009e505759d5e2eff3a42557d6 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Sat, 16 Aug 2025 17:42:55 +0530 Subject: [PATCH 2/3] fix comments --- github/github.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/github/github.go b/github/github.go index 7bf26f3c86b..bfe4c06903b 100644 --- a/github/github.go +++ b/github/github.go @@ -1024,10 +1024,9 @@ func (c *Client) bareDoUntilFound(ctx context.Context, req *http.Request, maxRed return nil, response, err } -// WithCallback assigns a callback function to the Client instance. -// The callback can be executed later jsut before Client.bareDo +// The callback can be executed later just before Client.bareDo // Returns the same Client instance to allow method chaining. -// Callback function must return a func() +// Callback function must return a func(). func (c *Client) WithCallback(callbackfunction func()) *Client { c.Callback = callbackfunction return c From 659fe9847f7f332ebb6e15582cbc3a879d4bca11 Mon Sep 17 00:00:00 2001 From: Not-Dhananjay-Mishra Date: Sat, 16 Aug 2025 18:38:54 +0530 Subject: [PATCH 3/3] fix comments --- github/github.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/github.go b/github/github.go index bfe4c06903b..60e6a4e39a8 100644 --- a/github/github.go +++ b/github/github.go @@ -1024,7 +1024,7 @@ func (c *Client) bareDoUntilFound(ctx context.Context, req *http.Request, maxRed return nil, response, err } -// The callback can be executed later just before Client.bareDo +// 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 {