Exemple #1
0
func createOrUpdateWorkItemLinkCategory(ctx context.Context, linkCatRepo *link.GormWorkItemLinkCategoryRepository, name string, description string) error {
	cat, err := linkCatRepo.LoadCategoryFromDB(ctx, name)
	cause := errs.Cause(err)
	switch cause.(type) {
	case errors.NotFoundError:
		_, err := linkCatRepo.Create(ctx, &name, &description)
		if err != nil {
			return errs.WithStack(err)
		}
	case nil:
		log.Info(ctx, map[string]interface{}{
			"pkg":      "migration",
			"category": name,
		}, "Work item link category %s exists, will update/overwrite the description", name)

		cat.Description = &description
		linkCat := link.ConvertLinkCategoryFromModel(*cat)
		_, err = linkCatRepo.Save(ctx, linkCat)
		return errs.WithStack(err)
	}
	return nil
}