Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: QA categories were being used only by the CLI engine #1156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions qaengine/cliengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ func (c *CliEngine) FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Errorf("the QA problem object is invalid. Error: %q", err)
return prob, err
}
// return default if the category is skipped
probCategories := qatypes.GetProblemCategories(prob.ID, prob.Categories)
for _, category := range probCategories {
if common.IsStringPresent(common.DisabledCategories, category) {
// if prob.Default == nil {
// // todo: warn instead of returning error
// return prob, errors.New(fmt.Sprintf("category %s is skipped but default doesn't exist", category)) // TODO:
// }
if err := prob.SetAnswer(prob.Default, true); err != nil {
return prob, fmt.Errorf("failed to set the given solution as the answer. Error: %w", err)
}
return prob, nil
}
}

switch prob.Type {
case qatypes.SelectSolutionFormType:
return c.fetchSelectAnswer(prob)
Expand Down
16 changes: 16 additions & 0 deletions qaengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func SetupConfigFile(writeConfigFile string, configStrings, configFiles, presets
}
}

func isQuestionDisabled(prob qatypes.Problem) bool {
isDisabled := false
probCategories := qatypes.GetProblemCategories(prob.ID, prob.Categories)
for _, category := range probCategories {
if common.IsStringPresent(common.DisabledCategories, category) {
logrus.Debugf("Question belongs to the disabled category: %s", category)
isDisabled = true
break
}
}
return isDisabled
}

// FetchAnswer fetches the answer for the question
func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Trace("FetchAnswer start")
Expand All @@ -127,6 +140,9 @@ func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Debugf("Problem already solved.")
return prob, nil
}
if isQuestionDisabled(prob) {
return defaultEngine.FetchAnswer(prob)
}
var err error
logrus.Debug("looping through the engines to try and fetch the answer")
for _, engine := range engines {
Expand Down
Loading