travis_hook.go
func (t TravisHook) 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")
	}
	if err := t.handleSignature(r, repo.Hook.Secret); err != nil {
		return http.StatusBadRequest, err
	}
	if err := r.ParseForm(); err != nil {
		return http.StatusBadRequest, err
	}
	payload := r.FormValue("payload")
	if payload == "" {
		return http.StatusBadRequest, fmt.Errorf("Payload required")
	}
	data := &travisPayload{}
	if err := json.Unmarshal([]byte(payload), data); err != nil {
		return http.StatusBadRequest, err
	}

	// ignored webhooks
	err := hookIgnoredError{hookType: hookName(t)}
	if data.Type != "push" || data.StatusMessage != "Passed" {
		err.err = fmt.Errorf("Ignoring payload with wrong status or type")
		return 200, err
	}
	if repo.Branch != "" && data.Branch != repo.Branch {
		err.err = fmt.Errorf("Ignoring push for branch %s", data.Branch)
		return 200, err
	}

	// attempt pull
	if err := repo.Pull(); err != nil {
		return http.StatusInternalServerError, err
	}
	if err := repo.checkoutCommit(data.Commit); err != nil {
		return http.StatusInternalServerError, err
	}
	return 200, nil
}
func (t TravisHook) 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")
	}
	if err := t.handleSignature(r, repo.Hook.Secret); err != nil {
		return http.StatusBadRequest, err
	}
	if err := r.ParseForm(); err != nil {
		return http.StatusBadRequest, err
	}
	payload := r.FormValue("payload")
	if payload == "" {
		return http.StatusBadRequest, fmt.Errorf("Payload required")
	}
	data := &travisPayload{}
	if err := json.Unmarshal([]byte(payload), data); err != nil {
		return http.StatusBadRequest, err
	}

	// ignored webhooks
	err := hookIgnoredError{hookType: hookName(t)}
	if data.Type != "push" || data.StatusMessage != "Passed" {
		err.err = fmt.Errorf("Ignoring payload with wrong status or type")
		return 200, err
	}
	if repo.Branch != "" && data.Branch != repo.Branch {
		err.err = fmt.Errorf("Ignoring push for branch %s", data.Branch)
		return 200, err
	}

	// attempt pull
	if err := repo.Pull(); err != nil {
		return http.StatusInternalServerError, err
	}
	if err := repo.checkoutCommit(data.Commit); err != nil {
		return http.StatusInternalServerError, err
	}
	return 200, nil
}
func ( t TravisHook ) Handle ( w http . ResponseWriter , r * http . Request , repo * Repo ) ( int , error ) { if r . Method != " " { return http . StatusMethodNotAllowed , errors . New ( " " ) } if err := t . handleSignature ( r , repo . Hook . Secret ) ; err != nil { return http . StatusBadRequest , err } if err := r . ParseForm ( ) ; err != nil { return http . StatusBadRequest , err } payload := r . FormValue ( " " ) if payload == " " { return http . StatusBadRequest , fmt . Errorf ( " " ) } data := & travisPayload { } if err := json . Unmarshal ( [ ] byte ( payload ) , data ) ; err != nil { return http . StatusBadRequest , err } // ignored webhooks err := hookIgnoredError { hookType : hookName ( t ) } if data . Type != " " || data . StatusMessage != " " { err . err = fmt . Errorf ( " " ) return 200 , err } if repo . Branch != " " && data . Branch != repo . Branch { err . err = fmt . Errorf ( " " , data . Branch ) return 200 , err } // attempt pull if err := repo . Pull ( ) ; err != nil { return http . StatusInternalServerError , err } if err := repo . checkoutCommit ( data . Commit ) ; err != nil { return http . StatusInternalServerError , err } return 200 , nil }
// Handle satisfies hookHandler.
Handle satisfies hookHandler .