Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ployst/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ployst.settings.dev')

from django.conf import settings
from django.conf import settings # noqa

app = Celery('ployst')

Expand Down
3 changes: 2 additions & 1 deletion ployst/core/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Meta:


class ProjectSerializer(serializers.ModelSerializer):
users = ProjectUserSerializer(source='projectuser_set', many=True)
users = ProjectUserSerializer(source='projectuser_set', many=True,
read_only=True)
am_manager = serializers.SerializerMethodField('managed_by_me')

extra_data = serializers.ReadOnlyField()
Expand Down
7 changes: 7 additions & 0 deletions ployst/github/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def org_repos(self, org):
"""
return list(org.iter_repos())

def repo_issues(self, org, repo):
"""
Return all repos from the given organisation.

"""
return list(self.gh.iter_repo_issues(org, repo))

def create_hook(self, org, repo, url):
"""
Create a hook for the given org and repo.
Expand Down
93 changes: 93 additions & 0 deletions ployst/github/static/github/github-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ angular.module('ployst.github', [
);
}
])
.factory('github.RepoIssues', [
'$resource',
function($resource) {
return $resource(
'/github/repo-issues/:org/:repo', {
org: '@org',
repo: '@repo'
}
);
}
])
.factory('github.Token', [
'$resource',
function($resource) {
Expand Down Expand Up @@ -153,4 +164,86 @@ angular.module('ployst.github', [
}
};
}
])
.controller('GithubIssuesController', [
'$scope', 'github.Token', 'Repos', 'github.RepoIssues',

function($scope, GHToken, Repos, GHRepoIssues)
{
$scope.hasToken = null;
$scope.repos = null;
$scope.allIssues = [];
$scope.issues = [];
$scope.count = 0;
$scope.groupings = {};
$scope.groupBy = null;

var buildGroupings = function(repoIssues) {
angular.forEach(repoIssues, function(issue) {
angular.forEach(issue['labels'], function(label) {
if(label.name.indexOf(':') !== -1) {
var keyval = label.name.split(':'),
key = keyval[0],
val = keyval[1];
if($scope.groupings[key] === undefined) {
$scope.groupings[key] = {};
}
if($scope.groupings[key][val] === undefined) {
$scope.groupings[key][val] = [];
}
$scope.groupings[key][val].push(issue);
}
});
});
};

var loadData = function() {
$scope.issues = [];
Repos.query({project: $scope.project.id}, function(projectRepos) {
$scope.repos = projectRepos;
angular.forEach(projectRepos, function(repo) {
GHRepoIssues.query(
{org: repo.owner, repo: repo.name},
function(repoIssues) {
$scope.issues = $scope.issues.concat(repoIssues);
buildGroupings(repoIssues);
$scope.allIssues = $scope.issues;
}
);
});
});
};

$scope.setGroupBy = function(key) {
$scope.groupBy = key;
if(key === null) {
$scope.issues = $scope.allIssues;
} else {
$scope.issues = $scope.groupings[key];
}
};

GHToken.query(function(token) {
if (token.length > 0) {
loadData();
$scope.hasToken = true;
} else {
$scope.hasToken = false;
}
});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove some duplication...

}
])
.directive('githubIssues', [
'Django',

function(Django) {
return {
controller: 'GithubIssuesController',
restrict: 'E',
templateUrl: Django.URL.STATIC + 'github/github-issues.html',
scope: {
project: '='
}
};
}
]);
65 changes: 65 additions & 0 deletions ployst/github/static/github/github-issues.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<p ng-if="hasToken === null">
Loading...
</p>

<div ng-if="hasToken === false">
<p>You still haven't authorised ployst to access your Github account.</p>
<a href="/github/oauth-start" class="btn btn-primary">Assimilate Github account</a>
</div>


<div ng-if="hasToken">
<div class="well well-sm">
<p>Filter:
<input ng-model="filter" type="text">
</p>
<p ng-if="groupings != {}">Group by:
<span ng-repeat="(key, _) in groupings">
<span ng-click="setGroupBy(key)" class="label label-default">
<i class="fa fa-tag"></i> {{ key }}
</span> &nbsp;
</span>
<span ng-click="setGroupBy(null)" class="label label-danger">
<i class="fa fa-times-circle"></i> (no groups)
</span>
</p>
</div>

<ul ng-if="groupBy === null" class="list-unstyled">
<li ng-show="!issues">Loading...</li>
<li ng-repeat="issue in issues|filter:filter">
<a target="_blank" ng-href="{{issue.html_url}}">
#{{ issue.number }} {{issue.repo}}
</a>
{{ issue.title }}
<span ng-repeat="label in issue.labels">
<span class="label" style="background-color: #{{label.color}}">
{{ label.name }}
</span> &nbsp;
</span>
<!-- span ng-if="issue.milestone" class="badge">milestone:{{ issue.milestone.title }}</span -->
</li>
</ul>

<div ng-if="groupBy">
<h3>Grouping by {{groupBy}}</h3>
<div ng-repeat="(value, issues) in issues">
<h4 ng-if="issues">{{value}}</h3>
<ul class="list-unstyled">
<li ng-repeat="issue in issues|filter:filter">
<a target="_blank" ng-href="{{issue.html_url}}">
#{{ issue.number }} {{issue.repo}}
</a>
{{ issue.title }}
<span ng-repeat="label in issue.labels">
<span class="label" style="background-color: #{{label.color}}">
{{ label.name }}
</span> &nbsp;
</span>
<!-- span ng-if="issue.milestone" class="badge">milestone:{{ issue.milestone.title }}</span -->
</li>
</ul>
</div>
</div>

</div>
3 changes: 3 additions & 0 deletions ployst/github/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
url(r'^org-repos/(?P<name>\w+)',
github_data.OrganisationRepos.as_view(),
name='org-repos'),
url(r'^repo-issues/(?P<org>[-_\w]+)/(?P<repo>[-_\w]+)',
github_data.RepoIssues.as_view(),
name='repo-issues'),
)
35 changes: 35 additions & 0 deletions ployst/github/views/github_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,38 @@ def get_repos(self):
org_name = self.kwargs['name']
org = self.gh.gh.organization(org_name)
return self.gh.org_repos(org)


class RepoIssues(APIView):
"""
Retrieve all issues for a given repo.

The organisation name is kwarg ``org`` in the URL pattern.
The repo name is kwarg ``repo`` in the URL pattern.
"""
keys = [
'number', 'title', 'html_url', 'labels', 'milestone',
# 'id', 'state',
]

def get(self, request, org, repo):
self.gh = GithubClient(request.user.id)
issues = self.gh.repo_issues(org, repo)
filtered_issues = []
for issue in issues:
issue = restrict_keys(issue.to_json(), self.keys)
issue['owner'] = org
issue['repo'] = repo
issue['labels'] = [
{'name': label['name'], 'color': label['color']}
for label in issue['labels']
]
# Add milestone as a label:
if 'milestone' in issue and issue['milestone']:
milestone = issue['milestone']['title']
issue['labels'].append({
'name': 'milestone:{0}'.format(milestone),
'color': '777777',
})
filtered_issues.append(issue)
return Response(filtered_issues)
3 changes: 3 additions & 0 deletions ployst/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<li>
<a href="{% url 'ui:home' %}#/profile"><i class="fa fa-fw fa-user"></i> Profile</a>
</li>
<li>
<a href="{% url 'ui:home' %}#/projects"><i class="fa fa-fw fa-folder"></i> Projects</a>
</li>
<li class="divider"></li>
<li>
<a href="{% url 'logout' %}"><i class="fa fa-fw fa-sign-out"></i> Logout</a>
Expand Down
6 changes: 6 additions & 0 deletions ployst/ui/static/projects/ployst.projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ angular.module('ployst.projects', [
templateUrl: Django.URL.STATIC + 'projects/project-activity.html',
menu: 'projects'
})
.state('projects.issues', {
url: '/issues',
parent: 'projects',
templateUrl: Django.URL.STATIC + 'projects/project-issues.html',
menu: 'projects'
})
.state('projects.repos', {
url: '/repos',
templateUrl: Django.URL.STATIC + 'projects/project-repos.html',
Expand Down
1 change: 1 addition & 0 deletions ployst/ui/static/projects/project-issues.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<github-issues project="ps.project"></github-issues>
15 changes: 10 additions & 5 deletions ployst/ui/static/projects/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ <h2><i class="fa fa-folder"></i> Project {{ ps.project.name }}


<ul class="nav nav-tabs">
<li ui-sref-active="active">
<a ui-sref=".activity">
<i class="fa fa-rss"></i> Activity
</a>
</li>
<li ui-sref-active="active">
<a ui-sref=".repos">
<i class="fa fa-code-fork"></i> Repositories
Expand All @@ -25,6 +20,16 @@ <h2><i class="fa fa-folder"></i> Project {{ ps.project.name }}
<i class="fa fa-user"></i> Users
</a>
</li>
<li ui-sref-active="active">
<a ui-sref=".activity">
<i class="fa fa-rss"></i> Activity
</a>
</li>
<li ui-sref-active="active">
<a ui-sref=".issues">
<i class="fa fa-exclamation-circle"></i> Issues
</a>
</li>
</ul>


Expand Down