flash-Zentao

禅道与飞书的bug通信

当前为 2022-02-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         flash-Zentao
// @namespace    https://www.flashmoney.com/
// @version      1.2
// @description  禅道与飞书的bug通信
// @grant        GM_addStyle
// @run-at       document-end
// @author       ll
// @match        https://project.flashexpress.pub/bug-*
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const href = window.location.href
    $('body')
    .delegate('#submit', 'click', function(event) {
        const href = window.location.href

        if(href.indexOf('bug-create') > -1) {
            // 影响版本
            const _require = $('#openedBuild_chosen .search-choice >span').text()
            // 标题
            const _bugTitle = $('.input-control #title').val()
            // 指派给
            const bugUserName = $("#assignedTo_chosen >.chosen-single-with-deselect >span").text()

            if (_require && _bugTitle) {
                sendMessageFeiShu(_bugTitle, bugUserName)
            }
        } else {
            const _bugUserName = $(".picker-selections .picker-selection-text").text()

            const _bugTitle = $('.input-control #title').val() || $('.main-header >h2').children().eq(1).text()

            // 状态置为解决不发送
            const _resolution = $('#resolution_chosen')
            if (_resolution.length) return

            sendMessageFeiShu(_bugTitle, _bugUserName)
        }

        });


         // send飞书
        function sendMessageFeiShu(_title, _name){
            const _emailElement = $(`#assignedTo option:contains(${_name})`)
            const email = _emailElement && _emailElement.val()
            const query = {
                email: `${email}@flashexpress.com`,
                msg_type: "post",
                content: {
                    "post": {
                        "zh_cn": {
                            "title": "有人给你提bug",
                            "content": [
                                [{
                                    "tag": "text",
                                    "text": 'bug名:'
                                },
                                 {
                                     "tag": "text",
                                     "text": _title
                                 }],
                                 [{
                                     "tag": "text",
                                     "text": '归属人:'
                                 },
                                  {
                                      "tag": "text",
                                      "text": _name
                                  }]
                            ]
                        }
                    }
                }
            }

             let apiUrl = 'https://feishu-api.flashfin.com/send-message'

             // 针对没有邮箱的,url不一样
             // const whiteName = ['W:王雪晴', 'D:段飞扬']
             // if(whiteName.includes(_name)) {
                 // apiUrl = 'https://open.feishu.cn/open-apis/bot/v2/hook/2cb384af-73a4-4590-9bf9-31acaf7ddc12'
             // }

            $.ajax({
                url: apiUrl,
                type: "post",
                headers:{'Content-Type':'application/json'},
                dataType: 'json',
                data: JSON.stringify(query),
                success:function(result){
                    console.log('send success')
                }
            });
        }
})();