protected function execute(InputInterface $input, OutputInterface $output) { $nameOrKey = $input->getOption('project'); $summary = $input->getOption('summary'); $assignee = $input->getOption('assignee'); try { $issueField = new IssueField(); $issueField->setProjectKey($nameOrKey)->setSummary($summary)->setAssigneeName($assignee); $priority = $input->getOption('priority'); if ($priority) { $issueField->setPriorityName($priority); } $issueType = $input->getOption('issueType'); if ($issueType) { $issueField->setIssueType($issueType); } $desc = $input->getOption('desc'); if ($desc) { $issueField->setDescription($desc); } $version = $input->getOption('version'); if ($version) { $issueField->addVersion($version); } $issueService = new IssueService(); $ret = $issueService->create($issueField); //If success, Returns a link to the created issue. $output->writeln($ret); } catch (JiraException $e) { $output->writeln("Error Occured! " . $e->getMessage()); } }
public function create(\Request $request) { $data = Request::json()->all(); $issue_service = new IssueService(app(ConfigurationInterface::class)); $url_parts = parse_url($data['worklog']['self']); $uri = $url_parts['path']; $regex = '~^/rest/api/./issue/(?P<issue_id>.*?)/(?P<ignore>.*?)/?$~'; $matched = preg_match($regex, $uri, $matches); if (!$matched) { return null; } $issue = $issue_service->get($matches['issue_id']); $project_key = $issue->fields->project->key; $project = Project::whereJiraKey($project_key)->first(); $employee = Staff::whereUserName($data['worklog']['author']['name'])->first(); //return $project; $time_spent = $data['worklog']['timeSpentSeconds']; $started = $data['worklog']['started']; $timelog_jira_id = $data['worklog']['id']; $timelog = Timelog::whereJiraId($timelog_jira_id)->first(); if ($timelog == null) { $timelog = new Timelog(); } $timelog->project_id = $project->id; $timelog->staff_id = $employee->id; $timelog->started = $started; $timelog->time_spent = $time_spent; $timelog->jira_id = $timelog_jira_id; $timelog->save(); //debugInfo($timelog); return $timelog; }
/** * Register the service provider. * * @return void */ public function register() { $config = $this->app['config']->get('jira', []); $this->app['config']->set('jira', array_merge(require __DIR__ . '/../../config/jira.php', $config)); $config = $this->app['config']->get('jira', []); $this->app->bindShared('jiraprojectservice', function () use($config) { $service = new ProjectService($config); $service->setLogger($this->createLogger($config)); return $service; }); $this->app->bindShared('jiraissueservice', function () use($config) { $service = new IssueService($config); $service->setLogger($this->createLogger($config)); return $service; }); $this->app->bindShared('jirahookservice', function () use($config) { $service = new HookService($config); $service->setLogger($this->createLogger($config)); return $service; }); $this->app->bindShared('jirasearchservice', function () use($config) { $service = new SearchService($config); $service->setLogger($this->createLogger($config)); return $service; }); }
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); }
public function syncWithJira() { $staff_list = Staff::all(); Timelog::where('project_id', '=', $this->id)->delete(); $issue_service = new IssueService(app(ConfigurationInterface::class)); $start = 0; while (1) { try { $issues = $issue_service->search("project={$this->jira_key} and timespent>0 and updated >= {$this->start_date}", $start, 250, ["key", "worklog"]); } catch (JiraException $exception) { return false; } if (count($issues->getIssues()) == 0) { break; } $timelogs = []; foreach ($issues->getIssues() as $issue) { $jira_work_logs = $issue->fields->worklog->worklogs; foreach ($jira_work_logs as $jira_work_log) { if (!isset($jira_work_log->author)) { continue; } $employee = $staff_list->where('email', $jira_work_log->author->emailAddress)->first(); if ($employee == null) { continue; } $timelogs[] = ['project_id' => $this->id, 'staff_id' => $employee->id, 'time_spent' => $jira_work_log->timeSpentSeconds, 'jira_id' => $jira_work_log->id, 'started' => $jira_work_log->started]; } } Timelog::insert($timelogs); $start += count($issues->getIssues()); } return true; }
public function findTicket($ticket) { try { $issue = $this->issueService->get($ticket); return $issue; } catch (JiraException $e) { dd($e->getMessage()); } }
/** * @depends testUpdateWorkLogInIssue */ public function testGetWorkLogById($workLogid) { try { $issueService = new IssueService(); $worklog = $issueService->getWorklogById($this->issueKey, $workLogid); Dumper::dump($worklog); } catch (JiraException $e) { $this->assertTrue(false, 'testGetWorkLogById Failed : ' . $e->getMessage()); } }
public function testGetIssue() { $issueKey = 'TEST-155'; try { $issueService = new IssueService(); $queryParam = ['fields' => ['summary', 'comment'], 'expand' => ['renderedFields', 'names', 'schema', 'transitions', 'operations', 'editmeta', 'changelog']]; $issue = $issueService->get($issueKey, $queryParam); Dumper::dump($issue); } catch (JiraException $e) { $this->assertTrue(false, 'testSearch Failed : ' . $e->getMessage()); } }
public function testPostTimeTracking() { $timeTracking = new TimeTracking(); $timeTracking->setOriginalEstimate('3w 4d 6h'); $timeTracking->setRemainingEstimate('1w 2d 3h'); try { $issueService = new IssueService(); $ret = $issueService->timeTracking($this->issueKey, $timeTracking); var_dump($ret); } catch (JIRAException $e) { $this->assertTrue(false, 'testPostTimeTracking Failed : ' . $e->getMessage()); } }
public function testCreateSubTask() { try { $issueField = new IssueField(); $issueField->setProjectKey('TEST')->setSummary("Subtask - something's wrong")->setAssigneeName('lesstif')->setPriorityName('Critical')->setIssueType('Sub-task')->setDescription('Subtask - Full description for issue')->addVersion('1.0.1')->addVersion('1.0.3')->setParent($this->issueKey); $issueService = new IssueService(); $ret = $issueService->create($issueField); //If success, Returns a link to the created issue. print_r($ret); $issueKey = $ret->{'key'}; return $issueKey; } catch (JiraException $e) { $this->assertTrue(false, 'Create Failed : ' . $e->getMessage()); } }
public function testSearch() { $jql = 'project not in (TEST) and assignee = currentUser() and status in (Resolved, closed)'; try { $issueService = new IssueService(); $ret = $issueService->search($jql); var_dump($ret); } catch (JIRAException $e) { $this->assertTrue(false, 'testSearch 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']); }
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]); }