From 35b543b81ac0f2f549bc63d368e0cf9e2566b254 Mon Sep 17 00:00:00 2001 From: "jorg.vr" Date: Mon, 25 Nov 2024 11:39:13 +0100 Subject: [PATCH 1/5] Add update_activity errors to aggregated errors for mailing --- app/models/repository.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/repository.rb b/app/models/repository.rb index 95f4bfed74..7cd91cbdf6 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -274,6 +274,9 @@ def update_activity(act) end act.save + rescue ConfigParseError => e + # add error to the list of errors + errors.push e end def github_url(path = nil, mode: nil) From 4c19693190f560ae85b37356dbf583db662c3f67 Mon Sep 17 00:00:00 2001 From: "jorg.vr" Date: Mon, 25 Nov 2024 11:59:04 +0100 Subject: [PATCH 2/5] Update comment --- app/models/repository.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 7cd91cbdf6..b5bffedf6e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -275,7 +275,8 @@ def update_activity(act) act.save rescue ConfigParseError => e - # add error to the list of errors + # Add error to the list of errors encountered during processing + # This way the error will be picked up and aggregated in the process_activities method errors.push e end From db823d4f37fdb31f6c824bfd770dccf4928c38d2 Mon Sep 17 00:00:00 2001 From: "jorg.vr" Date: Mon, 25 Nov 2024 14:14:40 +0100 Subject: [PATCH 3/5] Find dirconfig error before it causes issues --- app/models/repository.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index b5bffedf6e..93e6d5212e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -136,6 +136,8 @@ def process_activities dirs = activity_dirs errors = [] + # Read all config files and dirconfig files in the activity directories + # filter out the invalid ones and keep track of them to make a single error report at the end activity_dirs_and_configs = dirs.map do |d| Pathname.new('./').join(activity_relative_path(d)).parent.descend.each do |p| read_config_file(full_path.join(p, Activity::DIRCONFIG_FILE)) @@ -146,6 +148,15 @@ def process_activities nil end.compact + # Read the outermost dirconfig file + # if it contains errors, don't process any activities + begin + read_config_file(full_path.join(Activity::DIRCONFIG_FILE)) + rescue ConfigParseError => e + errors.push e + raise AggregatedConfigErrors.new(self, errors) + end + existing_activities = activity_dirs_and_configs .reject { |_, c| c['internals'].nil? || c['internals']['token'].nil? } .map { |d, c| [d, Activity.find_by(repository_token: c['internals']['token'], repository_id: id)] } @@ -274,10 +285,6 @@ def update_activity(act) end act.save - rescue ConfigParseError => e - # Add error to the list of errors encountered during processing - # This way the error will be picked up and aggregated in the process_activities method - errors.push e end def github_url(path = nil, mode: nil) From e8ae24c4cec151218d7d66fb061b8cbf680d454f Mon Sep 17 00:00:00 2001 From: "jorg.vr" Date: Mon, 25 Nov 2024 14:49:04 +0100 Subject: [PATCH 4/5] Fix linting --- app/models/repository.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 93e6d5212e..2c73a47fad 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -162,9 +162,9 @@ def process_activities .map { |d, c| [d, Activity.find_by(repository_token: c['internals']['token'], repository_id: id)] } # rubocop:disable Style/CollectionCompact # This is a false positive for Hash#compact, where this is Array#compact - .reject { |_, e| e.nil? } + .reject { |_, a| a.nil? } # rubocop:enable Style/CollectionCompact - .group_by { |_, e| e } + .group_by { |_, a| a } .transform_values { |l| l.pluck(0) } handled_directories = [] handled_activity_ids = [] From e4773af56c9ef4cd6f77e97d9bc1941536af95c4 Mon Sep 17 00:00:00 2001 From: "jorg.vr" Date: Mon, 25 Nov 2024 14:51:29 +0100 Subject: [PATCH 5/5] Fix linting --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 2c73a47fad..4ca3d0132f 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -154,7 +154,7 @@ def process_activities read_config_file(full_path.join(Activity::DIRCONFIG_FILE)) rescue ConfigParseError => e errors.push e - raise AggregatedConfigErrors.new(self, errors) + activity_dirs_and_configs = [] end existing_activities = activity_dirs_and_configs