Commit 9d25872b authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files


parent 5c170f9f
...@@ -60,27 +60,22 @@ class Forge(Links, NamedModel): ...@@ -60,27 +60,22 @@ class Forge(Links, NamedModel):
return req.json() if req.status_code == 200 else [] return req.json() if req.status_code == 200 else []
def headers(self): def headers(self):
if self.source == SOURCES.github: return {
return {'Authorization': f'token {self.token}', 'Accept': 'application/vnd.github.drax-preview+json'} SOURCES.github: {'Authorization': f'token {self.token}', 'Accept':
if self.source == SOURCES.gitlab: 'application/vnd.github.drax-preview+json'},
return {'Private-Token': self.token} SOURCES.gitlab: {'Private-Token': self.token},
if self.source == SOURCES.redmine: SOURCES.redmine: {'X-Redmine-API-Key': self.token},
return {'X-Redmine-API-Key': self.token} }[self.source]
def api_url(self): def api_url(self):
if self.source == SOURCES.github: return {
return '' SOURCES.github: '',
if self.source == SOURCES.gitlab: SOURCES.gitlab: f'{self.url}/api/v4',
return f'{self.url}/api/v4' SOURCES.redmine: self.url,
return self.url }[self.source]
def get_projects(self): # TODO auto def get_projects(self):
if self.source == SOURCES.github: return getattr(self, f'get_projects_{self.get_source_display()}')()
return self.get_projects_github()
if self.source == SOURCES.gitlab:
return self.get_projects_gitlab()
if self.source == SOURCES.redmine:
return self.get_projects_redmine()
def get_namespaces_github(self): def get_namespaces_github(self):
for namespace in Namespace.objects.filter(group=True): for namespace in Namespace.objects.filter(group=True):
...@@ -260,12 +255,11 @@ class Repo(TimeStampedModel): ...@@ -260,12 +255,11 @@ class Repo(TimeStampedModel):
return return
def api_url(self): def api_url(self):
if self.forge.source == SOURCES.github: return {
return f'{self.forge.api_url()}/repos/{self.namespace.slug}/{self.slug}' SOURCES.github: f'{self.forge.api_url()}/repos/{self.namespace.slug}/{self.slug}',
if self.forge.source == SOURCES.redmine: SOURCES.redmine: f'{self.forge.api_url()}/projects/{self.repo_id}.json',
return f'{self.forge.api_url()}/projects/{self.repo_id}.json' SOURCES.gitlab: f'{self.forge.api_url()}/projects/{self.repo_id}',
if self.forge.source == SOURCES.gitlab: }[self.forge.source]
return f'{self.forge.api_url()}/projects/{self.repo_id}'
def api_data(self, url=''): def api_data(self, url=''):'requesting api {self.forge} {self.namespace} {self} {url}')'requesting api {self.forge} {self.namespace} {self} {url}')
...@@ -275,10 +269,7 @@ class Repo(TimeStampedModel): ...@@ -275,10 +269,7 @@ class Repo(TimeStampedModel):
def api_update(self): def api_update(self):
data = self.api_data() data = self.api_data()
if data: if data:
if self.forge.source == SOURCES.gitlab: return getattr(self, f'api_update_{self.forge.get_source_display()}')(data)
return self.api_update_gitlab(data)
if self.forge.source == SOURCES.github:
return self.api_update_github(data)
def api_update_gitlab(self, data): def api_update_gitlab(self, data):
# TODO Missing: license, homepage, open_pr # TODO Missing: license, homepage, open_pr
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment