Skip to content

Commit c83b212

Browse files
author
Renato Marinho
authored
Merge branch 'master' into feature-createIssue-ajax
2 parents 8bcbfed + 4b26b8c commit c83b212

22 files changed

+457
-146
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ PROXY_METHOD=
2727
PROXY_SERVER=
2828
PROXY_USER=
2929
PROXY_PASS=
30+
31+
SLACK_CHANNEL=channel-name
32+
SLACK_BOT_NAME=bot-name
33+
SLACK_WEBHOOK=endpoint

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ DB_PASSWORD=XXXXX
156156
**Remember**: Create the database for GitScrum before run artisan command.
157157

158158
```
159-
php artisan migrate --seed
159+
php artisan migrate
160+
php artisan db:seed --class=SettingSeeder
160161
```
161162

162163
#### Github

app/Contracts/SlackInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace GitScrum\Contracts;
4+
5+
interface SlackInterface
6+
{
7+
public function send($content, $type = 0);
8+
}

app/Http/Controllers/Web/AuthController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Socialite;
1414
use Auth;
1515
use SocialiteProviders\Manager\Exception\InvalidArgumentException;
16+
use Session;
1617

1718
class AuthController extends Controller
1819
{

app/Http/Controllers/Web/IssueController.php

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace GitScrum\Http\Controllers\Web;
1010

1111
use Illuminate\Http\Request;
12+
use GitScrum\Contracts\SlackInterface as Slack;
1213
use GitScrum\Http\Requests\IssueRequest;
1314
use GitScrum\Models\Sprint;
1415
use GitScrum\Models\Issue;
@@ -22,58 +23,41 @@ class IssueController extends Controller
2223
{
2324
public function index($slug)
2425
{
25-
if ($slug) {
26-
$sprint = Sprint::slug($slug)
27-
->with('issues.user')
28-
->with('issues.users')
29-
->with('issues.commits')
30-
->with('issues.statuses')
31-
->with('issues.status')
32-
->with('issues.comments')
33-
->with('issues.attachments')
34-
->with('issues.type')
35-
->with('issues.productBacklog')
36-
->with('issues.sprint')
37-
->with('issues.configEffort')
38-
->first();
39-
40-
//when viewing from sprint planning, issues need to be passed in an array indexed by their status, so they can be put in the appropriate kanban columns
41-
$is = $sprint->issues;
42-
$issues = array();
43-
foreach($is as $i) {
44-
$issues[$i->config_status_id] = array();
45-
}
46-
foreach($is as $i) {
47-
$issues[$i->config_status_id][] = $i;
48-
}
49-
} else {
50-
$sprint = null;
51-
$issues = Auth::user()->issues()
52-
->with('user')
53-
->with('users')
54-
->with('commits')
55-
->with('statuses')
56-
->with('status')
57-
->with('comments')
58-
->with('attachments')
59-
->with('type')
60-
->with('productBacklog')
61-
->with('sprint')
62-
->with('configEffort')
63-
->get()
64-
->sortBy('position')->groupBy('config_status_id');
65-
}
66-
67-
$configStatus = ConfigStatus::type('issues')->get();
26+
[$sprint,$issues] = $this->sprintWithIssues($slug);
6827

6928
if (!is_null($sprint) && !count($sprint)) {
7029
return redirect()->route('sprints.index');
7130
}
7231

7332
return view('issues.index')
7433
->with('sprint', $sprint)
75-
->with('issues', $issues)
76-
->with('configStatus', $configStatus);
34+
->with('issues', $issues->sortBy('position')->groupBy('config_issue_effort_id'))
35+
->with('configStatus', ConfigStatus::type('issues')->get());
36+
}
37+
38+
private function sprintWithIssues($slug)
39+
{
40+
if ($slug)
41+
{
42+
$sprint = $this->eagerLoad(Sprint::slug($slug),'issues.')->first();
43+
44+
return [$sprint , $sprint->issues];
45+
}
46+
47+
return [ null , $this->eagerLoad(Auth::user()->issues())->get()];
48+
}
49+
50+
private function eagerLoad($query , $relation = '')
51+
{
52+
$eagerLoaders = collect(['user','users','commits','statuses',
53+
'comments','attachments','type',
54+
'productBacklog','sprint','configEffort']);
55+
56+
$eagerLoaders->each(function($loader) use (&$query,$relation){
57+
$query = $query->with($relation . $loader);
58+
});
59+
60+
return $query;
7761
}
7862

7963
public function create($scope, $slug, $parent_id = null)
@@ -137,7 +121,7 @@ public function update(IssueRequest $request, $slug)
137121
->with('success', trans('gitscrum.congratulations-the-issue-has-been-edited-with-successfully'));
138122
}
139123

140-
public function statusUpdate(Request $request, $slug = null, $status = 0)
124+
public function statusUpdate(Request $request, Slack $slack, $slug = null, $status = 0)
141125
{
142126
$request->status_id = $request->status_id ?? $status;
143127

@@ -158,6 +142,17 @@ public function statusUpdate(Request $request, $slug = null, $status = 0)
158142

159143
resolve('IssueService')->setRequest($request)->updateStatus();
160144

145+
$issue = Issue::slug($slug)->firstOrFail();
146+
147+
$content = [
148+
'title' => "{$issue->title}",
149+
'url' => url("issues/status-update/{$slug}"),
150+
'updated_by' => Auth::user()->slack_username,
151+
'status' => $status,
152+
];
153+
154+
$slack->send($content, 2);
155+
161156
return back()->with('success', trans('gitscrum.updated-successfully'));
162157
}
163158

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace GitScrum\Http\Controllers\Web;
4+
5+
use Auth;
6+
use Illuminate\Http\Request;
7+
8+
class SlackUserController extends Controller
9+
{
10+
/**
11+
* Update the specified resource in storage.
12+
*
13+
* @param \Illuminate\Http\Request $request
14+
*
15+
*/
16+
public function update(Request $request)
17+
{
18+
$user = Auth::user();
19+
$user->slack_username = $request->slack_username;
20+
$user->save();
21+
22+
return back()->with('success', trans('gitscrum.updated-successfully'));
23+
}
24+
}

app/Http/Controllers/Web/SprintController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public function show($slug)
103103
return redirect()->route('sprints.index');
104104
}
105105

106+
if ($sprint->user_id !== Auth()->user()->id && $sprint->is_private) {
107+
return redirect()->route('sprints.index')
108+
->with('error', trans('gitscrum.private-sprint'));
109+
}
110+
106111
$configStatus = ConfigStatus::type('sprints')->get();
107112

108113
return view('sprints.show')

app/Http/Controllers/Web/UserIssueController.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
namespace GitScrum\Http\Controllers\Web;
1010

11-
use Illuminate\Http\Request;
11+
use Auth;
12+
use GitScrum\Contracts\SlackInterface as Slack;
1213
use GitScrum\Models\Issue;
1314
use GitScrum\Models\User;
15+
use Illuminate\Http\Request;
1416

1517
class UserIssueController extends Controller
1618
{
@@ -93,7 +95,7 @@ public function edit($id)
9395
*
9496
* @return \Illuminate\Http\Response
9597
*/
96-
public function update(Request $request, $slug)
98+
public function update(Request $request, $slug, Slack $slack)
9799
{
98100
$members = $request->input('members');
99101

@@ -103,6 +105,21 @@ public function update(Request $request, $slug)
103105
$issue->users()->sync($members);
104106

105107
if (!$request->ajax()) {
108+
$users = User::whereIn('id', $members)->select('slack_username')->get();
109+
$slackUsers = [];
110+
111+
foreach ($users as $user) {
112+
$slackUsers[] = $user->slack_username;
113+
}
114+
115+
$content = [
116+
'title' => $issue->title,
117+
'assigned_to' => $slackUsers,
118+
'url' => route('issues.show', $issue->slug),
119+
'assigned_by' => Auth::user()->slack_username,
120+
];
121+
$slack->send($content, 1);
122+
106123
return redirect()->back()->with('success', trans('gitscrum.updated-successfully'));
107124
}
108125
}

app/Http/Requests/IssueRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function rules()
3232
{
3333
return [
3434
'title' => 'required|min:2|max:255',
35+
'sprint_id' => 'required|integer',
3536
];
3637
}
3738
/**
@@ -45,6 +46,7 @@ public function messages()
4546
'title.required' => trans('gitscrum.issue-cannot-be-blank'),
4647
'title.min' => trans('gitscrum.issue-must-be-at-least-2-characters'),
4748
'title.max' => trans('gitscrum.issue-must-be-between-2-and-255-characters'),
49+
'sprint_id.required' => trans('gitscrum.sprint-cannot-be-blank'),
4850
];
4951
}
5052

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace GitScrum\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class SlackServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Bootstrap the application services.
11+
*
12+
* @return void
13+
*/
14+
public function boot()
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Register the application services.
21+
*
22+
* @return void
23+
*/
24+
public function register()
25+
{
26+
$this->app->bind('GitScrum\Contracts\SlackInterface', 'GitScrum\Services\SlackService');
27+
}
28+
}

0 commit comments

Comments
 (0)