1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: use Budabot\Core\AutoInject;
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
21: class GitController extends AutoInject {
22:
23: 24: 25: 26:
27: public $moduleName;
28:
29:
30: public function setup() {
31: $this->settingManager->add($this->moduleName, "gitpath", "Path to git binary", "edit", "text", "git", "git;/usr/bin/git;C:/Program Files (x86)/Git/bin/git.exe");
32: }
33:
34: 35: 36: 37:
38: public function gitIncomingCommand($message, $channel, $sender, $sendto, $args) {
39: $gitpath = $this->settingManager->get('gitpath');
40: $command = "$gitpath fetch origin 2>&1";
41: $this->executeCommand($command);
42:
43: $command = "$gitpath log master ...origin/master 2>&1";
44:
45: $blob = $this->executeCommand($command);
46: $msg = $this->text->makeBlob("git incoming", $blob);
47: $sendto->reply($msg);
48: }
49:
50: 51: 52: 53:
54: public function gitDiffCommand($message, $channel, $sender, $sendto, $args) {
55: $gitpath = $this->settingManager->get('gitpath');
56: $command = "$gitpath fetch origin 2>&1";
57: $this->executeCommand($command);
58:
59: $command = "$gitpath diff --stat HEAD ...origin/master 2>&1";
60:
61: $blob = $this->executeCommand($command);
62: $msg = $this->text->makeBlob("git diff", $blob);
63: $sendto->reply($msg);
64: }
65:
66: 67: 68: 69:
70: public function gitPullCommand($message, $channel, $sender, $sendto, $args) {
71: $gitpath = $this->settingManager->get('gitpath');
72: $command = "$gitpath pull origin master 2>&1";
73:
74: $blob = $this->executeCommand($command);
75: $msg = $this->text->makeBlob("git pull", $blob);
76: $sendto->reply($msg);
77: }
78:
79: 80: 81: 82:
83: public function gitLogCommand($message, $channel, $sender, $sendto, $args) {
84: $gitpath = $this->settingManager->get('gitpath');
85: $command = "$gitpath log -n 20 2>&1";
86:
87: $blob = $this->executeCommand($command);
88: $msg = $this->text->makeBlob("git log", $blob);
89: $sendto->reply($msg);
90: }
91:
92: 93: 94: 95:
96: public function gitStatusCommand($message, $channel, $sender, $sendto, $args) {
97: $gitpath = $this->settingManager->get('gitpath');
98: $command = "$gitpath status 2>&1";
99:
100: $blob = $this->executeCommand($command);
101: $msg = $this->text->makeBlob("git status", $blob);
102: $sendto->reply($msg);
103: }
104:
105: private function executeCommand($command) {
106: $output = array();
107: $return_var = '';
108: exec($command, $output, $return_var);
109:
110: $blob = $command . "\n\n";
111: $blob .= implode("\n", $output);
112: return $blob;
113: }
114: }
115: