Skip to content

Commit

Permalink
Initial draft view of issues accross project repos
Browse files Browse the repository at this point in the history
  • Loading branch information
txels committed Feb 27, 2015
1 parent e2800d7 commit cefa130
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 5 deletions.
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
58 changes: 58 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,51 @@ angular.module('ployst.github', [
}
};
}
])
.controller('GithubIssuesController', [
'$scope', 'github.Token', 'Repos', 'github.RepoIssues',

function($scope, GHToken, Repos, GHRepoIssues)
{
$scope.hasToken = null;
$scope.repos = null;
$scope.issues = [];

var loadData = function() {
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);
}
);
});
});
};

GHToken.query(function(token) {
if (token.length > 0) {
loadData();
$scope.hasToken = true;
} else {
$scope.hasToken = false;
}
});
}
])
.directive('githubIssues', [
'Django',

function(Django) {
return {
controller: 'GithubIssuesController',
restrict: 'E',
templateUrl: Django.URL.STATIC + 'github/github-issues.html',
scope: {
project: '='
}
};
}
]);
25 changes: 25 additions & 0 deletions ployst/github/static/github/github-issues.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<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">

<ul class="list-unstyled actionable-list">
<li ng-show="!issues">Loading...</li>
<li ng-repeat="issue in issues">
<a ng-href="{{issue.html_url}}">#{{ issue.number }} @{{issue.repo}}</a>
{{ issue.title }}
<span class="label" style="background-color: #{{label.color}}"
ng-repeat="label in issue.labels">
{{ label.name }}&nbsp;
</span>
</li>
</ul>

</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'),
)
26 changes: 26 additions & 0 deletions ployst/github/views/github_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,29 @@ 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 = [
'id', 'number', 'title', 'html_url', 'state', 'labels', 'milestone'
]

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['repo'] = '{0}/{1}'.format(org, repo)
issue['labels'] = [
{'name': label['name'], 'color': label['color']}
for label in issue['labels']
]
filtered_issues.append(issue)
return Response(filtered_issues)
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

0 comments on commit cefa130

Please sign in to comment.