flash-Zentao

禅道与飞书的bug通信

  1. // ==UserScript==
  2. // @name flash-Zentao
  3. // @namespace https://www.flashmoney.com/
  4. // @version 2.1.1
  5. // @description 禅道与飞书的bug通信
  6. // @grant GM_addStyle
  7. // @run-at document-end
  8. // @author ll
  9. // @match https://project.flashexpress.pub/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.  
  17. $('body')
  18. .delegate('#submit', 'click', function(event) {
  19. const href = window.top.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. const _bugTitle = $('.input-control #title').val() || $('.main-header >h2').children().eq(1).text()
  35.  
  36. // 状态置为解决不发送
  37. const _resolution = $('#resolution_chosen')
  38. if (_resolution.length) return
  39.  
  40. sendMessageFeiShu(_bugTitle, _bugUserName)
  41. }
  42.  
  43. });
  44.  
  45. // send飞书
  46. function sendMessageFeiShu(_title, _name){
  47. const _emailElement = $(`#assignedTo option:contains(${_name})`)
  48. const email = _emailElement && _emailElement.val()
  49.  
  50. // 白名单:不发送的email
  51. const whiteEmail = ['yanxuesong']
  52. if(whiteEmail.includes(email)) return
  53.  
  54. // 发送人
  55. const _sendName = window.top.$("#header #userNav .user-name").text()
  56. // bug地址
  57. const href = window.top.location.href
  58.  
  59. const query = {
  60. email: `${email}@flashexpress.com`,
  61. msg_type: "interactive",
  62. card: {
  63. "config": {
  64. "update_multi": true,
  65. "wide_screen_mode": true
  66. },
  67. "header": {
  68. "title": {
  69. "tag": "plain_text",
  70. "content": '🥺【bug】' + _name,
  71. },
  72. "template": "red"
  73. },
  74. "elements": [
  75. {
  76. "tag": "div",
  77. "text": {
  78. "tag": "lark_md",
  79. "content": `**bug:**[${_title}](${href})`
  80. }
  81. },
  82. {
  83. "tag": "div",
  84. "text": {
  85. "tag": "lark_md",
  86. "content": `**发送人:**${_sendName}`
  87. }
  88. },
  89. {
  90. "tag": "div",
  91. "text": {
  92. "tag": "lark_md",
  93. "content": `**发送时间:**${formatTimestamp(new Date(), "yyyy-MM-dd hh:mm:ss")}`
  94. }
  95. },
  96. {
  97. "tag": "action",
  98. "actions": [
  99. {
  100. "tag": "button",
  101. "text": {
  102. "tag":"plain_text",
  103. "content":'禅道bug地址' //指定按钮文本
  104. },
  105. "url": href,
  106. "type": "danger"
  107. }
  108. ]
  109. }
  110. ]
  111. }
  112. }
  113.  
  114. let apiUrl = 'https://feishu-api.flashfin.com/send-message'
  115.  
  116. // 针对没有邮箱的,url不一样
  117. // const whiteName = ['W:王雪晴', 'D:段飞扬']
  118. // if(whiteName.includes(_name)) {
  119. // apiUrl = 'https://open.feishu.cn/open-apis/bot/v2/hook/2cb384af-73a4-4590-9bf9-31acaf7ddc12'
  120. // }
  121.  
  122. $.ajax({
  123. url: apiUrl,
  124. type: "post",
  125. headers:{'Content-Type':'application/json'},
  126. dataType: 'json',
  127. data: JSON.stringify(query),
  128. success:function(result){
  129. console.log('send success')
  130. }
  131. });
  132. }
  133.  
  134. // 格式化时间
  135. function formatTimestamp (date, fmt) {
  136. if (!date) return date
  137. if (typeof date === 'string') {
  138. // 解决IOS上无法从dateStr parse 到Date类型问题
  139. date = date.replace(/-/g, '/')
  140. date = new Date(date)
  141. }
  142. const o = {
  143. 'M+': date.getMonth() + 1, // 月份
  144. 'd+': date.getDate(), // 日
  145. 'h+': date.getHours(), // 小时
  146. 'm+': date.getMinutes(), // 分
  147. 's+': date.getSeconds(), // 秒
  148. 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
  149. S: date.getMilliseconds() // 毫秒
  150. }
  151. if (/(y+)/.test(fmt)) {
  152. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  153. }
  154. for (const k in o) {
  155. if (new RegExp('(' + k + ')').test(fmt)) {
  156. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  157. }
  158. }
  159. return fmt
  160. }
  161. })();