func (g GithubHook) handleRelease(body []byte, repo *git.Repo) error { var release ghRelease err := json.Unmarshal(body, &release) if err != nil { return err } if release.Release.TagName == "" { return errors.New("The release request contained an invalid TagName.") } logger().Printf("Received new release '%s'. -> Updating local repository to this release.", release.Release.Name) // Update the local branch to the release tag name // this will pull the release tag. repo.Branch = release.Release.TagName repo.Pull() return nil }
func (g GithubHook) handlePush(body []byte, repo *git.Repo) error { var push ghPush err := json.Unmarshal(body, &push) if err != nil { return err } // extract the branch being pushed from the ref string // and if it matches with our locally tracked one, pull. refSlice := strings.Split(push.Ref, "/") if len(refSlice) != 3 { return errors.New("The push request contained an invalid reference string.") } branch := refSlice[2] if branch == repo.Branch { logger().Print("Received pull notification for the tracking branch, updating...") repo.Pull() } return nil }