diff --git a/app/controllers/settings/github_syncer_controller.rb b/app/controllers/settings/github_syncer_controller.rb index c9a9eb6a16..69bf92fc58 100644 --- a/app/controllers/settings/github_syncer_controller.rb +++ b/app/controllers/settings/github_syncer_controller.rb @@ -28,7 +28,7 @@ def update render json: { error: { type: :invalid_github_solution_syncer, - message: syncer.errors.full_messages.to_sentence + message: update_error_message(syncer) } }, status: :bad_request end @@ -84,4 +84,13 @@ def callback def destroy current_user.github_solution_syncer&.destroy end + + private + def update_error_message(syncer) + if syncer.errors.of_kind?(:main_branch_name, :invalid) + return t(".invalid_main_branch_name", max_length: User::GithubSolutionSyncer::MAX_BRANCH_NAME_LENGTH) + end + + t(".failed") + end end diff --git a/config/locales/views/settings/github_syncer.yml b/config/locales/views/settings/github_syncer.yml index 5087034194..f92e4b398e 100644 --- a/config/locales/views/settings/github_syncer.yml +++ b/config/locales/views/settings/github_syncer.yml @@ -4,3 +4,6 @@ en: show: github_syncer: heading: GitHub Syncer + update: + invalid_main_branch_name: "The main branch name must be a valid Git branch name of up to %{max_length} characters, using only letters, numbers, dots, dashes, underscores and slashes." + failed: "We couldn't save your GitHub Syncer settings." diff --git a/test/controllers/settings/github_syncer_controller_test.rb b/test/controllers/settings/github_syncer_controller_test.rb index 3fe583a345..e3825f1ba7 100644 --- a/test/controllers/settings/github_syncer_controller_test.rb +++ b/test/controllers/settings/github_syncer_controller_test.rb @@ -28,7 +28,9 @@ class Settings::GithubSyncerControllerTest < ActionDispatch::IntegrationTest assert_response :bad_request error = response.parsed_body["error"] assert_equal "invalid_github_solution_syncer", error["type"] - assert_equal "Main branch name is invalid", error["message"] + expected = "The main branch name must be a valid Git branch name of up to 100 characters, " \ + "using only letters, numbers, dots, dashes, underscores and slashes." + assert_equal expected, error["message"] syncer.reload assert_equal "main", syncer.main_branch_name