From 9922faf86742ab52f8b1407e3b281ee56b3aed9e Mon Sep 17 00:00:00 2001 From: Keshav Garg Date: Fri, 2 Aug 2019 17:28:19 +0530 Subject: [PATCH] community/: Add a webpage for Listing Issues This commit adds a general view for listing all the issue objects for any model which stores issue related details. The details which are compulsory needed are Hoster, Repository name, Issue title, Number and the URl of it. using this, the commit adds a webpage for displaying all the inactive issues. Closes https://github.com/coala/community/issues/288 --- .moban.yaml | 1 - .nocover.yaml | 1 - community/urls.py | 9 ++- community/views.py | 15 ++++- data/migrations/0009_inactiveissue.py | 24 ++++++++ data/models.py | 8 +++ inactive_issues/inactive_issues_scraper.py | 67 ---------------------- setup.cfg | 3 - templates/base.html | 2 +- templates/issues.html | 48 ++++++++++++++++ 10 files changed, 99 insertions(+), 79 deletions(-) create mode 100644 data/migrations/0009_inactiveissue.py delete mode 100644 inactive_issues/inactive_issues_scraper.py create mode 100644 templates/issues.html diff --git a/.moban.yaml b/.moban.yaml index 69b96581..37c33484 100644 --- a/.moban.yaml +++ b/.moban.yaml @@ -4,7 +4,6 @@ package_module: community packages: - community - activity - - inactive_issues - data - gci - gsoc diff --git a/.nocover.yaml b/.nocover.yaml index 4f217eeb..d5a2050e 100644 --- a/.nocover.yaml +++ b/.nocover.yaml @@ -11,7 +11,6 @@ nocover_file_globs: - ci_build/*.py - meta_review/handler.py # Optional coverage. Once off scripts. - - inactive_issues/inactive_issues_scraper.py - unassigned_issues/unassigned_issues_scraper.py # The following rules can remain here # django db diff --git a/community/urls.py b/community/urls.py index 3683d46d..96121a1b 100644 --- a/community/urls.py +++ b/community/urls.py @@ -9,7 +9,7 @@ from community.views import ( HomePageView, JoinCommunityView, - OrganizationTeams + OrganizationTeams, InactiveIssuesList ) from gci.views import GCIStudentsList from gci.feeds import LatestTasksFeed as gci_tasks_rss @@ -17,7 +17,6 @@ from data.views import ContributorsListView from gamification.views import GamificationResults from meta_review.views import ContributorsMetaReview -from inactive_issues.inactive_issues_scraper import inactive_issues_json from unassigned_issues.unassigned_issues_scraper import ( unassigned_issues_activity_json, ) @@ -79,10 +78,10 @@ def get_index(): distill_file='meta-review/index.html', ), distill_url( - r'static/inactive-issues.json', inactive_issues_json, - name='inactive_issues_json', + r'inactive-issues/', InactiveIssuesList.as_view(), + name='inactive-issues', distill_func=get_index, - distill_file='static/inactive-issues.json', + distill_file='inactive-issues/index.html', ), distill_url( r'static/unassigned-issues.json', unassigned_issues_activity_json, diff --git a/community/views.py b/community/views.py index df3614db..fdc88fa2 100644 --- a/community/views.py +++ b/community/views.py @@ -23,7 +23,7 @@ NewcomerPromotion, Feedback ) -from data.models import Team +from data.models import Team, InactiveIssue from gamification.models import Participant as GamificationParticipant from meta_review.models import Participant as MetaReviewer @@ -221,3 +221,16 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context = get_header_and_footer(context) return context + + +class InactiveIssuesList(ListView): + + template_name = 'issues.html' + model = InactiveIssue + ordering = 'hoster' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context = get_header_and_footer(context) + context['page_name'] = 'Inactive Issues List' + return context diff --git a/data/migrations/0009_inactiveissue.py b/data/migrations/0009_inactiveissue.py new file mode 100644 index 00000000..6bdaf3e1 --- /dev/null +++ b/data/migrations/0009_inactiveissue.py @@ -0,0 +1,24 @@ +# Generated by Django 2.1.7 on 2019-08-02 11:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('data', '0008_auto_20190802_0745'), + ] + + operations = [ + migrations.CreateModel( + name='InactiveIssue', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('hoster', models.CharField(max_length=30)), + ('title', models.CharField(max_length=500)), + ('repository', models.CharField(max_length=100)), + ('number', models.SmallIntegerField()), + ('url', models.URLField()), + ], + ), + ] diff --git a/data/models.py b/data/models.py index 295ec08f..b7f4afdc 100644 --- a/data/models.py +++ b/data/models.py @@ -116,3 +116,11 @@ def get_closes_issues_object(self): issue_object = issue_number.get_issue() issues_object_list.append(issue_object) return issues_object_list + + +class InactiveIssue(models.Model): + hoster = models.CharField(max_length=30) + title = models.CharField(max_length=500) + repository = models.CharField(max_length=100) + number = models.SmallIntegerField() + url = models.URLField() diff --git a/inactive_issues/inactive_issues_scraper.py b/inactive_issues/inactive_issues_scraper.py deleted file mode 100644 index 88c2e3a1..00000000 --- a/inactive_issues/inactive_issues_scraper.py +++ /dev/null @@ -1,67 +0,0 @@ -import time -import json - -from github import Github -from dateutil.parser import parse -from datetime import date -from django.http import HttpResponse -from gci.config import get_api_key - -from community.git import get_org_name - - -def run(issues): - issues_number_list = [] - for j in issues: - issue_no = j.number - events = j.get_events() - myevent_list = [] - data = [] - for i in events: - myevent_list.append(str(i.event)) - for i in events: - if i.commit_id is not None: - data.append(str(i.created_at)) - for i, myevents in reversed(list(enumerate(myevent_list))): - if myevents == 'unassigned': - break - elif myevents == 'assigned': - a = events[i].created_at - c = (date.fromtimestamp(time.time()) - a.date()).days - if c >= 60: # for checking assigned duration - - mydata = list(reversed(data)) - if len(mydata) != 0: - commit1 = parse(mydata[0]) - calculated_days = (date.fromtimestamp( - time.time()) - commit1.date()).days - if calculated_days >= 60: - # for checking last commit update - issues_number_list.append(issue_no) - else: - issues_number_list.append(issue_no) - break - return issues_number_list - - -def inactive_issues_json(request): - try: - GH_TOKEN = get_api_key('GH') - except Exception: - return HttpResponse('[]') - g1 = Github(GH_TOKEN) - org_name = get_org_name() - org = g1.get_organization(org_name) - repo = org.get_repo(org_name) - issues = repo.get_issues() - issues_list = [] - for myissue in issues: - labels = [] - for mylabel in myissue.labels: - labels.append(mylabel.name) - if 'status/blocked' not in labels: - if myissue.state == 'open' and myissue.pull_request is None: - issues_list.append(myissue) - - final_list = run(issues_list) - return HttpResponse(json.dumps(final_list)) diff --git a/setup.cfg b/setup.cfg index 23113a04..cddc1f02 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,6 @@ DJANGO_SETTINGS_MODULE = community.settings testpaths = community activity - inactive_issues data gci gsoc @@ -63,7 +62,6 @@ plugins = source = community activity - inactive_issues data gci gsoc @@ -80,7 +78,6 @@ omit = gsoc/*.py ci_build/*.py meta_review/handler.py - inactive_issues/inactive_issues_scraper.py unassigned_issues/unassigned_issues_scraper.py */migrations/*.py */management/commands/*.py diff --git a/templates/base.html b/templates/base.html index 32b4c185..ec774ee9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -71,7 +71,7 @@
  • Contributors Information
  • Mentors
  • Google Code-in Students
  • -
  • Inactive issues
  • +
  • Inactive issues
  • Unassigned issues activity
  • Project CI Build
  • {% if isTravis %} diff --git a/templates/issues.html b/templates/issues.html new file mode 100644 index 00000000..bc5a652a --- /dev/null +++ b/templates/issues.html @@ -0,0 +1,48 @@ +{% extends 'base.html' %} +{% load staticfiles %} + +{% block main-content %} +
    +

    ~

    +

    + {{ page_name }} +

    +

    ~

    +
    +
    + {% if object_list.count > 0 %} + + + + + + + + + + {% for issue in object_list %} + + + + + + {% endfor %} + +
    +
    Hoster
    +
    +
    Title
    +
    +
    Issue
    +
    {{ issue.hoster }}{{ issue.title }} + {{ issue.repository }}#{{ issue.number }} +
    + {% else %} +
    + No Issues Found! +
    + {% endif %} +
    + +{% endblock %}