Skip to content

Commit

Permalink
fix github timestamp creation (anchore#111)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Mar 13, 2023
1 parent 5c29a65 commit dc53866
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/vunnel/providers/github/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,15 @@ def _parse(self, data):
def get(self):
# determine if a run was completed by looking for a timestamp
metadata = self.db.get_metadata()

# why rstrip(Z)? Previous code had been incorrectly adding a Z to the end of the timestamp manually
# instead of using the isoformat() method. This lead to a parsing problem with the github API (naturally).
# in the future this rstrip() should be removed when all cached data in CI is updated.
self.timestamp = metadata.data.get("timestamp")
current_timestamp = f"{datetime.datetime.now(tz=datetime.timezone.utc).isoformat()}Z"
if self.timestamp:
self.timestamp = self.timestamp.rstrip("Z")

current_timestamp = datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
has_cursor = True

# Process everything that was persisted first
Expand All @@ -169,6 +176,9 @@ def get(self):
# point in time, if a cursor is present, it will be used as well
data = self._download()

if "errors" in data:
raise RuntimeError(f"Error downloading advisories: {data['errors']}")

page_info = data["data"]["securityAdvisories"]["pageInfo"]
if page_info["hasNextPage"]:
self.cursor = has_cursor = page_info.get("endCursor")
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/providers/github/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def test_get_commits_timestamp(self, fake_get_query, tmpdir, empty_response):
metadata = database.get_metadata()
timestamp = metadata.data["timestamp"]
assert isinstance(timestamp, str)
assert timestamp.endswith("Z")
assert timestamp.endswith("Z") or timestamp.endswith("+00:00")

def test_get_commits_timestamp_with_cursors(self, advisories, fake_get_query, tmpdir, empty_response):
fake_get_query([empty_response, advisories(has_next_page=True)])
Expand All @@ -355,7 +355,7 @@ def test_get_commits_timestamp_with_cursors(self, advisories, fake_get_query, tm
metadata = database.get_metadata()
timestamp = metadata.data["timestamp"]
assert isinstance(timestamp, str)
assert timestamp.endswith("Z")
assert timestamp.endswith("Z") or timestamp.endswith("+00:00")

def test_has_next_page(self, advisories, fake_get_query, tmpdir, empty_response):
fake_get_query([empty_response, advisories(has_next_page=True)])
Expand Down

0 comments on commit dc53866

Please sign in to comment.