1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- const express = require('express')
- const app = express()
- const port = 3222
- const fs = require('fs')
- const Git = require('./utils/git')
- const ftpDeploy = require('./utils/ftpDeploy')
- // const { REMOTE_NAME_TEXT_MAP } = require('./config/remote_config')
- const readConfig = require('./utils/readConfig')
- const logsInit = require('./utils/log')
- const runCmds = require('./utils/runCmds')
- app.use(express.json())
- app.use(express.urlencoded({ extended: true }))
- app.post('/git-hooker', async (req, res) => {
- let body = req.body
- if (body.ref_type !== 'tag') return;
- const TAG = body.ref
- // let branch = TAG.indexOf('test') > -1 ? 'test' : ''
- // if (!branch) return
-
- const _projectName = body.repository.name
- var git = new Git(_projectName)
- await git.clone(body.repository.clone_url, _projectName)
- git = new Git(_projectName)
- await git.pull()
- let deplogConfig = readConfig(_projectName, TAG)
- let branch
- // 判断是否触发流程
- if (TAG.indexOf(deplogConfig.tagExg) > -1) {
- branch = deplogConfig.branch
- }
-
-
- if (!branch) return;
- logsInit(_projectName, TAG)
- await git.pull()
- await git.checkout(deplogConfig.branch)
- try {
- await runCmds(deplogConfig.cmds, _projectName)
- } catch (err) {
- console.log(err)
- }
- await ftpDeploy(deplogConfig.parameter)
- res.send({
- code: 0,
- msg: '完成'
- })
- })
- app.listen(port, () => console.log(`listening on port ${port}!`))
|