commit 8ccfe71d11fdb43fc395d1c5f43c165737871bdc Author: jaybe Date: Wed Mar 5 04:39:21 2025 +0000 Upload files to "/" diff --git a/JIRADB.php b/JIRADB.php new file mode 100644 index 0000000..49d73ed --- /dev/null +++ b/JIRADB.php @@ -0,0 +1,44 @@ +db = \Config\Database::connect('jira'); + $this->zenith = \Config\Database::connect(); + } + + public function updateToken($data) + { + $insertData = [ + 'uid' => 0, + 'access_token' => $data['access_token'] ?? '', + 'refresh_token' => $data['refresh_token'] ?? '', + 'expires_time' => date('Y-m-d H:i:s', time() + $data['expires_in']), + ]; + $this->db->transStart(); + $builder = $this->db->table('api_info'); + $builder->setData($insertData); + $updateTime = ['update_time' => new RawSql('NOW()')]; + $builder->updateFields($updateTime, true); + $builder->upsert(); + $result = $this->db->transComplete(); + + return $result; + } + + public function getToken() + { + $builder = $this->db->table('api_info'); + $builder->select('access_token, refresh_token, expires_time'); + $builder->where('uid', 0); + $result = $builder->get()->getRowArray(); + + return $result; + } +} diff --git a/ZenithJira.php b/ZenithJira.php new file mode 100644 index 0000000..943da7d --- /dev/null +++ b/ZenithJira.php @@ -0,0 +1,167 @@ +db = new JIRADB(); + $this->iss = new ArrayConfiguration( + [ + 'jiraHost' => $this->jiraHost, + 'jiraUser' => 'jaybe@carelabs.co.kr', + 'jiraPassword' => $this->accessToken, + /* 'useTokenBasedAuth' => true, + 'personalAccessToken' => $this->accessToken, */ + + // custom log config + /* 'jiraLogEnabled' => true, + 'jiraLogFile' => "/my-jira-rest-client.log", + 'jiraLogLevel' => 'INFO', */ + ] + ); + } + + public function getProjects() + { + try { + $proj = new ProjectService($this->iss); + + $prjs = $proj->getAllProjects(); + return $prjs; + + } catch (JiraException $e) { + print_r("에러 발생 : ".$e->getMessage()); + } + } + + public function getDevelopIssues($status) + { + try { + $issueService = new IssueService($this->iss); + + $jql = 'project = "DEV" and status="'.$status.'"'; + $startAt = 0; + $maxResults = 200; + + $issues = $issueService->search($jql, $startAt, $maxResults); + + return $issues->getIssues(); + } catch (JiraException $e) { + print_r("에러 발생 : ".$e->getMessage()); + } + } + + public function getIssue($issueKey) + { + try { + $issueService = new IssueService($this->iss); + + $queryParam = [ + 'expand' => [ + 'renderedFields', + 'names', + 'schema', + 'transitions', + 'operations', + 'editmeta', + 'changelog', + ], + 'fields' => [ + 'status', + ] + ]; + + $issue = $issueService->get($issueKey, $queryParam); + + return $issue; + } catch (JiraException $e) { + print_r("에러 발생 : ".$e->getMessage()); + } + } + + public function getComments() + { + try { + $issueService = new IssueService(); + + $param = [ + 'startAt' => 0, + 'maxResults' => 3, + 'expand' => 'renderedBody', + ]; + + $comments = $issueService->getComments('TEST-867', $param); + + dd($comments); + } catch (JiraException $e) { + print_r("에러 발생 : ".$e->getMessage()); + } + } + + public function getUsers() + { + try { + $us = new UserService(); + + $paramArray = [ + 'username' => '.', // get all users. + 'startAt' => 0, + 'maxResults' => 1000, + 'includeInactive' => true, + //'property' => '*', + ]; + + // get the user info. + $users = $us->findUsers($paramArray); + } catch (JiraException $e) { + print_r("에러 발생 : ".$e->getMessage()); + } + } + + public function setIssueStatus($issueKey) + { + try { + $issueService = new IssueService($this->iss); + $transition = new Transition(); + + $issue = $this->getIssue($issueKey); + $currentIssueStatus = $issue->fields->status->id; + if($currentIssueStatus == '10132'){return ['result' => false, 'msg' => '이미 완료처리된 이슈입니다.'];} + + $transition->setTransitionId('21'); + $result = $issueService->transition($issueKey, $transition); + return ['result' => $result, 'msg' => '완료처리 되었습니다.']; + } catch (JiraException $e) { + print_r("에러 발생 : ".$e->getMessage()); + } + } + + public function testRequest() + { + try { + $statusService = new StatusService($this->iss); + $statuses = $statusService->getAll(); + dd($statuses); + } catch (JiraException $e) { + print_r("에러 발생 : ".$e->getMessage()); + } + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..4607086 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "lesstif/php-jira-rest-client": "^3.1" + } +}