Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 35 |
ProjectInfoController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 35 |
getGitInfo | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
getGitStatus | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 14 |
|||
getGitCommits | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 12 |
|||
getGitBranch | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ApiGateway\Controllers\ProjectInfo; |
4 | |
5 | use Qmp\Laravel\ApiGateway\Controllers\AbstractApiController; |
6 | |
7 | class ProjectInfoController extends AbstractApiController |
8 | { |
9 | public function getGitInfo() |
10 | { |
11 | return $this->response([ |
12 | 'status' => $this->getGitStatus(), |
13 | 'commits' => $this->getGitCommits() |
14 | ]); |
15 | } |
16 | |
17 | /** |
18 | * @return array |
19 | */ |
20 | private function getGitStatus() |
21 | { |
22 | $statusFile = storage_path('git/status.csv'); |
23 | $status = []; |
24 | |
25 | if (file_exists($statusFile)) { |
26 | $file = fopen($statusFile, "r"); |
27 | while ( ($data = fgetcsv($file)) !== false) { |
28 | |
29 | $row = [ |
30 | 'service' => $data[0], |
31 | 'branch_name' => $data[1], |
32 | 'branch_commit' => $data[2], |
33 | 'tag_name' => $data[3], |
34 | 'tag_commit' => $data[4], |
35 | 'status' => $data[5] |
36 | ]; |
37 | |
38 | array_push($status, $row); |
39 | } |
40 | fclose($file); |
41 | } |
42 | |
43 | return $status; |
44 | } |
45 | |
46 | /** |
47 | * @return array |
48 | */ |
49 | private function getGitCommits() |
50 | { |
51 | $commit = []; |
52 | $commitFile = storage_path('git/commit.csv'); |
53 | if (file_exists($commitFile)) { |
54 | $file = fopen($commitFile, "r"); |
55 | while ( ($data = fgetcsv($file)) !== false) { |
56 | |
57 | $row = [ |
58 | 'hash' => $data[0], |
59 | 'author' => $data[1], |
60 | 'timestamp' => $data[2], |
61 | 'message' => $data[3], |
62 | ]; |
63 | |
64 | array_push($commit, $row); |
65 | } |
66 | fclose($file); |
67 | } |
68 | |
69 | return $commit; |
70 | } |
71 | |
72 | public function getGitBranch() |
73 | { |
74 | $branchFile = storage_path('git/branch.txt'); |
75 | |
76 | $branch = ''; |
77 | if (file_exists($branchFile)) { |
78 | $branch = file_get_contents($branchFile); |
79 | } |
80 | |
81 | return $this->response([ |
82 | 'branch' => $branch |
83 | ]); |
84 | } |
85 | |
86 | } |