func CreateApp(app *App, user *auth.User) error {
	if _, err := GetByName(app.GetName()); err != appTypes.ErrAppNotFound {
		if err != nil {
			return errors.WithMessage(err, "unable to check if app already exists")
		}
		return &appTypes.AppCreationError{Err: ErrAppAlreadyExists, App: app.GetName()}
	}
	var plan *appTypes.Plan
	var err error
	if app.Plan.Name == "" {
		plan, err = servicemanager.Plan.DefaultPlan()
	} else {
		plan, err = servicemanager.Plan.FindByName(app.Plan.Name)
	}
	if err != nil {
		return err
	}
	app.Plan = *plan
	err = app.SetPool()
	if err != nil {
		return err
	}
	err = app.configureCreateRouters()
	if err != nil {
		return err
	}
	app.Teams = []string{app.TeamOwner}
	app.Owner = user.Email
	app.Tags = processTags(app.Tags)
	if app.Platform != "" {
		app.Platform, app.PlatformVersion, err = getPlatformNameAndVersion(app.Platform)
		if err != nil {
			return err
		}
	}
	err = app.validateNew()
	if err != nil {
		return err
	}
	actions := []*action.Action{
		&reserveUserApp,
		&insertApp,
		&createAppToken,
		&exportEnvironmentsAction,
		&createRepository,
		&provisionApp,
		&addRouterBackend,
	}
	pipeline := action.NewPipeline(actions...)
	err = pipeline.Execute(app, user)
	if err != nil {
		return &appTypes.AppCreationError{App: app.Name, Err: err}
	}
	return nil
}
func CreateApp(app *App, user *auth.User) error {
	if _, err := GetByName(app.GetName()); err != appTypes.ErrAppNotFound {
		if err != nil {
			return errors.WithMessage(err, "unable to check if app already exists")
		}
		return &appTypes.AppCreationError{Err: ErrAppAlreadyExists, App: app.GetName()}
	}
	var plan *appTypes.Plan
	var err error
	if app.Plan.Name == "" {
		plan, err = servicemanager.Plan.DefaultPlan()
	} else {
		plan, err = servicemanager.Plan.FindByName(app.Plan.Name)
	}
	if err != nil {
		return err
	}
	app.Plan = *plan
	err = app.SetPool()
	if err != nil {
		return err
	}
	err = app.configureCreateRouters()
	if err != nil {
		return err
	}
	app.Teams = []string{app.TeamOwner}
	app.Owner = user.Email
	app.Tags = processTags(app.Tags)
	if app.Platform != "" {
		app.Platform, app.PlatformVersion, err = getPlatformNameAndVersion(app.Platform)
		if err != nil {
			return err
		}
	}
	err = app.validateNew()
	if err != nil {
		return err
	}
	actions := []*action.Action{
		&reserveUserApp,
		&insertApp,
		&createAppToken,
		&exportEnvironmentsAction,
		&createRepository,
		&provisionApp,
		&addRouterBackend,
	}
	pipeline := action.NewPipeline(actions...)
	err = pipeline.Execute(app, user)
	if err != nil {
		return &appTypes.AppCreationError{App: app.Name, Err: err}
	}
	return nil
}
// CreateApp creates a new app.
//
// Creating a new app is a process composed of the following steps:
//
//       1. Save the app in the database
//       2. Create the git repository using the repository manager
//       3. Provision the app using the provisioner