diff options
-rw-r--r-- | cgitize/config.py | 4 | ||||
-rw-r--r-- | cgitize/main.py | 35 | ||||
-rw-r--r-- | docker/frontend/etc/cgit/common | 2 | ||||
-rwxr-xr-x | test/integration/local/test.sh | 23 |
4 files changed, 56 insertions, 8 deletions
diff --git a/cgitize/config.py b/cgitize/config.py index d4e660a..2df8651 100644 --- a/cgitize/config.py +++ b/cgitize/config.py @@ -44,6 +44,10 @@ class MainSection(Section): return self._get_config_path('output_dir', default=MainSection.DEFAULT_OUTPUT_DIR) @property + def error_header_path(self): + return os.path.join(self.output_dir, 'error.html') + + @property def clone_url(self): return self._get_config_value('clone_url', required=False) diff --git a/cgitize/main.py b/cgitize/main.py index 879e07d..7e52df0 100644 --- a/cgitize/main.py +++ b/cgitize/main.py @@ -32,23 +32,42 @@ def parse_args(argv=None): return parser.parse_args(argv) +def setup_error_header_file(error_header_path, success, error=None): + with open(error_header_path, 'w') as file: + contents = '' + if not success: + contents = '''<p style="text-align: center; color: red; font-weight: bold;">''' + contents += '''Some repositories couldn't be updated, please check application logs for details.''' + if error is not None: + contents += f'''<br>{type(error).__name__}: {error}''' + contents += '''</p>\n''' + file.write(contents) + + def main(argv=None): args = parse_args(argv) with setup_logging(args.verbose): config = Config.read(args.config) - cgit_server = CGitServer(config.main.clone_url) - output = CGitRepositories(config.main.output_dir, cgit_server, force=args.force) success = True - for repo in config.parse_repositories(): - if args.repos is None or repo.name in args.repos: - if not output.update(repo): - success = False + error = None + + try: + cgit_server = CGitServer(config.main.clone_url) + output = CGitRepositories(config.main.output_dir, cgit_server, force=args.force) + for repo in config.parse_repositories(): + if args.repos is None or repo.name in args.repos: + success = success and output.update(repo) + except Exception as e: + success = False + error = e + if success: logging.info('All repositories were updated successfully') - return 0 else: logging.warning("Some repositories couldn't be updated!") - return 1 + + setup_error_header_file(config.main.error_header_path, success, error) + return int(not success) if __name__ == '__main__': diff --git a/docker/frontend/etc/cgit/common b/docker/frontend/etc/cgit/common index 2e1b6eb..ffcb1b7 100644 --- a/docker/frontend/etc/cgit/common +++ b/docker/frontend/etc/cgit/common @@ -37,3 +37,5 @@ source-filter=/usr/lib/cgit/filters/syntax-highlighting.py # Set the directory path to search for repositories. scan-path=/mnt/cgitize + +header=/mnt/cgitize/error.html diff --git a/test/integration/local/test.sh b/test/integration/local/test.sh index 96ab2c5..dbed2e1 100755 --- a/test/integration/local/test.sh +++ b/test/integration/local/test.sh @@ -179,6 +179,26 @@ verify_added_commits() { verify_commits 'first commit' 'second commit' 'third commit' } +verify_error_header_empty() { + echo + echo ---------------------------------------------------------------------- + echo Verifying the error header + echo ---------------------------------------------------------------------- + + test ! -s "$output_dir/error.html" +} + +verify_error_header() { + echo + echo ---------------------------------------------------------------------- + echo Verifying the error header + echo ---------------------------------------------------------------------- + + local contents + contents="$( cat -- "$output_dir/error.html" )" + check_contains "$contents" "Some repositories couldn't be updated" +} + test_bare() { echo echo ====================================================================== @@ -191,6 +211,7 @@ test_bare() { add_commits cgitize verify_added_commits + verify_error_header_empty cleanup success } @@ -207,6 +228,7 @@ test_workdir() { add_commits cgitize verify_added_commits + verify_error_header_empty cleanup success } @@ -237,6 +259,7 @@ test_failure() { echo "The added commits should not have been pulled." >&2 return 1 fi + verify_error_header cleanup success } |