Skip to content

Commit 114c50f

Browse files
committed
Merge pull request #33 from carsonbot/multiple_repositories
Multiple repositories
2 parents 26984df + 9b7b2bd commit 114c50f

27 files changed

+950
-429
lines changed

app/Resources/views/default/homepage.html.twig

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,24 @@
1111

1212
<h1>Carson: The Issue Butler</h1>
1313

14-
<div>
15-
<a href="{{ needsReviewUrl }}" class="btn btn-primary">Find "Needs Review" issues and pull requests</a>
16-
</div>
17-
14+
<table class="table">
15+
<thead>
16+
<tr>
17+
<th>Repository</th>
18+
<th>Needs Review issues &amp; pull requests</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
{% for repository in repositories %}
23+
<tr>
24+
<td>{{ repository.vendor }}/{{ repository.name }}</td>
25+
<td>
26+
<a href="{{ repository.needsReviewUrl }}" class="btn btn-xs btn-default">Needs Review Issues</a>
27+
</td>
28+
</tr>
29+
{% endfor %}
30+
</tbody>
31+
</table>
1832
</div>
1933
</div>
2034
</div>

app/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Composer\Autoload\ClassLoader;
55

66
/**
7-
* @var ClassLoader $loader
7+
* @var ClassLoader
88
*/
99
$loader = require __DIR__.'/../vendor/autoload.php';
1010

app/config/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ imports:
22
- { resource: parameters.yml }
33
- { resource: security.yml }
44
- { resource: services.yml }
5+
- { resource: github.yml }
56

67
# Put parameters here that don't need to change on each machine where the app is deployed
78
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration

app/config/github.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# listener services that you can opt into for a repository
2+
services:
3+
app.subscriber.status_change_by_comment_subscriber:
4+
class: AppBundle\Subscriber\StatusChangeByCommentSubscriber
5+
arguments:
6+
- '@app.status_api'
7+
8+
app.subscriber.needs_review_new_pr_subscriber:
9+
class: AppBundle\Subscriber\NeedsReviewNewPRSubscriber
10+
arguments:
11+
- '@app.status_api'
12+
13+
app.subscriber.bug_label_new_issue_subscriber:
14+
class: AppBundle\Subscriber\BugLabelNewIssueSubscriber
15+
arguments:
16+
- '@app.status_api'
17+
18+
parameters:
19+
# point to the main symfony repositories
20+
repositories:
21+
symfony/symfony:
22+
subscribers:
23+
- app.subscriber.status_change_by_comment_subscriber
24+
- app.subscriber.needs_review_new_pr_subscriber
25+
- app.subscriber.bug_label_new_issue_subscriber
26+
# secret: change_me
27+
symfony/symfony-docs:
28+
subscribers:
29+
- app.subscriber.status_change_by_comment_subscriber
30+
- app.subscriber.needs_review_new_pr_subscriber
31+
- app.subscriber.bug_label_new_issue_subscriber
32+
33+
# used in a functional test
34+
weaverryan/symfony:
35+
subscribers:
36+
- app.subscriber.status_change_by_comment_subscriber
37+
- app.subscriber.needs_review_new_pr_subscriber
38+
- app.subscriber.bug_label_new_issue_subscriber

app/config/parameters.yml.dist

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@ parameters:
1919
secret: ThisTokenIsNotSoSecretChangeIt
2020

2121
# token used to update labels on the repository, etc
22-
github_token: XXXX
23-
# point to the symfony/symfony repository
24-
repository_username: symfony
25-
repository_name: symfony
22+
github_token: XXX

app/config/services.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ services:
2424

2525
app.github.cached_labels_api:
2626
class: AppBundle\Issues\GitHub\CachedLabelsApi
27-
arguments: ['@app.github.labels_api', '%repository_username%', '%repository_name%']
27+
arguments: ['@app.github.labels_api']
2828

2929
app.status_api:
3030
class: AppBundle\Issues\GitHub\GitHubStatusApi
31-
arguments: ['@app.github.cached_labels_api', '%repository_username%', '%repository_name%']
31+
arguments: ['@app.github.cached_labels_api']
3232

33-
app.issue_listener:
34-
class: AppBundle\Issues\IssueListener
35-
arguments: ['@app.status_api']
33+
app.github.request_handler:
34+
class: AppBundle\Issues\GitHubRequestHandler
35+
arguments: ['@event_dispatcher', '@app.repository_provider', '@service_container']
36+
37+
app.repository_provider:
38+
class: AppBundle\Repository\Provider\InMemoryRepositoryProvider
39+
arguments: [ '%repositories%' ]

src/AppBundle/Controller/DefaultController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class DefaultController extends Controller
1212
*/
1313
public function homepageAction()
1414
{
15+
$repositories = $this->get('app.repository_provider')->getAllRepositories();
16+
1517
return $this->render('default/homepage.html.twig', [
16-
'needsReviewUrl' => $this->get('app.status_api')->getNeedsReviewUrl(),
18+
'repositories' => $repositories,
1719
]);
1820
}
1921
}

src/AppBundle/Controller/WebhookController.php

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,8 @@ class WebhookController extends Controller
1616
*/
1717
public function githubAction(Request $request)
1818
{
19-
$data = json_decode($request->getContent(), true);
20-
if ($data === null) {
21-
throw new \Exception('Invalid JSON body!');
22-
}
23-
24-
$event = $request->headers->get('X-Github-Event');
25-
$listener = $this->get('app.issue_listener');
26-
27-
switch ($event) {
28-
case 'issue_comment':
29-
$responseData = [
30-
'issue' => $data['issue']['number'],
31-
'status_change' => $listener->handleCommentAddedEvent(
32-
$data['issue']['number'],
33-
$data['comment']['body']
34-
),
35-
];
36-
break;
37-
case 'pull_request':
38-
switch ($data['action']) {
39-
case 'opened':
40-
$responseData = [
41-
'pull_request' => $data['pull_request']['number'],
42-
'status_change' => $listener->handlePullRequestCreatedEvent(
43-
$data['pull_request']['number']
44-
),
45-
];
46-
break;
47-
default:
48-
$responseData = [
49-
'unsupported_action' => $data['action'],
50-
];
51-
}
52-
break;
53-
case 'issues':
54-
switch ($data['action']) {
55-
case 'labeled':
56-
$responseData = [
57-
'issue' => $data['issue']['number'],
58-
'status_change' => $listener->handleLabelAddedEvent(
59-
$data['issue']['number'],
60-
$data['label']['name']
61-
),
62-
];
63-
break;
64-
default:
65-
$responseData = [
66-
'unsupported_action' => $data['action'],
67-
];
68-
}
69-
break;
70-
default:
71-
$responseData = [
72-
'unsupported_event' => $event,
73-
];
74-
}
19+
$responseData = $this->get('app.github.request_handler')->handle($request);
7520

7621
return new JsonResponse($responseData);
77-
78-
// 1 read in what event they have
79-
// 2 perform some action
80-
// 3 return JSON
81-
82-
// log something to the database?
8322
}
8423
}

src/AppBundle/Event/GitHubEvent.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace AppBundle\Event;
4+
5+
use AppBundle\Repository\Repository;
6+
use Symfony\Component\EventDispatcher\Event;
7+
8+
/**
9+
* GitHubEvent.
10+
*
11+
* @author Jules Pietri <jules@heahprod.com>
12+
*/
13+
class GitHubEvent extends Event
14+
{
15+
protected $responseData = array();
16+
17+
private $data;
18+
private $repository;
19+
20+
public function __construct(array $data, Repository $repository)
21+
{
22+
$this->data = $data;
23+
$this->repository = $repository;
24+
}
25+
26+
public function getData()
27+
{
28+
return $this->data;
29+
}
30+
31+
/**
32+
* @return Repository
33+
*/
34+
public function getRepository()
35+
{
36+
return $this->repository;
37+
}
38+
39+
public function getResponseData()
40+
{
41+
return $this->responseData;
42+
}
43+
44+
public function setResponseData(array $responseData)
45+
{
46+
foreach ($responseData as $k => $v) {
47+
$this->responseData[$k] = $v;
48+
}
49+
}
50+
}

src/AppBundle/GitHubEvents.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace AppBundle;
4+
5+
/**
6+
* GitHubEvents.
7+
*
8+
* {@link https://developer.github.com/v3/activity/events/types/}
9+
*
10+
* @author Jules Pietri <jules@heahprod.com>
11+
*/
12+
final class GitHubEvents
13+
{
14+
/** @Event('\AppBundle\Event\GitHubEvent') */
15+
const COMMIT_COMMENT = 'github.commit_comment';
16+
17+
/** @Event('\AppBundle\Event\GitHubEvent') */
18+
const CREATE = 'github.create';
19+
20+
/** @Event('\AppBundle\Event\GitHubEvent') */
21+
const DELETE = 'github.delete';
22+
23+
/** @Event('\AppBundle\Event\GitHubEvent') */
24+
const DEPLOYMENT = 'github.deployment';
25+
26+
/** @Event('\AppBundle\Event\GitHubEvent') */
27+
const DEPLOYMENT_STATUS = 'github.deployment_status';
28+
29+
/** @Event('\AppBundle\Event\GitHubEvent') */
30+
const FORK = 'github.fork';
31+
32+
/** @Event('\AppBundle\Event\GitHubEvent') */
33+
const GOLLUM = 'github.gollum';
34+
35+
/** @Event('\AppBundle\Event\GitHubEvent') */
36+
const ISSUE_COMMENT = 'github.issue_comment';
37+
38+
/** @Event('\AppBundle\Event\GitHubEvent') */
39+
const ISSUES = 'github.issues';
40+
41+
/** @Event('\AppBundle\Event\GitHubEvent') */
42+
const MEMBER = 'github.member';
43+
44+
/** @Event('\AppBundle\Event\GitHubEvent') */
45+
const MEMBERSHIP = 'github.membership';
46+
47+
/** @Event('\AppBundle\Event\GitHubEvent') */
48+
const PAGE_BUILD = 'github.page_build';
49+
50+
/** @Event('\AppBundle\Event\GitHubEvent') */
51+
const IS_PUBLIC = 'github.public';
52+
53+
/** @Event('\AppBundle\Event\GitHubEvent') */
54+
const PR_REVIEW_COMMENT = 'github.pull_request_review_comment';
55+
56+
/** @Event('\AppBundle\Event\GitHubEvent') */
57+
const PULL_REQUEST = 'github.pull_request';
58+
59+
/** @Event('\AppBundle\Event\GitHubEvent') */
60+
const PUSH = 'github.push';
61+
62+
/** @Event('\AppBundle\Event\GitHubEvent') */
63+
const REPOSITORY = 'github.repository';
64+
65+
/** @Event('\AppBundle\Event\GitHubEvent') */
66+
const RELEASE = 'github.release';
67+
68+
/** @Event('\AppBundle\Event\GitHubEvent') */
69+
const STATUS = 'github.status';
70+
71+
/** @Event('\AppBundle\Event\GitHubEvent') */
72+
const TEAM_ADD = 'github.team_add';
73+
74+
/** @Event('\AppBundle\Event\GitHubEvent') */
75+
const WATCH = 'github.watch';
76+
}

0 commit comments

Comments
 (0)