Commit d68a6684 authored by Shrikrishna Singh's avatar Shrikrishna Singh

Serialize coala mrs on GitHub and GitLab

Closes coala/landing#54
coala/landing#55
parent 00f3081e
Pipeline #23578245 passed with stages
in 18 minutes and 40 seconds
......@@ -9,7 +9,7 @@ COPY backend/requirements.txt /app
RUN pip install -r requirements.txt
COPY backend /app
ENV BEAR_CRON_TIME='*/200 * * * *' REPO_CRON_TIME='*/200 * * * *' CONTRIBUTORS_CRON_TIME='*/200 * * * *' USE_DB_CACHE=True ISSUES_CRON_TIME='*/200 * * * *'
ENV BEAR_CRON_TIME='*/200 * * * *' REPO_CRON_TIME='*/200 * * * *' CONTRIBUTORS_CRON_TIME='*/200 * * * *' USE_DB_CACHE=True ISSUES_CRON_TIME='*/200 * * * *' MRS_CRON_TIME='*/200 * * * *'
RUN python3 manage.py migrate
RUN python3 manage.py createcachetable
......
......@@ -178,9 +178,11 @@ GITLAB_API_KEY = os.environ.get('GITLAB_API_KEY')
BEAR_CRON_TIME = os.environ['BEAR_CRON_TIME']
CONTRIBUTORS_CRON_TIME = os.environ['CONTRIBUTORS_CRON_TIME']
ISSUES_CRON_TIME = os.environ['ISSUES_CRON_TIME']
MRS_CRON_TIME = os.environ['MRS_CRON_TIME']
CRONJOBS = [
(BEAR_CRON_TIME, 'bears.cron.fetch_bears'),
(CONTRIBUTORS_CRON_TIME, 'org.cron.fetch_org'),
(ISSUES_CRON_TIME, 'org.issues_cron.get_issues'),
(MRS_CRON_TIME, 'org.mrs_cron.get_mrs'),
]
......@@ -18,7 +18,7 @@ from django.contrib import admin
from django.views.generic import TemplateView
from bears.views import home, search, analytics
from org.views import contrib, issues
from org.views import contrib, issues, merge_requests
from try_online.views import editor
......@@ -31,5 +31,7 @@ urlpatterns = [
url(r'^analytics/', analytics),
url(r'^issues/github/all', issues, {'hoster': 'github'}),
url(r'^issues/gitlab/all', issues, {'hoster': 'gitlab'}),
url(r'^mrs/github/all', merge_requests, {'hoster': 'github'}),
url(r'^mrs/gitlab/all', merge_requests, {'hoster': 'gitlab'}),
url(r'^', TemplateView.as_view(template_name='home.html'))
]
from functools import lru_cache
from org.git import get_igitt_org
@lru_cache(maxsize=32)
def get_mrs(hoster):
data = dict()
org = get_igitt_org(hoster)
repos = org.repositories
for repo in repos:
mrs = repo.filter_merge_requests(state='all')
for mr in mrs:
data[mr.number] = {
'number': mr.number,
'title': mr.title,
'description': mr.description,
'repo': repo.full_name,
'url': mr.web_url,
'closes_issues': (
[int(issue.number) for issue in mr.closes_issues]),
'state': mr.state.value,
'author': mr.author.username,
'assignees': [assignee.username for assignee in mr.assignees],
'ci_status': mr.tests_passed,
'created_at': mr.created,
'updated_at': mr.updated,
'labels': [label for label in mr.labels],
'reactions': [r.name for r in mr.reactions],
}
return data
......@@ -5,6 +5,7 @@ from django.views.decorators.http import require_http_methods
from django_common.http import HttpResponse
from org.models import Contributor
from org.issues_cron import get_issues
from org.mrs_cron import get_mrs
from brake.decorators import ratelimit
......@@ -34,3 +35,13 @@ def issues(request, hoster):
return HttpResponse(
json.dumps(issues, indent=4, default=str),
content_type='application/json',)
@ratelimit(block=True, rate='1/m')
@csrf_exempt
@require_http_methods(['GET'])
def merge_requests(request, hoster):
mrs = get_mrs(hoster)
return HttpResponse(
json.dumps(mrs, indent=4, default=str),
content_type='application/json',)
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