Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
saqqdy committed Mar 27, 2020
2 parents abac90f + d30c675 commit f47ecd2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ gitm admin publish release
### gitm admin update
更新release、bugfix、support分支代码,默认走merge方法
```
# 形式:gitm admin update <type> [-r --rebase]
# 传入rebase使用release方法合并
gitm admin update bug
# 形式:gitm admin update <type> [-r --rebase] [-m --mode [mode]]
# mode:出现冲突时,保留传入代码还是保留当前代码;1=采用当前 2=采用传入;默认为 0=手动处理。本参数不可与--rebase同时使用
# release:传入rebase使用release方法合并,默认使用merge
gitm admin update bugfix -m 2
```

### gitm admin clean
Expand Down
12 changes: 9 additions & 3 deletions bin/gitm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,23 @@ program
})
program
.name('gitm admin')
.usage('<command> <type>')
.usage('<command> <type> [-m --mode [mode]]')
.command('update <type>')
.description('更新bugfix、release、support分支代码')
.option('-r, --rebase', '是否使用rebase方式更新,默认merge', false)
.option('-m, --mode [mode]', '出现冲突时,保留传入代码还是保留当前代码;1=采用当前 2=采用传入;默认为 0=手动处理。本参数不可与--rebase同时使用', 0)
.action(async (type, opt) => {
const opts = ['bugfix', 'release', 'support'] // 允许执行的指令
let base = type === 'release' ? config.master : config.release,
mode = '', // 冲突时,保留哪方代码
status = await getStatus()
if (!status) sh.exit(1)
if (opt.mode === 1) {
mode = ' --strategy-option ours'
} else if (opt.mode === 2) {
mode = ' --strategy-option theirs'
}
if (opts.includes(type)) {
// release从master拉取,其他从release拉取
let cmd = [
`git checkout ${base}`,
`git pull`,
Expand All @@ -194,7 +200,7 @@ program
config: { slient: false, again: true }
},
{
cmd: `git merge --no-ff ${base}`,
cmd: `git merge --no-ff ${base}${mode}`,
config: { slient: false, again: false, postmsg: true, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
},
{
Expand Down
47 changes: 42 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const defaults = {
support: 'support',
user: '',
email: '',
msgTemplate: '${message};项目:${project};路径:${pwd}',
msgUrl: 'http://crp.kingdee.com/cd/metroOperateOutside/startMetroByMetroId?metroId=305648017963220992&describe=1235&isCurlAnother=false'
}
const getConfigFrom = () => {
Expand Down Expand Up @@ -54,9 +55,9 @@ function getConfig() {
} else if (configFrom === 2) {
return require(pwd + 'gitmarsconfig.json')
}
return defaults
return {}
}
config = getConfig()
config = { ...defaults, ...getConfig() }

/**
* wait
Expand Down Expand Up @@ -121,7 +122,7 @@ const queue = list => {
// 只有silent模式才需要输出信息
config.silent && sh.echo(error(err))
sh.echo(error('指令 ' + cmd + ' 执行失败,中断了进程'))
config.postmsg && postMessage('指令 ' + cmd + ' 执行失败,中断了进程')
config.postmsg && postMessage('出错了!指令 ' + cmd + ' 执行失败,中断了进程')
rest.length > 0 && sh.echo(error('请处理相关问题之后输入gitm continue继续'))
sh.exit(1)
} else {
Expand Down Expand Up @@ -218,15 +219,51 @@ const getCurrent = async () => {
* @description 发送消息
*/
const postMessage = msg => {
msg = msg.replace(/\s/g, '')
config.msgUrl && sh.exec(`curl -i -H "Content-Type: application/json" -X POST -d '{"envParams":{"error_msg":"'${msg}'"}}' "${config.msgUrl}"`)
if (!config.msgTemplate) return
let message = config.msgTemplate.replace(/\$\{([a-zA-Z0-9-_]+)\}/g, (a, b) => {
if (b === 'message') return msg
return getMessage(b)
})
message = message.replace(/\s/g, '')
config.msgUrl && sh.exec(`curl -i -H "Content-Type: application/json" -X POST -d '{"envParams":{"error_msg":"'${message}'"}}' "${config.msgUrl}"`, { silent: true })
}

/**
* getMessage
* @description 解析模板数据
*/
const getMessage = type => {
let str = '',
name = pwd.match(/\/([a-zA-Z0-9-_]+)\/?$/)
switch (type) {
case 'time':
str = new Date()
break
case 'pwd':
str = pwd
break
case 'project':
str = name ? name[1] : ''
break
case 'user':
str = config.user
break

default:
break
}
return str
}

const handleConfigOutput = name => {
if (name === 'user') {
return '请输入Git用户名(必填)'
} else if (name === 'email') {
return '请输入Git邮箱'
} else if (name === 'msgUrl') {
return '请输入云之家消息推送地址,默认:' + defaults.msgUrl
} else if (name === 'msgTemplate') {
return '请输入消息模板,默认:' + defaults.msgTemplate
}
return '请输入' + name + '分支名称,默认为:' + defaults[name]
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gitmars",
"description": "git tool for newbees",
"version": "1.0.10",
"version": "1.0.11",
"main": "bin/gitm.js",
"scripts": {
"start": "react-scripts start"
Expand Down

0 comments on commit f47ecd2

Please sign in to comment.