Skip to content
This repository was archived by the owner on Apr 12, 2020. It is now read-only.

Commit 79ed6bb

Browse files
committed
compare on branches page
1 parent 44310d7 commit 79ed6bb

8 files changed

Lines changed: 81 additions & 39 deletions

File tree

src/Gitonomy/Bundle/WebsiteBundle/Controller/ProjectController.php

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,14 @@ public function treeAction($slug, $reference, $path)
221221

222222
public function branchesAction($slug)
223223
{
224-
$project = $this->getProject($slug);
225-
$repository = $this->getGitRepository($project);
226-
$branches = $repository->getReferences()->getBranches();
227-
228-
usort($branches, function($left, $right) {
229-
return $left->getCommit()->getAuthorDate() < $right->getCommit()->getAuthorDate();
230-
});
224+
$project = $this->getProject($slug);
225+
$rows = $this->getBranchesWithActivity($project);
226+
$defaultBranch = $this->getGitRepository($project)->getReferences()->getBranch($project->getDefaultBranch());
231227

232228
return $this->render('GitonomyWebsiteBundle:Project:branches.html.twig', array(
233-
'project' => $project,
234-
'branches' => $branches,
229+
'project' => $project,
230+
'rows' => $rows,
231+
'defaultBranch' => $defaultBranch,
235232
));
236233
}
237234

@@ -446,28 +443,8 @@ public function deleteAction(Request $request, $slug)
446443

447444
public function _branchActivityAction($project, $route, $reference = null, $path = null, $withAll = false)
448445
{
449-
$project = $this->getProject($project);
450-
$repository = $this->getGitRepository($project);
451-
$rows = array();
452-
$references = $repository->getReferences();
453-
454-
$against = $references->getBranch(null === $reference ? $project->getDefaultBranch() : $reference);
455-
456-
foreach ($references->getBranches() as $branch) {
457-
$logBehind = $repository->getLog($branch->getFullname().'..'.$against->getFullname());
458-
$logAbove = $repository->getLog($against->getFullname().'..'.$branch->getFullname());
459-
460-
$rows[] = array(
461-
'branch' => $branch,
462-
'above' => count($logAbove->getCommits()),
463-
'behind' => count($logBehind->getCommits()),
464-
'lastModification' => $branch->getLastModification(),
465-
);
466-
}
467-
468-
usort($rows, function ($left, $right) {
469-
return $left['lastModification']->getTimestamp() < $right['lastModification']->getTimestamp();
470-
});
446+
$project = $this->getProject($project);
447+
$rows = $this->getBranchesWithActivity($project, $reference);
471448

472449
return $this->render('GitonomyWebsiteBundle:Project:_branchActivity.html.twig', array(
473450
'project' => $project,
@@ -497,4 +474,34 @@ protected function getProject($slug)
497474

498475
return $project;
499476
}
477+
478+
protected function getBranchesWithActivity(Project $project, $reference = null)
479+
{
480+
$repository = $this->getGitRepository($project);
481+
$references = $repository->getReferences();
482+
483+
if (null === $reference) {
484+
$reference = $project->getDefaultBranch();
485+
}
486+
487+
$against = $references->getBranch(null === $reference ? $project->getDefaultBranch() : $reference);
488+
489+
foreach ($references->getBranches() as $branch) {
490+
$logBehind = $repository->getLog($branch->getFullname().'..'.$against->getFullname());
491+
$logAbove = $repository->getLog($against->getFullname().'..'.$branch->getFullname());
492+
493+
$rows[] = array(
494+
'branch' => $branch,
495+
'above' => count($logAbove->getCommits()),
496+
'behind' => count($logBehind->getCommits()),
497+
'lastModification' => $branch->getLastModification(),
498+
);
499+
}
500+
501+
usort($rows, function ($left, $right) {
502+
return $left['lastModification']->getTimestamp() < $right['lastModification']->getTimestamp();
503+
});
504+
505+
return $rows;
506+
}
500507
}

src/Gitonomy/Bundle/WebsiteBundle/Resources/public/css/global.sass

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ i.symbol
2424
table.table .btn-group
2525
height: 1em
2626
margin-top: -3px
27+
28+
span.behind
29+
color: red
30+
31+
span.above
32+
color: green

src/Gitonomy/Bundle/WebsiteBundle/Resources/public/css/project/newsfeed.sass

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ $cell: 50px
3131
span.behind , span.above
3232
font-size: 0.7em
3333

34-
span.behind
35-
color: red
36-
37-
span.above
38-
color: green
39-
4034
.btn-group.open
4135
.dropdown-toggle
4236
box-shadow: none

src/Gitonomy/Bundle/WebsiteBundle/Resources/translations/project_branches.en_US.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ table.column.branch: "Branch"
33
table.column.last_commit: "Last commit"
44
table.column.author: "Author"
55
table.column.date: "Date"
6+
table.column.diff: "Diff"

src/Gitonomy/Bundle/WebsiteBundle/Resources/translations/project_branches.fr_FR.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ table.column.branch: "Branche"
33
table.column.last_commit: "Dernier commit"
44
table.column.author: "Auteur"
55
table.column.date: "Date"
6+
table.column.diff: "Diff"

src/Gitonomy/Bundle/WebsiteBundle/Resources/views/Project/_branchActivity.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% for row in branches %}
1010
<li>
1111
<a href="{{ path(route, { slug: project.slug, reference: row.branch.name, path: path }) }}">
12-
{% if reference != row.branch.name %}
12+
{% if row.behind and row.above %}
1313
<div class="label pull-right">
1414
<span class="behind">-{{ row.behind }}</span>
1515
<span class="above">+{{ row.above }}</span>

src/Gitonomy/Bundle/WebsiteBundle/Resources/views/Project/branches.html.twig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
<th>{{ 'table.column.last_commit'|trans }}</th>
1616
<th>{{ 'table.column.author'|trans }}</th>
1717
<th>{{ 'table.column.date'|trans }}</th>
18+
<th>{{ 'table.column.diff'|trans }}</th>
1819
</tr>
1920
</thead>
2021
<tbody>
21-
{% for branch in branches %}
22+
{% for row in rows %}
23+
{% set branch = row.branch %}
2224
<tr>
2325
<td>{{ branch.name }}</td>
2426
<td><a href="{{ path('project_commit', {slug: project.slug, hash: branch.commit.hash}) }}">{{ branch.commit.shortHash }}</a> {{ branch.commit.shortMessage }}</td>
@@ -27,6 +29,16 @@
2729
{{ branch.commit.authorName }}
2830
</td>
2931
<td>{{ branch.commit.authorDate.format('Y-m-d H:i:s') }}</td>
32+
<td>
33+
{% if row.behind and row.above %}
34+
<div class="pull-right">
35+
<a href="{{ path('project_compare', {slug: project.slug, revision: defaultBranch.commitHash~'..'~branch.commitHash}) }}">
36+
<span class="behind">-{{ row.behind }}</span>
37+
<span class="above">+{{ row.above }}</span>
38+
</a>
39+
</div>
40+
{% endif %}
41+
</td>
3042
</tr>
3143
{% else %}
3244
<tr>

src/Gitonomy/Bundle/WebsiteBundle/Tests/Controller/ProjectControllerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ public function testTreeHistory()
140140
$this->assertCount(1, $crawler->filter('a:contains("d8930cd")'));
141141
}
142142

143+
public function testBranches()
144+
{
145+
$this->client->connect('alice');
146+
147+
$crawler = $this->client->request('GET', '/projects/foobar/branches');
148+
$response = $this->client->getResponse();
149+
150+
$this->assertEquals(200, $response->getStatusCode());
151+
$this->assertCount(1, $crawler->filter('a:contains("10b5d71")'));
152+
}
153+
154+
public function testTags()
155+
{
156+
$this->client->connect('alice');
157+
158+
$crawler = $this->client->request('GET', '/projects/foobar/tags');
159+
$response = $this->client->getResponse();
160+
161+
$this->assertEquals(200, $response->getStatusCode());
162+
}
163+
143164
public function testCompare()
144165
{
145166
$this->client->connect('alice');

0 commit comments

Comments
 (0)