From 3635fdbe1834dda00463a78b7fb2a5e040bea177 Mon Sep 17 00:00:00 2001 From: Nicholas McDonnell <50747025+mcdonnnj@users.noreply.github.com> Date: Tue, 21 May 2024 18:10:15 -0400 Subject: [PATCH 1/2] Add handling for empty JSON output from cloc Starting in version 1.96 of cloc it will output an empty JSON object (`{}`) instead of nothing if no files are detected. --- scraper/util.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scraper/util.py b/scraper/util.py index 67c788c..7ee1e4f 100644 --- a/scraper/util.py +++ b/scraper/util.py @@ -148,6 +148,13 @@ def git_repo_to_sloc(url): except json.decoder.JSONDecodeError: logger.error("Error Decoding: url=%s, out=%s", url, out) sloc = 0 + except KeyError: + logging.error( + "Missing LOC information (Is the repository empty?): url=%s, json=%s", + url, + json.dumps(cloc_json), + ) + sloc = 0 logger.debug("SLOC: url=%s, sloc=%d", url, sloc) From 0f4fceadbb52e4047c45cc8f22f08fb8f3b2423f Mon Sep 17 00:00:00 2001 From: Nicholas McDonnell <50747025+mcdonnnj@users.noreply.github.com> Date: Tue, 21 May 2024 23:57:47 -0400 Subject: [PATCH 2/2] Reformat file with black When running `make test` this file was listed as needing to be reformatted by black. --- scraper/code_gov/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scraper/code_gov/models.py b/scraper/code_gov/models.py index 5186416..02cfe21 100644 --- a/scraper/code_gov/models.py +++ b/scraper/code_gov/models.py @@ -220,9 +220,9 @@ def from_github3(klass, repository, labor_hours=True): project["tags"] = ["github"] old_accept = repository.session.headers["Accept"] - repository.session.headers[ - "Accept" - ] = "application/vnd.github.mercy-preview+json" + repository.session.headers["Accept"] = ( + "application/vnd.github.mercy-preview+json" + ) topics = repository._get(repository.url + "/topics").json() project["tags"].extend(topics.get("names", [])) repository.session.headers["Accept"] = old_accept