예제 #1
0
func parseCollectorByID(ctx *context.Context) *models.Collector {
	collector, err := models.GetCollectorByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if errors.IsCollectorNotFound(err) {
			ctx.Handle(404, "EditApplication", nil)
		} else {
			ctx.Handle(500, "GetCollectorByID", err)
		}
		return nil
	}
	ctx.Data["Collector"] = collector
	return collector
}
예제 #2
0
파일: hook.go 프로젝트: Unknwon/orbiter
func Hook(ctx *context.Context) {
	collector, err := models.GetCollectorBySecret(ctx.Query("secret"))
	if err != nil {
		if errors.IsCollectorNotFound(err) {
			ctx.Error(403)
		} else {
			ctx.Error(500, err.Error())
		}
		return
	}

	payload, err := ctx.Req.Body().Bytes()
	if err != nil {
		ctx.Error(500, err.Error())
		return
	}

	// NOTE: Currently only support GitHub
	event, err := webhook.ParseGitHubEvent(payload)
	if err != nil {
		ctx.Error(500, err.Error())
		return
	}

	if err = models.NewWebhook(&models.Webhook{
		CollectorID: collector.ID,
		Owner:       tool.FirstNonEmptyString(event.Repository.Owner.Login, event.Repository.Owner.Name),
		RepoName:    event.Repository.Name,
		EventType:   ctx.Req.Header.Get("X-GitHub-Event"),
		Sender:      event.Sender.Login,
		Payload:     string(payload),
	}); err != nil {
		ctx.Error(500, err.Error())
		return
	}

	ctx.Status(202)
}