-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Projects List Feature #14
base: master
Are you sure you want to change the base?
Changes from 4 commits
d26d6b1
2e58640
d4098d3
e69003a
02f16a3
d3898cb
8e839a8
5c996fc
7bd1bf0
3f8d336
ca2bbc6
69543fb
a687d35
a4133cc
b5ecc8a
c770a2f
b83bacf
1b2982a
0bdd4cc
88e3793
f515563
a853b98
01842f7
2313cc3
32d4fd9
6c825f6
3922973
a3cf8e2
50fc91e
2cd04b5
c8e33ae
58b4d1e
08f1b7c
429c9ba
ba0e6f4
85b368e
cbe5fa5
1e40f13
aa14305
bedc587
e362ef8
fda2a9f
b51fced
0b182b9
c6db487
9eb9c4a
0ba1576
476faeb
2c0d44b
574d0f6
803ebd7
69b6614
89a25d7
f44b959
9ba28cf
2e1d595
5ea2b9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ def _make_lgtm_get(self, url: str) -> dict: | |
) | ||
return r.json() | ||
|
||
# Retrieves a user's projects | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the python standard for API doc comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you point me in that direction? I can google it but want to make sure we are on the same page. I'm not native to python :/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you send that link to me? I tried looking online but can't find any defacto API doc comment rules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this covers it. |
||
def get_my_projects(self) -> List[dict]: | ||
url = 'https://lgtm.com/internal_api/v0.2/getMyProjects?apiVersion=' + self.api_version | ||
data = self._make_lgtm_get(url) | ||
|
@@ -43,10 +44,12 @@ def get_my_projects(self) -> List[dict]: | |
else: | ||
raise LGTMRequestException('LGTM GET request failed with response: %s' % str(data)) | ||
|
||
# Given an org name, retrieve a user's projects under that org | ||
def get_my_projects_under_org(self, org: str) -> List['SimpleProject']: | ||
projects_sorted = LGTMDataFilters.org_to_ids(self.get_my_projects()) | ||
return LGTMDataFilters.extract_project_under_org(org, projects_sorted) | ||
|
||
# This method handles making a POST request to the LGTM server | ||
def _make_lgtm_post(self, url: str, data: dict) -> dict: | ||
api_data = { | ||
'apiVersion': self.api_version | ||
|
@@ -74,6 +77,7 @@ def _make_lgtm_post(self, url: str, data: dict) -> dict: | |
else: | ||
raise LGTMRequestException('LGTM POST request failed with response: %s' % str(data_returned)) | ||
|
||
# Given a project list id and a list of project ids, add the projects to the project list. | ||
def load_into_project_list(self, into_project: int, lgtm_project_ids: List[str]): | ||
url = "https://lgtm.com/internal_api/v0.2/updateProjectSelection" | ||
# Because LGTM uses some wacky format for it's application/x-www-form-urlencoded data | ||
|
@@ -104,14 +108,15 @@ def force_rebuild_project(self, simple_project: 'SimpleProject'): | |
except LGTMRequestException: | ||
print('Failed rebuilding project. This may be because it is already being built. `%s`' % simple_project) | ||
|
||
def follow_repository(self, repository_url: str): | ||
def follow_repository(self, repository_url: str) -> dict: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked and can't find any case where returning data in the function breaks the code. |
||
url = "https://lgtm.com/internal_api/v0.2/followProject" | ||
data = { | ||
'url': repository_url, | ||
'apiVersion': self.api_version | ||
} | ||
self._make_lgtm_post(url, data) | ||
return self._make_lgtm_post(url, data) | ||
|
||
# Given a project id, unfollow the project | ||
def unfollow_repository_by_id(self, project_id: str): | ||
url = "https://lgtm.com/internal_api/v0.2/unfollowProject" | ||
data = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# - new script: | ||
# - we need a script that will take a text file, loop through the text file, | ||
# and for each item in the text file add the item to the lgtm list (the list name | ||
# is derived from the name of the ext file) | ||
# | ||
|
||
from typing import List | ||
from lgtm import LGTMSite | ||
|
||
import sys | ||
import time | ||
import os | ||
|
||
cached_files = os.listdir("cache") | ||
site = LGTMSite.create_from_file() | ||
|
||
for cached_file in cached_files: | ||
# This is dirty. Is there an easier way to do this? | ||
cached_file = "cache/" + cached_file | ||
|
||
project_list_name = cached_file.split(".")[0] | ||
|
||
# We want to find or create a project list based on the the name of | ||
# the text file that holds all of the projects we are currently following. | ||
project_list_data = site.get_or_create_project_list(project_list_name) | ||
project_list_id = project_list_data['realProject'][0]['key'] | ||
file = open("cache/" + cached_file, "r") | ||
|
||
project_ids = file.read() | ||
# With the project list id and the project ids, we now want to save the repos | ||
# we currently follow to the project list | ||
site.load_into_project_list(project_list_id, project_ids) | ||
|
||
for project_id in project_ids: | ||
print(project_id) | ||
# The last thing we need to do is tidy up and unfollow all the repositories | ||
# we just added to our project list. | ||
site.unfollow_repository_by_id(project_id) | ||
|
||
os.remove(cached_file) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import List | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will remove this file once the code is more polished. |
||
import sys | ||
import os | ||
|
||
print(os.listdir("cache")) | ||
mrthankyou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
# | ||
# projects: List[str] = [] | ||
# | ||
# print(sys.argv) | ||
|
||
# from lgtm import LGTMSite | ||
# lgtm_site = LGTMSite.create_from_file() | ||
# | ||
# repo_url: str = 'https://github.com/google/jax' | ||
# | ||
# result = lgtm_site.follow_repository(repo_url) | ||
# print("1111111111") | ||
# print("1111111111") | ||
# print("1111111111") | ||
# print("1111111111") | ||
# print("1111111111") | ||
# project_id = result['realProject'][0]['key'] | ||
# print(project_id) | ||
# | ||
# print("1111111111") | ||
# print("1111111111") | ||
# print("1111111111") | ||
# print("1111111111") | ||
# project_list_id = lgtm_site.get_or_create_project_list("test_project_16") | ||
# print(project_list_id) | ||
# | ||
# lgtm_site.load_into_project_list(project_list_id, [project_id]) | ||
# | ||
# lgtm_site.unfollow_repository_by_id(project_id) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from typing import List | ||
|
||
def write_project_ids_to_file(project_ids: List[str], file_name: str): | ||
file = open("cache/" + file_name + ".txt", "a") | ||
for project_id in project_ids: | ||
file.write(project_id + "\n") | ||
file.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fan of this!