Skip to content

Commit

Permalink
Add: Unassigned issue app
Browse files Browse the repository at this point in the history
List of all the issues on organization
main repository on which someone opened
a PR (with passed ``CI``) without getting
assigned to it.
  • Loading branch information
RaiVaibhav committed May 3, 2018
1 parent 2a20c4b commit bfd358d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions community/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
OutsideCommitterListView,
OutsideCommitterDetailView,
)
from unassigned_issues.unassigned_issues_scraper import (
unassigned_issues_activity_json,
)


def get_index():
Expand Down Expand Up @@ -202,4 +205,10 @@ def get_organization():
name='org-detail',
distill_func=get_organization,
),
distill_url(
r'static/unassigned-issues.json', unassigned_issues_activity_json,
name='unassigned_issues_activity_json',
distill_func=get_index,
distill_file='static/unassigned-issues.json',
),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2 changes: 2 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
href="/static/inactive-issues.json">Inactive Issues</a>
<li><a href="/openhub/">OpenHub Data</a>
<li><a href="/model/">Visit imported data</a>
<li><a title="List of all the issues on organization main repository on which someone has opened a pull request without getting assigned to it."
href="/static/unassigned-issues.json">Unassigned issues activity</a>
</ul>
</body>
</html>
48 changes: 48 additions & 0 deletions unassigned_issues/unassigned_issues_scraper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json

from django.http import HttpResponse
from gci.config import get_api_key
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubRepository import GitHubRepository
from IGitt.Interfaces import MergeRequestStates
from IGitt.Interfaces import IssueStates
from IGitt.Interfaces.CommitStatus import Status

from community.git import get_org_name


def run(mr_requests):
issues_number_list = []
for pr in mr_requests:
if pr.state is MergeRequestStates.OPEN:
for commit in pr.commits:
status = commit.combined_status
break
if status in [Status.PENDING, Status.SUCCESS]:
for issue in pr.closes_issues:
if issue.state is IssueStates.OPEN:
if pr.author.username not in (
[a.username for a in issue.assignees]):
issues_number_list.append(issue.number)
issues_number_list.sort()
return issues_number_list


def unassigned_issues_activity_json(request):
try:
GH_TOKEN = get_api_key('GH')
except Exception:
return HttpResponse('[]')
org_name = get_org_name()
org_repo_name = org_name
# Here 'org_repo_name' is the name of repository of a organization.
# (assumed here, that name of repository is same as the organization name.)
# But you can change 'org_repo_name' as per your requirement.
repo_name = org_name + '/' + org_repo_name
# 'repo_name' is a full name of repository e.g. `fossasia/susi_server`
# which further used for query (assuming here 'org_name' is different from
# 'org_repo_name')
repo = GitHubRepository(GitHubToken(GH_TOKEN), repo_name)
mr_requests = repo.merge_requests
final_list = run(mr_requests)
return HttpResponse(json.dumps(final_list))

0 comments on commit bfd358d

Please sign in to comment.