func()

in internal/command/shared/customaction/customaction.go [55:107]


func (c *Command) processAPIEndpoints(ctx context.Context, response *accessverifier.Response) error {
	client, err := gitlabnet.GetClient(c.Config)

	if err != nil {
		return err
	}

	data := response.Payload.Data
	request := &Request{Data: data}
	request.Data.UserID = response.Who

	for _, endpoint := range data.APIEndpoints {
		ctxlog := log.WithContextFields(ctx, log.Fields{
			"primary_repo": data.PrimaryRepo,
			"endpoint":     endpoint,
		})

		ctxlog.Info("customaction: processApiEndpoints: Performing custom action")

		response, err := c.performRequest(ctx, client, endpoint, request)
		if err != nil {
			return err
		}

		// Print to os.Stdout the result contained in the response
		//
		if err = c.displayResult(response.Result); err != nil {
			return err
		}

		// In the context of the git push sequence of events, it's necessary to read
		// stdin in order to capture output to pass onto subsequent commands
		//
		var output []byte

		if c.EOFSent {
			output, err = c.readFromStdin()
			if err != nil {
				return err
			}
		} else {
			output = c.readFromStdinNoEOF()
		}
		ctxlog.WithFields(log.Fields{
			"eof_sent":    c.EOFSent,
			"stdin_bytes": len(output),
		}).Debug("customaction: processApiEndpoints: stdin buffered")

		request.Output = output
	}

	return nil
}