zen.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * The zen file of jenkins module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Zeng Gang<zenggang@easycorp.ltd>
  8. * @package jenkins
  9. * @link https://www.zentao.net
  10. */
  11. class jenkinsZen extends jenkins
  12. {
  13. /**
  14. * 构建流水线下拉菜单树。
  15. * Build pipeline dropmenu tree.
  16. *
  17. * @param array $tasks
  18. * @access public
  19. * @return array
  20. */
  21. protected function buildTree($tasks)
  22. {
  23. $result = array();
  24. foreach($tasks as $groupName => $task)
  25. {
  26. if(empty($task)) continue;
  27. $itemArray = array
  28. (
  29. 'id' => is_array($task) ? '' : $groupName,
  30. 'text' => is_array($task) ? urldecode($groupName) : urldecode($task),
  31. 'keys' => urldecode(zget(common::convert2Pinyin(array($groupName)), $groupName, '')),
  32. );
  33. if(is_array($task))
  34. {
  35. $itemArray['items'] = $this->buildTree($task);
  36. $itemArray['type'] = 'folder';
  37. }
  38. $result[] = $itemArray;
  39. }
  40. return $result;
  41. }
  42. /**
  43. * 检查Jenkins账号信息是否正确。
  44. * Check jenkins account and password.
  45. *
  46. * @param string $url
  47. * @param string $account
  48. * @param string $password
  49. * @param string $token
  50. * @access protected
  51. * @return bool
  52. */
  53. protected function checkTokenAccess($url, $account, $password, $token)
  54. {
  55. $password = $token ? $token : $password;
  56. $response = json_decode(common::http("{$url}/api/json", '', array(CURLOPT_USERPWD => "{$account}:{$password}")));
  57. if(empty($response) || empty($response->_class)) dao::$errors['account'] = $this->lang->jenkins->error->unauthorized;
  58. return dao::isError();
  59. }
  60. }