function processPushHook($app) { $json = $app->request->getBody(); $hook = json_decode($json, true); $app->log->debug('processPushHook : ' . json_encode($hook, JSON_PRETTY_PRINT)); $u = getGitUserName(2, $app); foreach ($hook['commits'] as $commit) { $app->log->info('Commit : ' . json_encode($commit, JSON_PRETTY_PRINT)); $issueKey = extractIssueKey($commit['message']); if (empty($issueKey)) { continue; } $transitionName = needTransition($commit['message'], $message); try { if (empty($transitionName)) { $comment = new Comment(); $body = sprintf($message, $u->username, $commit['url']); $comment->setBody($body); $issueService = new IssueService(); $ret = $issueService->addComment($issueKey, $comment); } else { $transition = new Transition(); $transition->setTransitionName($transitionName); $body = sprintf($message, $u->username, $transitionName, $commit['url']); $transition->setCommentBody($body); $issueService = new IssueService(); $issueService->transition($issueKey, $transition); } } catch (JIRAException $e) { $app->log->error("add Comment Failed : " . $e->getMessage()); } } $app->response->setStatus(200); }
/** * @param $issueService * @param $issueKey * @param $body * * @return bool|\Exception|\JiraRestApi\JiraException */ public function postPipe($issueService, $issueKey, $body) { try { $comment = new Comment(); $comment->setBody($body)->setVisibility('role', 'Users'); $resp = $issueService->addComment($issueKey, $comment); } catch (JIRAException $e) { return $e; } if (!empty($resp->errorMessages)) { return $resp; } return true; }
private function pushHook(Request $request) { $userController = new UserController(); $hook = $request->json(); // call UserController's method using IoC. $user = \App::make('App\\Http\\Controllers\\UserController')->{'getGitUser'}($hook->get('user_id')); $commits = $hook->get('commits'); // empty commit logs. stop processing. if (is_null($commits) || count($commits) == 0) { Log::info("Empty commit logs. " . json_encode($hook->all(), JSON_PRETTY_PRINT)); return response()->json(['result' => 'Ok', 'issue_count' => 0]); } $issueCount = 0; foreach ($commits as $commit) { Log::debug('Commit : ' . json_encode($commit, JSON_PRETTY_PRINT)); $issueKey = $this->extractIssueKey($commit['message']); if (empty($issueKey)) { Log::debug('Can\'t found issue Key in commit message : ' . $commit['message']); continue; } Log::debug("Found found issue Key({$issueKey}) in commit message : " . $commit['message']); $issueCount++; $transitionName = $this->needTransition($commit['message'], $message); try { if (empty($transitionName)) { $comment = new Comment(); $body = sprintf($message, $user['username'], $commit['url']); $comment->setBody($body); $issueService = new IssueService(new DotEnvConfiguration(base_path())); $ret = $issueService->addComment($issueKey, $comment); } else { $transition = new Transition(); $transition->setTransitionName($transitionName); $body = sprintf($message, $user['username'], $transitionName, $commit['url']); $transition->setCommentBody($body); $issueService = new IssueService(new DotEnvConfiguration(base_path())); $issueService->transition($issueKey, $transition); } } catch (JIRAException $e) { Log::error("add Comment Failed : " . $e->getMessage()); } } return response()->json(['result' => 'Ok', 'issue_count' => $issueCount]); }
/** * @depends testUpdateIssue */ public function testAddcomment($issueKey) { //$this->markTestIncomplete(); try { $comment = new Comment(); $body = <<<COMMENT Adds a new comment to an issue. * Bullet 1 * Bullet 2 ** sub Bullet 1 ** sub Bullet 2 COMMENT; $comment->setBody($body)->setVisibility('role', 'Users'); $issueService = new IssueService(); $ret = $issueService->addComment($issueKey, $comment); print_r($ret); return $issueKey; } catch (JIRAException $e) { $this->assertTrue(false, 'add Comment Failed : ' . $e->getMessage()); } }
private function mergeRequestHook(Request $request) { $userController = new UserController(); $hook = $request->json(); // call UserController's method using IoC. $user = \App::make('App\\Http\\Controllers\\UserController')->{'getGitUser'}($hook->get('user_id')); $attributes = $hook->get('object_attributes'); if (!is_null($attributes)) { $issueKey = $this->extractIssueKey($attributes['title']); if (empty($issueKey)) { Log::debug('Can\'t found issue Key in merge request title : ' . $attributes['title']); } else { Log::debug("Found found issue Key({$issueKey}) in merge request title : " . $attributes['title']); try { $comment = new Comment(); $body = 'Merge Request [' . $attributes['iid'] . '|' . $attributes['source']['web_url'] . '] opened on GitLab {panel}' . $attributes['title'] . '{panel}'; $comment->setBody($body); $issueService = new IssueService(new DotEnvConfiguration(base_path())); $ret = $issueService->addComment($issueKey, $comment); } catch (JIRAException $e) { Log::error("add Comment Failed : " . $e->getMessage()); } } } else { Log::info("Empty object attributes. " . json_encode($hook->all(), JSON_PRETTY_PRINT)); } return response()->json(['result' => 'Ok']); }