Inheritance: implements JsonSerializable
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);
}
 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']);
                 // doesn't post to jira because of unknown jira bug => adding comment separately
                 //$transition->setCommentBody($body);
                 $issueService = new IssueService(new DotEnvConfiguration(base_path()));
                 $issueService->transition($issueKey, $transition);
                 $comment = new Comment();
                 $comment->setBody($body);
                 $issueService->addComment($issueKey, $comment);
             }
         } catch (JIRAException $e) {
             Log::error("add Comment Failed : " . $e->getMessage());
         }
     }
     return response()->json(['result' => 'Ok', 'issue_count' => $issueCount]);
 }
 /**
  * @depends testAddcomment
  */
 public function testTransition($issueKey)
 {
     try {
         $transition = new Transition();
         $transition->setTransitionName('Resolved');
         $transition->setCommentBody('Issue close by REST API.');
         $issueService = new IssueService();
         $ret = $issueService->transition($issueKey, $transition);
         return $issueKey;
     } catch (JIRAException $e) {
         $this->assertTrue(false, 'testTransition Failed : ' . $e->getMessage());
     }
 }