Skip to content

Commit

Permalink
Merge branch 'root-v1.21-and-main' into release/dcs/v1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
richmahn committed Dec 1, 2023
2 parents 3c82dc1 + 34ee484 commit 50f0358
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 150 deletions.
66 changes: 66 additions & 0 deletions models/door43metadata/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ type SearchCatalogOptions struct {
Tags []string
Stage Stage
Subjects []string
FlavorTypes []string
Flavors []string
Resources []string
Abbreviations []string
ContentFormats []string
CheckingLevels []string
Books []string
IncludeHistory bool
MetadataTypes []string
MetadataVersions []string
MetadataQueries map[string][]string
ShowIngredients util.OptionalBool
Languages []string
LanguageIsGL util.OptionalBool
Expand Down Expand Up @@ -107,12 +111,16 @@ func SearchCatalogCondition(opts *SearchCatalogOptions) builder.Cond {

cond := builder.NewCond().And(
GetSubjectCond(opts.Subjects, opts.PartialMatch),
GetFlavorTypeCond(opts.FlavorTypes, opts.PartialMatch),
GetFlavorCond(opts.Flavors, opts.PartialMatch),
GetResourceCond(opts.Resources),
GetAbbreviationCond(opts.Abbreviations),
GetContentFormatCond(opts.ContentFormats, opts.PartialMatch),
GetBookCond(opts.Books),
GetLanguageCond(opts.Languages, opts.PartialMatch),
GetCheckingLevelCond(opts.CheckingLevels),
GetMetadataTypeCond(opts.MetadataTypes, opts.PartialMatch),
GetMetadataQueryCond(opts.MetadataQueries, opts.PartialMatch),
GetTagCond(opts.Tags),
repoCond,
ownerCond,
Expand Down Expand Up @@ -191,6 +199,36 @@ func GetSubjectCond(subjects []string, partialMatch bool) builder.Cond {
return subjectCond
}

// GetFlavorTypeCond gets the flavor type condition
func GetFlavorTypeCond(flavorTypes []string, partialMatch bool) builder.Cond {
flavorTypeCond := builder.NewCond()
for _, flavorType := range flavorTypes {
for _, v := range strings.Split(flavorType, ",") {
if partialMatch {
flavorTypeCond = flavorTypeCond.Or(builder.Like{"`door43_metadata`.flavor_type", strings.TrimSpace(v)})
} else {
flavorTypeCond = flavorTypeCond.Or(builder.Eq{"`door43_metadata`.flavor_type": strings.TrimSpace(v)})
}
}
}
return flavorTypeCond
}

// GetFlavorCond gets the flavor type condition
func GetFlavorCond(flavors []string, partialMatch bool) builder.Cond {
flavorCond := builder.NewCond()
for _, flavor := range flavors {
for _, v := range strings.Split(flavor, ",") {
if partialMatch {
flavorCond = flavorCond.Or(builder.Like{"`door43_metadata`.flavor", strings.TrimSpace(v)})
} else {
flavorCond = flavorCond.Or(builder.Eq{"`door43_metadata`.flavor": strings.TrimSpace(v)})
}
}
}
return flavorCond
}

// GetResourceCond gets the metdata type condition
func GetResourceCond(resources []string) builder.Cond {
resourceCond := builder.NewCond()
Expand All @@ -202,6 +240,17 @@ func GetResourceCond(resources []string) builder.Cond {
return resourceCond
}

// GetAbbreviationCond gets the abbreviation condition
func GetAbbreviationCond(abberviations []string) builder.Cond {
abbreviationCond := builder.NewCond()
for _, abbreviation := range abberviations {
for _, v := range strings.Split(abbreviation, ",") {
abbreviationCond = abbreviationCond.Or(builder.Eq{"`door43_metadata`.abbreviation": strings.TrimSpace(v)})
}
}
return abbreviationCond
}

// GetContentFormatCond gets the metdata type condition
func GetContentFormatCond(formats []string, partialMatch bool) builder.Cond {
formatCond := builder.NewCond()
Expand Down Expand Up @@ -243,6 +292,23 @@ func GetMetadataVersionCond(versions []string, partialMatch bool) builder.Cond {
return versionCond
}

// GetMetadataQueryCond gets the metdata query condition
func GetMetadataQueryCond(queries map[string][]string, partialMatch bool) builder.Cond {
metadataQueryCond := builder.NewCond()
for field, values := range queries {
for _, value := range values {
for _, v := range strings.Split(value, ",") {
if partialMatch {
metadataQueryCond = metadataQueryCond.Or(builder.Like{field, v})
} else {
metadataQueryCond = metadataQueryCond.Or(builder.Eq{field: v})
}
}
}
}
return metadataQueryCond
}

// GetLanguageCond gets the language condition
func GetLanguageCond(languages []string, partialMatch bool) builder.Cond {
langCond := builder.NewCond()
Expand Down
57 changes: 30 additions & 27 deletions models/repo/door43metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,36 @@ func InitDoor43Metadata() error {

// Door43Metadata represents the metadata of repository's release or default branch (ReleaseID = 0).
type Door43Metadata struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX UNIQUE(repo_ref) NOT NULL"`
Repo *Repository `xorm:"-"`
ReleaseID int64 `xorm:"NOT NULL"`
Release *Release `xorm:"-"`
Ref string `xorm:"INDEX UNIQUE(repo_ref) NOT NULL"`
RefType string `xorm:"NOT NULL"`
CommitSHA string `xorm:"NOT NULL VARCHAR(40)"`
Stage door43metadata.Stage `xorm:"INDEX NOT NULL"`
MetadataType string `xorm:"INDEX NOT NULL"`
MetadataVersion string `xorm:"NOT NULL"`
Resource string `xorm:"NOT NULL"`
Subject string `xorm:"INDEX NOT NULL"`
Title string `xorm:"NOT NULL"`
Language string `xorm:"INDEX NOT NULL"`
LanguageTitle string `xorm:"NOT NULL"`
LanguageDirection string `xorm:"NOT NULL"`
LanguageIsGL bool `xorm:"NOT NULL"`
ContentFormat string `xorm:"NOT NULL"`
CheckingLevel int `xorm:"NOT NULL"`
Ingredients []*structs.Ingredient `xorm:"JSON"`
Metadata *map[string]interface{} `xorm:"JSON"`
ReleaseDateUnix timeutil.TimeStamp `xorm:"NOT NULL"`
IsLatestForStage bool `xorm:"INDEX"`
IsRepoMetadata bool `xorm:"INDEX"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created NOT NULL"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX UNIQUE(repo_ref) NOT NULL"`
Repo *Repository `xorm:"-"`
ReleaseID int64 `xorm:"NOT NULL"`
Release *Release `xorm:"-"`
Ref string `xorm:"INDEX UNIQUE(repo_ref) NOT NULL"`
RefType string `xorm:"NOT NULL"`
CommitSHA string `xorm:"NOT NULL VARCHAR(40)"`
Stage door43metadata.Stage `xorm:"INDEX NOT NULL"`
MetadataType string `xorm:"INDEX NOT NULL"`
MetadataVersion string `xorm:"NOT NULL"`
Resource string `xorm:"NOT NULL"`
Subject string `xorm:"INDEX NOT NULL"`
FlavorType string `xorm:"INDEX NOT NULL"`
Flavor string `xorm:"INDEX NOT NULL"`
Abbreviation string `xorm:"INDEX NOT NULL"`
Title string `xorm:"NOT NULL"`
Language string `xorm:"INDEX NOT NULL"`
LanguageTitle string `xorm:"NOT NULL"`
LanguageDirection string `xorm:"NOT NULL"`
LanguageIsGL bool `xorm:"NOT NULL"`
ContentFormat string `xorm:"NOT NULL"`
CheckingLevel int `xorm:"NOT NULL"`
Ingredients []*structs.Ingredient `xorm:"JSON"`
Metadata map[string]interface{} `xorm:"JSON"`
ReleaseDateUnix timeutil.TimeStamp `xorm:"NOT NULL"`
IsLatestForStage bool `xorm:"INDEX"`
IsRepoMetadata bool `xorm:"INDEX"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created NOT NULL"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
}

func init() {
Expand Down
23 changes: 16 additions & 7 deletions models/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,19 @@ type SearchRepoOptions struct {
Owners []string // DCS Customizations
Repos []string // DCS Customizations
Subjects []string // DCS Customizations
FlavorTypes []string // DCS Customizaitons
Flavors []string // DCS Customizations
Resources []string // DCS Customizations
Abbreviations []string // DCS Customizations
ContentFormats []string // DCS Customization
Books []string // DCS Customizations
Languages []string // DCS Customizations
LanguageIsGL util.OptionalBool // DCS Customizations
// query metadata type and version
MetadataTypes []string // DCS Customizations
MetadataVersions []string // DCS Customizations
MetadataTypes []string // DCS Customizations
MetadataVersions []string // DCS Customizations
MetadataQueries map[string][]string // DCS Customizations
PartialMatch bool // DCS Customizations
// When specified true, apply some filters over the conditions:
// - Don't show forks, when opts.Fork is OptionalBoolNone.
// - Do not display repositories that don't have a description, an icon and topics.
Expand Down Expand Up @@ -515,14 +520,18 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
}

/*** DCS Customizations ***/
cond = cond.And(door43metadata.GetRepoCond(opts.Repos, false),
door43metadata.GetOwnerCond(opts.Owners, false),
door43metadata.GetSubjectCond(opts.Subjects, false),
cond = cond.And(door43metadata.GetRepoCond(opts.Repos, opts.PartialMatch),
door43metadata.GetOwnerCond(opts.Owners, opts.PartialMatch),
door43metadata.GetSubjectCond(opts.Subjects, opts.PartialMatch),
door43metadata.GetFlavorTypeCond(opts.FlavorTypes, opts.PartialMatch),
door43metadata.GetFlavorCond(opts.Flavors, opts.PartialMatch),
door43metadata.GetResourceCond(opts.Resources),
door43metadata.GetAbbreviationCond(opts.Abbreviations),
door43metadata.GetContentFormatCond(opts.ContentFormats, false),
door43metadata.GetBookCond(opts.Books),
door43metadata.GetLanguageCond(opts.Languages, false),
door43metadata.GetMetadataTypeCond(opts.MetadataTypes, false))
door43metadata.GetLanguageCond(opts.Languages, opts.PartialMatch),
door43metadata.GetMetadataTypeCond(opts.MetadataTypes, false),
door43metadata.GetMetadataQueryCond(opts.MetadataQueries, opts.PartialMatch))

if len(opts.MetadataTypes) > 0 {
cond.And(door43metadata.GetMetadataVersionCond(opts.MetadataVersions, false))
Expand Down
16 changes: 8 additions & 8 deletions modules/dcs/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,47 @@ func ReadFileFromBlob(blob *git.Blob) ([]byte, error) {
}

// ReadYAMLFromBlob reads a yaml file from a blob and unmarshals it
func ReadYAMLFromBlob(blob *git.Blob) (*map[string]interface{}, error) {
func ReadYAMLFromBlob(blob *git.Blob) (map[string]interface{}, error) {
buf, err := ReadFileFromBlob(blob)
if err != nil {
return nil, err
}

var result *map[string]interface{}
var result map[string]interface{}
if err := yaml.Unmarshal(buf, &result); err != nil {
log.Error("yaml.Unmarshal: %v", err)
return nil, err
}
if result != nil {
for k, v := range *result {
for k, v := range result {
if val, err := ToStringKeys(v); err != nil {
log.Error("ToStringKeys: %v", err)
} else {
(*result)[k] = val
(result)[k] = val
}
}
}
return result, nil
}

// ReadJSONFromBlob reads a json file from a blob and unmarshals it
func ReadJSONFromBlob(blob *git.Blob) (*map[string]interface{}, error) {
func ReadJSONFromBlob(blob *git.Blob) (map[string]interface{}, error) {
buf, err := ReadFileFromBlob(blob)
if err != nil {
return nil, err
}

var result *map[string]interface{}
var result map[string]interface{}
if err := json.Unmarshal(buf, &result); err != nil {
log.Error("json.Unmarshal: %v", err)
return nil, err
}
if result != nil {
for k, v := range *result {
for k, v := range result {
if val, err := ToStringKeys(v); err != nil {
log.Error("ToStringKeys: %v", err)
} else {
(*result)[k] = val
(result)[k] = val
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/dcs/rc02.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ func ValidateMetadataTreeEntry(entry *git.TreeEntry) (*jsonschema.ValidationErro
}

// ValidateMapByRC02Schema Validates a map structure by the RC v0.2.0 schema and returns the result
func ValidateMapByRC02Schema(data *map[string]interface{}) (*jsonschema.ValidationError, error) {
func ValidateMapByRC02Schema(data map[string]interface{}) (*jsonschema.ValidationError, error) {
if data == nil {
return &jsonschema.ValidationError{Message: "file cannot be empty"}, nil
}
schema, err := GetRC02Schema(false)
if err != nil {
return nil, err
}
if err = schema.Validate(*data); err != nil {
if err = schema.Validate(data); err != nil {
switch e := err.(type) {
case *jsonschema.ValidationError:
return e, nil
Expand Down
Loading

0 comments on commit 50f0358

Please sign in to comment.