示例#1
0
// SaveWebhook writes the webhook to the postgres database, updating an existing
// row if it exists.
func (db *Driver) SaveWebhook(hook *entity.Webhook) error {
	if hook.ID == nil || hook.IsNew() {
		return db.insertWebhook(hook)
	}

	panic("TODO: update existing webhook")
}
示例#2
0
// Exec runs the use case.
func (kase *CreateWebhook) Exec(hook entity.Webhook) (uid RepoID, err error) {
	hook.ID = &RepoID{}

	err = hook.Valid()
	if err != nil {
		err = &CreateWebhookError{Step: "validate", Child: err}
		return
	}

	err = kase.DB.SaveWebhook(&hook)
	if err != nil {
		err = &CreateWebhookError{Step: "repo", Child: err}
		return
	}

	if hook.IsNew() {
		// TODO: add some further explanation that the repo failed to assign
		// and ID.
		err = &CreateWebhookError{Step: "repo"}
		return
	}

	uid = *hook.ID.(*RepoID)
	return
}