Skip to content

Commit 68feb84

Browse files
committed
Merge pull request #11 from weaverryan/auto_status_bug_issues
Auto-adding "Needs Review" to Bug Issues
2 parents 182080b + 8c9da62 commit 68feb84

21 files changed

+1291
-435
lines changed

app/config/config_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
imports:
22
- { resource: config_dev.yml }
3+
- { resource: services_test.yml }
34

45
framework:
56
test: ~

app/config/services.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ parameters:
44
# parameter_name: value
55

66
services:
7-
app.github.status_manager:
8-
class: AppBundle\GitHub\StatusManager
9-
arguments: []
10-
11-
app.github_client:
7+
app.github.client:
128
class: Github\Client
139
arguments: []
1410
calls:
@@ -17,6 +13,23 @@ services:
1713
- http_token
1814
- %github_token%
1915

20-
app.issue_status_changer:
21-
class: AppBundle\GitHub\IssueStatusChanger
22-
arguments: ['@app.github_client', '%repository_username%', '%repository_name%']
16+
app.github.issues_api:
17+
class: Github\Api\Issue
18+
factory: ['@app.github.client', api]
19+
arguments: [issue]
20+
21+
app.github.labels_api:
22+
class: Github\Api\Issue\Labels
23+
factory: ['@app.github.issues_api', labels]
24+
25+
app.github.cached_labels_api:
26+
class: AppBundle\Issues\GitHub\CachedLabelsApi
27+
arguments: ['@app.github.labels_api', '%repository_username%', '%repository_name%']
28+
29+
app.status_api:
30+
class: AppBundle\Issues\GitHub\GitHubStatusApi
31+
arguments: ['@app.github.cached_labels_api', '%repository_username%', '%repository_name%']
32+
33+
app.issue_listener:
34+
class: AppBundle\Issues\IssueListener
35+
arguments: ['@app.status_api']

app/config/services_test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
imports:
3+
- { resource: services.yml }
4+
5+
services:
6+
app.status_api:
7+
class: AppBundle\Issues\NullStatusApi

src/AppBundle/Controller/DefaultController.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace AppBundle\Controller;
44

5-
use AppBundle\GitHub\StatusManager;
5+
use AppBundle\Issues\IssueListener;
6+
use AppBundle\Issues\Status;
67
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
78
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
89

@@ -14,12 +15,7 @@ class DefaultController extends Controller
1415
public function homepageAction()
1516
{
1617
return $this->render('default/homepage.html.twig', [
17-
'needsReviewUrl' => sprintf(
18-
'https://github.com/%s/%s/labels/%s',
19-
$this->container->getParameter('repository_username'),
20-
$this->container->getParameter('repository_name'),
21-
rawurlencode(StatusManager::getLabelForStatus(StatusManager::STATUS_NEEDS_REVIEW))
22-
)
18+
'needsReviewUrl' => $this->get('app.status_api')->getNeedsReviewUrl(),
2319
]);
2420
}
2521
}

src/AppBundle/Controller/WebhookController.php

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace AppBundle\Controller;
44

5-
use AppBundle\GitHub\StatusManager;
5+
use AppBundle\Issues\IssueListener;
66
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
77
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
88
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
@@ -23,15 +23,44 @@ public function githubAction(Request $request)
2323
}
2424

2525
$event = $request->headers->get('X-Github-Event');
26+
$listener = $this->get('app.issue_listener');
2627

2728
switch ($event) {
2829
case 'issue_comment':
29-
$responseData = $this->handleIssueCommentEvent($data);
30+
$responseData = [
31+
'issue' => $data['issue']['number'],
32+
'status_change' => $listener->handleCommentAddedEvent(
33+
$data['issue']['number'],
34+
$data['comment']['body']
35+
),
36+
];
3037
break;
3138
case 'pull_request':
3239
switch ($data['action']) {
3340
case 'opened':
34-
$responseData = $this->handlePullRequestCreateEvent($data);
41+
$responseData = [
42+
'pull_request' => $data['pull_request']['number'],
43+
'status_change' => $listener->handlePullRequestCreatedEvent(
44+
$data['pull_request']['number']
45+
),
46+
];
47+
break;
48+
default:
49+
$responseData = [
50+
'unsupported_action' => $data['action']
51+
];
52+
}
53+
break;
54+
case 'issues':
55+
switch ($data['action']) {
56+
case 'labeled':
57+
$responseData = [
58+
'issue' => $data['issue']['number'],
59+
'status_change' => $listener->handleLabelAddedEvent(
60+
$data['issue']['number'],
61+
$data['label']['name']
62+
),
63+
];
3564
break;
3665
default:
3766
$responseData = [
@@ -53,41 +82,4 @@ public function githubAction(Request $request)
5382

5483
// log something to the database?
5584
}
56-
57-
private function handleIssueCommentEvent(array $data)
58-
{
59-
$commentText = $data['comment']['body'];
60-
$issueNumber = $data['issue']['number'];
61-
62-
$newStatus = $this->get('app.github.status_manager')
63-
->getStatusChangeFromComment($commentText);
64-
65-
// hacky way to not actually try to talk to GitHub when testing
66-
if ($this->container->getParameter('kernel.environment') != 'test') {
67-
$this->get('app.issue_status_changer')
68-
->setIssueStatusLabel($issueNumber, $newStatus);
69-
}
70-
71-
return [
72-
'issue' => $issueNumber,
73-
'status_change' => $newStatus,
74-
];
75-
}
76-
77-
private function handlePullRequestCreateEvent(array $data)
78-
{
79-
$prNumber = $data['pull_request']['number'];
80-
$newStatus = StatusManager::STATUS_NEEDS_REVIEW;
81-
82-
// hacky way to not actually try to talk to GitHub when testing
83-
if ($this->container->getParameter('kernel.environment') != 'test') {
84-
$this->get('app.issue_status_changer')
85-
->setIssueStatusLabel($prNumber, $newStatus);
86-
}
87-
88-
return [
89-
'pull_request' => $prNumber,
90-
'status_change' => $newStatus,
91-
];
92-
}
9385
}

src/AppBundle/GitHub/IssueStatusChanger.php

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/AppBundle/GitHub/StatusManager.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)