code: func appsFindOrCreateByRepo(db *gorm.DB, repo string) (*App, error) {
  	n := appNameFromRepo(repo)
  	a, err := appsFind(db, AppsQuery{Name: &n})
  	if err != nil && err != gorm.RecordNotFound {
  		return a, err
  	}
  
  	// If the app wasn't found, create a new app.
  	if err != gorm.RecordNotFound {
  		return a, appsEnsureRepo(db, a, repo)
  	}
  
  	a = &App{
  		Name: n,
  		Repo: &repo,
  	}
  
  	return appsCreate(db, a)
  }
docs: // appsFindOrCreateByRepo first attempts to find an app by repo, falling back to
  // creating a new app.