Skip to content

Commit

Permalink
Merge pull request #26 from VincentCATILLON/feature-labels
Browse files Browse the repository at this point in the history
Adds labels and milestones display to PR
  • Loading branch information
Florent Dubost committed May 9, 2016
2 parents be563cc + f758726 commit bd99aa5
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Options :
* *org* : an array of Github organizations,
* *apiUrl* : url of your Github API (optional, default is `https://api.github.com`),
* *descendingOrder* : allow to change ordering of pull requests (optional, default is `true`).
* *labels* : display labels of pull requests (optional, default is `false`).
* *milestones* : display milestones of pull requests (optional, default is `false`).
* *token* : authorization token for API calls (optional, it can allow access to more repos and increase API rate limit) NB: if a token is set, OAuth will be ignored for the team
* *oauthAppClientId* : clientId of the OAuth app the team depends on (optional)
* **githubOAuth** : OAuth config (optional)
Expand Down
12 changes: 12 additions & 0 deletions app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ angular.module('gtrApp')
$scope.descendingOrder = true;
}

if (typeof(config.teams[team].labels) !== 'undefined') {
$scope.labels = config.teams[team].labels;
} else {
$scope.labels = false;
}

if (typeof(config.teams[team].milestones) !== 'undefined') {
$scope.milestones = config.teams[team].milestones;
} else {
$scope.milestones = false;
}

var statePriorities = {
'error': 4,
'failure': 3,
Expand Down
16 changes: 16 additions & 0 deletions app/scripts/services/pullFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,26 @@ angular.module('gtrApp')
});
};

var addLabelsToPull = function (pull) {
return request(pull.issue_url + '/labels').then(function (response) {
pull.labels = response.data;
});
};

var removeMilestoneToPull = function (pull) {
pull.milestone = null;
};

var getRepoPulls = function (repo) {
return request(repo.pulls_url.replace('{/number}', ''))
.then(function (response) {
var filtered = response.data.filter(filterPulls);
if (currentTeam.labels) {
filtered.map(addLabelsToPull);
}
if (!currentTeam.milestones) {
filtered.map(removeMilestoneToPull);
}

return $q.all(filtered.map(addStatusToPull)).then(function() {
return filtered;
Expand Down
16 changes: 16 additions & 0 deletions app/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,19 @@ ul {
.pr-counter {
margin-right: 10px;
}

.badge {
padding: 4px 8px;
border-radius: 4px;
font-size: 0.875em;
color: black;
}

.badge-label {
margin-left: 4px;
}

.badge-milestone {
background-color: white;
margin-right: 4px;
}
7 changes: 6 additions & 1 deletion app/views/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
<div class="container">
<ul class="pulls">
<li ng-repeat="pr in toArray(pulls) | orderBy:'updated_at':descendingOrder" ng-class="pr.statuses[0].state" class="status">
<span class="link"><img class="avatar" ng-src="{{ pr.user.avatar_url}}" title="{{ pr.user.login }}" /><a ng-href="{{pr.html_url}}" >#{{ pr.number }} {{ pr.title }}</a></span>
<span class="link">
<img class="avatar" ng-src="{{ pr.user.avatar_url}}" title="{{ pr.user.login }}" />
<a ng-href="{{pr.html_url}}" >#{{ pr.number }} {{ pr.title }}</a>
<span class="badge badge-label" ng-repeat="label in toArray(pr.labels)" style="background-color: #{{ label.color }}">{{ label.name }}</span>
</span>
<span class="pull-right">
<span class="badge badge-milestone" ng-show="pr.milestone != null">{{ pr.milestone.title }}</span>
<span class="repo"><a ng-href="{{pr.head.repo.html_url}}" >{{ pr.head.repo.full_name }}</a></span>
<span class="date">{{pr.updated_at | date:"dd/MM/yyyy"}}</span>
</span>
Expand Down
4 changes: 3 additions & 1 deletion config/config.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"projects": ["repo1", "repo2"],
"orgs": ["orgname1", "orgname2"],
"token": "apiToken",
"descendingOrder": true
"descendingOrder": true,
"labels": true,
"milestones": true
},
"teamWithOAuth": {
"members": ["username4", "username2", "username5"],
Expand Down
6 changes: 4 additions & 2 deletions config/config_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
"burton": {
"members": ["papy", "worker"],
"orgs": ["m6web"],
"apiUrl": "/api/v3"
"apiUrl": "/api/v3",
"labels": true
},
"service-polls": {
"descendingOrder": false,
"projects": ["service-polls"],
"orgs": ["m6web", "replay"],
"apiUrl": "/api/v3"
"apiUrl": "/api/v3",
"milestones": true
}
}
}
Expand Down
34 changes: 28 additions & 6 deletions test/e2e/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('Test GTR screen', function () {
backend.whenGET('/api/v3/repos/m6web/service-polls/pulls').respond([{
'id': 6467,
'html_url': 'http://example.com/m6web/service-polls/pull/54',
'issue_url': '/api/v3/repos/m6web/service-polls/issues/54',
'number': 54,
'title': 'PR 54',
'state': 'open',
Expand All @@ -97,11 +98,13 @@ describe('Test GTR screen', function () {
'full_name': 'm6web/service-polls',
'name': 'service-polls'
}
}
},
'milestone': null
},
{
'id': 6468,
'html_url': 'http://example.com/m6web/service-polls/pull/55',
'issue_url': '/api/v3/repos/m6web/service-polls/issues/55',
'number': 55,
'title': 'PR 55',
'state': 'open',
Expand All @@ -120,11 +123,15 @@ describe('Test GTR screen', function () {
'full_name': 'm6web/service-polls',
'name': 'service-polls'
}
},
'milestone': {
'title': 'release-1.1.0'
}
},
{
'id': 6469,
'html_url': 'http://example.com/m6web/service-polls/pull/56',
'issue_url': '/api/v3/repos/m6web/service-polls/issues/56',
'number': 56,
'title': 'PR 56',
'state': 'open',
Expand All @@ -143,11 +150,15 @@ describe('Test GTR screen', function () {
'full_name': 'm6web/service-polls',
'name': 'service-polls'
}
},
'milestone': {
'title': 'release-1.0.0'
}
}]);
backend.whenGET('/api/v3/repos/replay/bundle-polls-client/pulls').respond([{
'id': 5895,
'html_url': 'http://example.com/replay/bundle-polls-client/pull/49',
'issue_url': '/api/v3/repos/replay/bundle-polls-client/issues/49',
'number': 49,
'title': 'PR 49',
'state': 'open',
Expand All @@ -166,11 +177,13 @@ describe('Test GTR screen', function () {
'full_name': 'replay/bundle-polls-client',
'name': 'bundle-polls-client'
}
}
},
'milestone': null
},
{
'id': 5896,
'html_url': 'http://example.com/replay/bundle-polls-client/pull/50',
'issue_url': '/api/v3/repos/replay/bundle-polls-client/issues/50',
'number': 50,
'title': 'PR 50',
'state': 'open',
Expand All @@ -189,7 +202,8 @@ describe('Test GTR screen', function () {
'full_name': 'replay/bundle-polls-client',
'name': 'bundle-polls-client'
}
}
},
'milestone': null
}]);

//Statuses
Expand Down Expand Up @@ -220,6 +234,14 @@ describe('Test GTR screen', function () {
'state': 'success'
}]);

// Labels
backend.whenGET('/api/v3/repos/m6web/service-polls/issues/55/labels').respond([
{
'name': 'need_review',
'color': 'b60205'
}
]);

// Others
backend.whenGET(/.*/).passThrough();
});
Expand Down Expand Up @@ -288,7 +310,7 @@ describe('Test GTR screen', function () {

expect(pulls).toEqual([{
index: 0,
text: '#55 PR 55\nm6web/service-polls 28/08/2014',
text: '#55 PR 55 need_review\nm6web/service-polls 28/08/2014',
class: '',
avatar: 'http://example.com/papy.jpg',
pullUrl: 'http://example.com/m6web/service-polls/pull/55'
Expand All @@ -310,14 +332,14 @@ describe('Test GTR screen', function () {
},
{
index: 1,
text: '#55 PR 55\nm6web/service-polls 28/08/2014',
text: '#55 PR 55\nrelease-1.1.0 m6web/service-polls 28/08/2014',
class: '',
avatar: 'http://example.com/papy.jpg',
pullUrl: 'http://example.com/m6web/service-polls/pull/55'
},
{
index: 2,
text: '#56 PR 56\nm6web/service-polls 28/10/2014',
text: '#56 PR 56\nrelease-1.0.0 m6web/service-polls 28/10/2014',
class: 'success',
avatar: 'http://example.com/bieber.jpg',
pullUrl: 'http://example.com/m6web/service-polls/pull/56'
Expand Down

0 comments on commit bd99aa5

Please sign in to comment.