Skip to content

Commit af75424

Browse files
authored
Merge pull request #3257 from chaoss/main
Latest Augur Stable Release
2 parents 9d9df05 + d5bff52 commit af75424

File tree

4 files changed

+62
-69
lines changed

4 files changed

+62
-69
lines changed

augur/application/config.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import List, Any, Optional
55
import os
66
from augur.application.db.models import Config
7-
from augur.application.db.util import execute_session_query
7+
from augur.application.db.util import execute_session_query, convert_type_of_value
88

99
def get_development_flag_from_config():
1010

@@ -109,35 +109,6 @@ def get_development_flag():
109109
}
110110

111111

112-
def convert_type_of_value(config_dict, logger=None):
113-
114-
data_type = config_dict["type"]
115-
116-
if data_type == "str" or data_type is None:
117-
return config_dict
118-
119-
elif data_type == "int":
120-
config_dict["value"] = int(config_dict["value"])
121-
122-
elif data_type == "bool":
123-
value = config_dict["value"]
124-
125-
if value.lower() == "false":
126-
config_dict["value"] = False
127-
else:
128-
config_dict["value"] = True
129-
130-
elif data_type == "float":
131-
config_dict["value"] = float(config_dict["value"])
132-
133-
else:
134-
if logger:
135-
logger.error(f"Need to add support for {data_type} types to config")
136-
else:
137-
print(f"Need to add support for {data_type} types to config")
138-
139-
return config_dict
140-
141112
class AugurConfig():
142113

143114
from augur.application.db.session import DatabaseSession

augur/application/db/lib.py

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,11 @@
1313
from augur.application.db.models import Config, Repo, Commit, WorkerOauth, Issue, PullRequest, PullRequestReview, ContributorsAlias,UnresolvedCommitEmail, Contributor, CollectionStatus, UserGroup, RepoGroup
1414
from augur.tasks.util.collection_state import CollectionState
1515
from augur.application.db import get_session, get_engine
16-
from augur.application.db.util import execute_session_query
16+
from augur.application.db.util import execute_session_query, convert_type_of_value
1717
from augur.application.db.session import remove_duplicates_by_uniques, remove_null_characters_from_list_of_dicts
1818

1919
logger = logging.getLogger("db_lib")
2020

21-
def convert_type_of_value(config_dict, logger=None):
22-
23-
24-
data_type = config_dict["type"]
25-
26-
if data_type == "str" or data_type is None:
27-
return config_dict
28-
29-
if data_type == "int":
30-
config_dict["value"] = int(config_dict["value"])
31-
32-
elif data_type == "bool":
33-
value = config_dict["value"]
34-
35-
if value.lower() == "false":
36-
config_dict["value"] = False
37-
else:
38-
config_dict["value"] = True
39-
40-
elif data_type == "float":
41-
config_dict["value"] = float(config_dict["value"])
42-
43-
else:
44-
if logger:
45-
logger.error(f"Need to add support for {data_type} types to config")
46-
else:
47-
print(f"Need to add support for {data_type} types to config")
48-
49-
return config_dict
50-
5121

5222
def get_section(section_name) -> dict:
5323
"""Get a section of data from the config.
@@ -255,24 +225,46 @@ def facade_bulk_insert_commits(logger, records):
255225

256226
facade_bulk_insert_commits(logger, firsthalfRecords)
257227
facade_bulk_insert_commits(logger, secondhalfRecords)
258-
elif len(records) == 1 and isinstance(e,DataError) and "time zone displacement" in f"{e}":
228+
elif len(records) == 1:
259229
commit_record = records[0]
260230
#replace incomprehensible dates with epoch.
261231
#2021-10-11 11:57:46 -0500
262232

263233
# placeholder_date = "1970-01-01 00:00:15 -0500"
264-
placeholder_date = commit_record['author_timestamp']
234+
placeholder_date = commit_record['cmt_author_timestamp']
235+
236+
postgres_valid_timezones = {
237+
-1200, -1100, -1000, -930, -900, -800, -700,
238+
-600, -500, -400, -300, -230, -200, -100, 000,
239+
100, 200, 300, 330, 400, 430, 500, 530, 545, 600,
240+
630, 700, 800, 845, 900, 930, 1000, 1030, 1100, 1200,
241+
1245, 1300, 1400
242+
}
265243

266244
# Reconstruct timezone portion of the date string to UTC
267-
placeholder_date = re.split("[-+]", placeholder_date)
268-
placeholder_date.pop()
269-
placeholder_date = "-".join(placeholder_date) + "+0000"
245+
placeholder_date_segments = re.split(" ", placeholder_date)
246+
tzdata = placeholder_date_segments.pop()
247+
248+
if ":" in tzdata:
249+
tzdata = tzdata.replace(":", "")
250+
251+
if int(tzdata) not in postgres_valid_timezones:
252+
tzdata = "+0000"
253+
else:
254+
raise e
255+
256+
placeholder_date_segments.append(tzdata)
257+
258+
placeholder_date = " ".join(placeholder_date_segments)
270259

271260
#Check for improper utc timezone offset
272261
#UTC timezone offset should be between -14:00 and +14:00
273262

274-
commit_record['author_timestamp'] = placeholder_date
275-
commit_record['committer_timestamp'] = placeholder_date
263+
# analyzecommit.generate_commit_record() defines the keys on the commit_record dictionary
264+
commit_record['cmt_author_timestamp'] = placeholder_date
265+
commit_record['cmt_committer_timestamp'] = placeholder_date
266+
267+
logger.warning(f"commit with invalid timezone set to UTC: {commit_record['cmt_commit_hash']}")
276268

277269
session.execute(
278270
s.insert(Commit),

augur/application/db/util.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,33 @@ def convert_orm_list_to_dict_list(result):
5858

5959
return new_list
6060

61+
62+
63+
def convert_type_of_value(config_dict, logger=None):
64+
65+
data_type = config_dict["type"]
66+
67+
if data_type == "str" or data_type is None:
68+
return config_dict
69+
70+
elif data_type == "int":
71+
config_dict["value"] = int(config_dict["value"])
72+
73+
elif data_type == "bool":
74+
value = config_dict["value"]
75+
76+
if value.lower() == "false":
77+
config_dict["value"] = False
78+
else:
79+
config_dict["value"] = True
80+
81+
elif data_type == "float":
82+
config_dict["value"] = float(config_dict["value"])
83+
84+
else:
85+
if logger:
86+
logger.error(f"Need to add support for {data_type} types to config")
87+
else:
88+
print(f"Need to add support for {data_type} types to config")
89+
90+
return config_dict

augur/application/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def get_all_repos_count(**kwargs):
2424

2525
result = controller.get_repo_count(source="all", **kwargs)
2626

27-
return result
27+
return result

0 commit comments

Comments
 (0)