diff --git a/docs/AutoComplete.php b/docs/AutoComplete.php new file mode 100644 index 0000000..23b2f2c --- /dev/null +++ b/docs/AutoComplete.php @@ -0,0 +1,21 @@ + + + +### Request + +URL: + +Method: + +Query: + + +### User + + $value) : ?> +: + + + +### Additional Data + +```php + +``` + + +View the event: + +--- + +**关闭issue后记得关闭sentry的event** diff --git a/src/Controller/SentryNotifications.php b/src/Controller/SentryNotifications.php new file mode 100644 index 0000000..5b00f76 --- /dev/null +++ b/src/Controller/SentryNotifications.php @@ -0,0 +1,15 @@ +sentryNotification->createIssue($this->request->getContent()); + + return $this->response->json($ret); + } +} diff --git a/src/Service/SentryNotification.php b/src/Service/SentryNotification.php new file mode 100644 index 0000000..00b2cdb --- /dev/null +++ b/src/Service/SentryNotification.php @@ -0,0 +1,91 @@ +assignees; + } + + $value = $payload['event']['sentry.interfaces.Exception']['values'][0]; + list($file, $line) = explode(':', $value['module']); + + exec(sprintf('git log -1 --pretty=%%an -L %s,%s:%s', $line, $line, $file), $output); + if (isset($output[0])) { + return $output[0]; + } + + return $this->assignees; + } + + /** + * @param string $payload + * @return array + */ + public function createIssue($payload) + { + $payload = json_decode($payload, true); + if (!$payload || !isset($payload['message'])) { + return $this->err('Invalid payload'); + } + + $title = sprintf('[%s]告警: %s', date('y-m-d'), $payload['message']); + + $http = $payload['event']['sentry.interfaces.Http']; + $user = $payload['event']['sentry.interfaces.User']; + $body = $this->view->render('sentryNotifications/issue-tpl.php', [ + 'payload' => $payload, + 'http' => $http, + 'user' => $user, + ]); + + $assignees = $this->guestAssignees($payload); + + $http = $this->http([ + 'url' => 'https://api.github.com/repos/' . $this->githubRepo . '/issues', + 'method' => 'post', + 'dataType' => 'json', + 'userAgent' => 'Wei/0.9.X', + 'errorLevel' => 'debug', + 'headers' => [ + 'Authorization' => 'token ' . $this->githubToken, + ], + 'data' => json_encode([ + 'title' => $title, + 'body' => $body, + 'assignees' => [$assignees], + 'labels' => $this->issueLabels, + ]), + ]); + + if ($http->isSuccess()) { + return $this->suc(['http' => $http]); + } else { + return $this->err(['http' => $http]); + } + } +}