flash-Zentao

禅道与飞书的bug通信

目前为 2022-01-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name flash-Zentao
  3. // @namespace https://www.flashmoney.com/
  4. // @version 1.1
  5. // @description 禅道与飞书的bug通信
  6. // @grant GM_addStyle
  7. // @run-at document-end
  8. // @author ll
  9. // @match https://project.flashexpress.pub/zentao/bug-*
  10. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. const href = window.location.href
  17. $('body')
  18. .delegate('#submit', 'click', function(event) {
  19. const href = window.location.href
  20.  
  21. if(href.indexOf('bug-create') > -1) {
  22. // 影响版本
  23. const _require = $('#openedBuild_chosen .search-choice >span').text()
  24. // 标题
  25. const _bugTitle = $('.input-control #title').val()
  26. // 指派给
  27. const bugUserName = $("#assignedTo_chosen >.chosen-single-with-deselect >span").text()
  28.  
  29. if (_require && _bugTitle) {
  30. sendMessageFeiShu(_bugTitle, bugUserName)
  31. }
  32. } else {
  33. const _bugUserName = $(".picker-selections .picker-selection-text").text()
  34.  
  35. const _bugTitle = $('.input-control #title').val() || $('.main-header >h2').children().eq(1).text()
  36.  
  37. // 状态置为解决不发送
  38. const _resolution = $('#resolution_chosen')
  39. if (_resolution.length) return
  40.  
  41. sendMessageFeiShu(_bugTitle, _bugUserName)
  42. }
  43.  
  44. });
  45.  
  46.  
  47. // send飞书
  48. function sendMessageFeiShu(_title, _name){
  49. const _emailElement = $(`#assignedTo option:contains(${_name})`)
  50. const email = _emailElement && _emailElement.val()
  51. const query = {
  52. email: `${email}@flashexpress.com`,
  53. msg_type: "post",
  54. content: {
  55. "post": {
  56. "zh_cn": {
  57. "title": "有人给你提bug",
  58. "content": [
  59. [{
  60. "tag": "text",
  61. "text": 'bug名:'
  62. },
  63. {
  64. "tag": "text",
  65. "text": _title
  66. }],
  67. [{
  68. "tag": "text",
  69. "text": '归属人:'
  70. },
  71. {
  72. "tag": "text",
  73. "text": _name
  74. }]
  75. ]
  76. }
  77. }
  78. }
  79. }
  80.  
  81. let apiUrl = 'https://feishu-api.flashfin.com/send-message'
  82.  
  83. // 针对没有邮箱的,url不一样
  84. const whiteName = ['W:王雪晴', 'D:段飞扬']
  85. if(whiteName.includes(_name)) {
  86. apiUrl = 'https://open.feishu.cn/open-apis/bot/v2/hook/2cb384af-73a4-4590-9bf9-31acaf7ddc12'
  87. }
  88.  
  89. $.ajax({
  90. url: apiUrl,
  91. type: "post",
  92. headers:{'Content-Type':'application/json'},
  93. dataType: 'json',
  94. data: JSON.stringify(query),
  95. success:function(result){
  96. console.log('send success')
  97. }
  98. });
  99. }
  100. })();