github_hook.go
func (g GithubHook) Handle(w http.ResponseWriter, r *http.Request, repo *Repo) (int, error) {
	if r.Method != "POST" {
		return http.StatusMethodNotAllowed, errors.New("the request had an invalid method")
	}

	// read full body - required for signature
	body, err := ioutil.ReadAll(r.Body)

	err = g.handleSignature(r, body, repo.Hook.Secret)
	if err != nil {
		return http.StatusBadRequest, err
	}

	event := r.Header.Get("X-Github-Event")
	if event == "" {
		return http.StatusBadRequest, errors.New("the 'X-Github-Event' header is required but was missing")
	}

	switch event {
	case "ping":
		w.Write([]byte("pong"))
	case "push":
		err = g.handlePush(body, repo)
		if !hookIgnored(err) && err != nil {
			return http.StatusBadRequest, err
		}
	case "release":
		err = g.handleRelease(body, repo)
		if err != nil {
			return http.StatusBadRequest, err
		}

	// return 400 if we do not handle the event type.
	// This is to visually show the user a configuration error in the GH ui.
	default:
		return http.StatusBadRequest, nil
	}

	return http.StatusOK, err
}
func (g GithubHook) Handle(w http.ResponseWriter, r *http.Request, repo *Repo) (int, error) {
	if r.Method != "POST" {
		return http.StatusMethodNotAllowed, errors.New("the request had an invalid method")
	}

	// read full body - required for signature
	body, err := ioutil.ReadAll(r.Body)

	err = g.handleSignature(r, body, repo.Hook.Secret)
	if err != nil {
		return http.StatusBadRequest, err
	}

	event := r.Header.Get("X-Github-Event")
	if event == "" {
		return http.StatusBadRequest, errors.New("the 'X-Github-Event' header is required but was missing")
	}

	switch event {
	case "ping":
		w.Write([]byte("pong"))
	case "push":
		err = g.handlePush(body, repo)
		if !hookIgnored(err) && err != nil {
			return http.StatusBadRequest, err
		}
	case "release":
		err = g.handleRelease(body, repo)
		if err != nil {
			return http.StatusBadRequest, err
		}

	// return 400 if we do not handle the event type.
	// This is to visually show the user a configuration error in the GH ui.
	default:
		return http.StatusBadRequest, nil
	}

	return http.StatusOK, err
}
func ( g GithubHook ) Handle ( w http . ResponseWriter , r * http . Request , repo * Repo ) ( int , error ) { if r . Method != " " { return http . StatusMethodNotAllowed , errors . New ( " " ) } // read full body - required for signature body , err := ioutil . ReadAll ( r . Body ) err = g . handleSignature ( r , body , repo . Hook . Secret ) if err != nil { return http . StatusBadRequest , err } event := r . Header . Get ( " " ) if event == " " { return http . StatusBadRequest , errors . New ( " " ) } switch event { case " " : w . Write ( [ ] byte ( " " ) ) case " " : err = g . handlePush ( body , repo ) if ! hookIgnored ( err ) && err != nil { return http . StatusBadRequest , err } case " " : err = g . handleRelease ( body , repo ) if err != nil { return http . StatusBadRequest , err } // return 400 if we do not handle the event type. // This is to visually show the user a configuration error in the GH ui. default : return http . StatusBadRequest , nil } return http . StatusOK , err }
// Handle satisfies hookHandler.
Handle satisfies hookHandler .