Skip to content

Commit

Permalink
Fix misc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrthankyou committed Mar 3, 2021
1 parent 89a25d7 commit f44b959
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lgtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def build_simple_project(project: dict) -> SimpleProject:
key: str
project_type: str
is_valid_project: bool = True
state: str
state: str = ""

if 'protoproject' in project:
the_project = project['protoproject']
Expand Down
42 changes: 26 additions & 16 deletions utils/cacher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
import os
import time
from lgtm import LGTMSite, LGTMRequestException, LGTMDataFilters
from lgtm import LGTMSite, LGTMRequestException, LGTMDataFilters, SimpleProject

# This is very similar to SimpleProject. If I had discovered SimpleProject earlier
# I would have built this code around that.
Expand Down Expand Up @@ -59,7 +59,7 @@ def project_state(self, state: str, followed_projects: List[dict]) -> bool:

# Real projects always have successful builds, or at least as far as I can tell.
if not simple_project.is_protoproject():
in_state = !(state == "build_attempt_in_progress" or state == "build_attempt_failed")
in_state = not (state == "build_attempt_in_progress" or state == "build_attempt_failed")
break

return in_state
Expand Down Expand Up @@ -87,19 +87,22 @@ def unfollow_projects(self, site: 'LGTMSite'):
time.sleep(2)

if project.is_protoproject():
# Protoprojects are gnarly because I believe LGTM updates the key
# if the protoproject succeeds. In case it does, we retrieve the
# latest id from LGTM then unfollow it.
data = site.retrieve_project(project.display_name)

# A failed protoproject build will always be intrepreted to LGTM
# as a project that can't be found.
if 'code' in data and data['code'] == 404:
continue

self.unfollow_proto_project(data['id'])
self.unfollow_proto_project(site, data['id'])
else:
self.unfollow_real_project(project.key)
self.unfollow_real_project(site, project.key)


def unfollow_proto_project(id: int):
def unfollow_proto_project(self, site: 'LGTMSite', id: int):
try:
time.sleep(2)

Expand All @@ -108,9 +111,9 @@ def unfollow_proto_project(id: int):
# In some cases even though we've recorded the project as a protoproject
# it's actually a realproject. So we can't unfollow it via a proto-project
# unfollow API call. We can however unfollow it via the real project API call.
self.unfollow_real_project(id)
self.unfollow_real_project(site, id)

def unfollow_real_project(id: int):
def unfollow_real_project(self, site: 'LGTMSite', id: int):
try:
time.sleep(2)

Expand Down Expand Up @@ -157,18 +160,25 @@ def get_project_builds(cached_file: str) -> ProjectBuilds:

cached_projects = file.read().split("\n")

while("" in project_data):
while("" in cached_projects):
cached_projects.remove("")

for i, project in enumerate(cached_projects):
cached_projects[i] = ProjectBuild({
"display_name": project.split(",")[0],
"key": project.split(",")[1],
"project_type": project.split(",")[2],
"is_valid_project": True,
"org": "",
"state": ""
})
cached_projects[i] = ProjectBuild(
display_name=project.split(",")[0],
key=project.split(",")[1],
project_type=project.split(",")[2],
is_valid_project=True,
org="",
state=""
)

# display_name: str
# key: str
# project_type: str
# is_valid_project: bool
# org: str
# state: str

file.close()

Expand Down

0 comments on commit f44b959

Please sign in to comment.