import axios from 'axios'
const { default: packageInfo } = await import(
    "../package.json",
    {
      with: { type: "json" },
    }
  );
import git from 'simple-git'
import { getCurBranch, getGitUserName, addPkgInfoTagAndPushGitOrigin, pushCurTagToOrigin } from './utils.js'

const PYY_HOOK = 'https://oapi.dingtalk.com/robot/send?access_token=433e3e0e440ff2865409ec43ea4474c9ebcfd3fcfa5b592420e97245cb6cd1cc'



async function postPublishShell() {
    // const curBranch = await getCurBranch()
    // const isMain = curBranch === 'master'
    // const prefixTip = isMain ? '主' : curBranch === 'test' ? '测试' : curBranch === 'dev' ? '开发' : '不稳定'

    const userName = await getGitUserName()
    const payload = {
        markdown: {
            title: '发版公共',
            text: `#### 彭于晏提醒*${userName}*  \n  ## **${prefixTip}环境版本：**  \n  ### **${packageInfo.name}@${packageInfo.version}** 发版成功！  \n  访问[*拉斐尔*](https://raphael.dingdanll.com/)查看最新文档`
        },
        msgtype: 'markdown'
    }
    // axios.post(PYY_HOOK, payload)
    // git().fetch()
    // if (curBranch === 'master') {
    //     const [bigVersion] = packageInfo.version.split('-')
    //     const [f, s, t] = bigVersion.split('.').map(Number)
    //     const { all }  = await git().tags()
    //     let betaTag = 1
    //     let devTag = 1
    //     while (!!all.find(item => item === `v${f}.${s}.${t}-beta.${betaTag}`)) {
    //         betaTag++
    //     }
    //     while (!!all.find(item => item === `v${f}.${s}.${t}-dev.${devTag}`)) {
    //         devTag++
    //     }
    //     await git().checkout('test')
    //     await git().pull()
    //     const betaVersion = `v${f}.${s}.${t}-beta.${betaTag}`
    //     await addPkgInfoTagAndPushGitOrigin(betaVersion)
    //     await pushCurTagToOrigin(betaVersion)

    //     await git().checkout('dev')
    //     await git().pull()
    //     const devVersion = `v${f}.${s}.${t}-dev.${devTag}`
    //     await addPkgInfoTagAndPushGitOrigin(devVersion)
    //     await pushCurTagToOrigin(devVersion)

    //     await git().checkout('master')
    // }
}

postPublishShell()