Skip to content

Commit abac90f

Browse files
committed
Merge branch 'dev'
2 parents 0514beb + da66349 commit abac90f

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ gitm admin create release
143143
### gitm admin publish
144144
发版操作
145145
```
146-
# 形式:gitm admin publish <type> [-c --combine] [-r --rebase]
147-
# 可传入2个参数,传入combine时合并release之后会把release同步到bugfix,传入rebase使用release方法合并
146+
# 形式:gitm admin publish <type> [-c --combine] [-r --rebase] [-p --prod]
147+
# 传入combine时合并release之后会把release同步到bugfix
148+
# 传入rebase使用release方法合并
149+
# 当需要发布bugfix时,传入prod会把bugfix同步到master,不传则不合并
148150
gitm admin publish release
149151
```
150152

bin/gitm-admin.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ program
4848
.description('发布bugfix、release、support分支')
4949
.option('-c, --combine', '是否把release代码同步到bug', false)
5050
.option('-r, --rebase', '是否使用rebase方式更新,默认merge', false)
51+
.option('-p, --prod', '发布bug分支时,是否合并bug到master', false)
5152
.action(async (type, opt) => {
5253
const opts = ['bugfix', 'release', 'support'] // 允许执行的指令
5354
let status = await getStatus()
@@ -69,16 +70,6 @@ program
6970
cmd: `git merge --no-ff ${config.bugfix}`,
7071
config: { slient: false, again: false, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
7172
},
72-
{
73-
cmd: `git push`,
74-
config: { slient: false, again: true, success: '推送成功', fail: '推送失败,请根据提示处理' }
75-
},
76-
`git checkout ${config.master}`,
77-
`git pull`,
78-
{
79-
cmd: `git merge --no-ff ${config.bugfix}`,
80-
config: { slient: false, again: false, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
81-
},
8273
{
8374
cmd: `git push`,
8475
config: { slient: false, again: true, success: '推送成功', fail: '推送失败,请根据提示处理' }
@@ -123,6 +114,20 @@ program
123114
}
124115
]
125116
}
117+
if (type === 'bugfix' && opt.prod) {
118+
cmd[type] = cmd[type].concat([
119+
`git checkout ${config.master}`,
120+
`git pull`,
121+
{
122+
cmd: `git merge --no-ff ${config.bugfix}`,
123+
config: { slient: false, again: false, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
124+
},
125+
{
126+
cmd: `git push`,
127+
config: { slient: false, again: true, success: '推送成功', fail: '推送失败,请根据提示处理' }
128+
}
129+
])
130+
}
126131
if (type === 'release' && opt.combine) {
127132
if (opt.rebase) {
128133
cmd[type] = cmd[type].concat([
@@ -135,7 +140,7 @@ program
135140
},
136141
{
137142
cmd: `git rebase ${config.release}`,
138-
config: { slient: false, again: false, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
143+
config: { slient: false, again: false, postmsg: true, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
139144
},
140145
{
141146
cmd: `git push`,
@@ -151,7 +156,7 @@ program
151156
`git pull`,
152157
{
153158
cmd: `git merge --no-ff ${config.release}`,
154-
config: { slient: false, again: false, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
159+
config: { slient: false, again: false, postmsg: true, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
155160
},
156161
{
157162
cmd: `git push`,
@@ -190,7 +195,7 @@ program
190195
},
191196
{
192197
cmd: `git merge --no-ff ${base}`,
193-
config: { slient: false, again: false, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
198+
config: { slient: false, again: false, postmsg: true, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
194199
},
195200
{
196201
cmd: `git push`,
@@ -208,7 +213,7 @@ program
208213
},
209214
{
210215
cmd: `git rebase ${base}`,
211-
config: { slient: false, again: false, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
216+
config: { slient: false, again: false, postmsg: true, success: '分支合并成功', fail: '合并失败,请根据提示处理' }
212217
},
213218
{
214219
cmd: `git push`,

bin/gitm-config.js

100755100644
File mode changed.

bin/index.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const defaults = {
1919
bugfix: 'bug',
2020
support: 'support',
2121
user: '',
22-
email: ''
22+
email: '',
23+
msgUrl: 'http://crp.kingdee.com/cd/metroOperateOutside/startMetroByMetroId?metroId=305648017963220992&describe=1235&isCurlAnother=false'
2324
}
2425
const getConfigFrom = () => {
2526
if (sh.test('-f', pwd + '.gitmarsrc')) {
@@ -39,10 +40,10 @@ configFrom = getConfigFrom()
3940
function getConfig() {
4041
if (configFrom === 1) {
4142
let str = (sh.cat('.gitmarsrc') + '')
42-
.replace(/(^\n*)|(\n*$)/g, '')
43-
.replace(/\n{2,}/g, '\n')
44-
.replace(/\r/g, '')
45-
.replace(/[^\S\x0a\x0d]/g, ''),
43+
.replace(/(^\n*)|(\n*$)/g, '')
44+
.replace(/\n{2,}/g, '\n')
45+
.replace(/\r/g, '')
46+
.replace(/[^\S\x0a\x0d]/g, ''),
4647
arr = []
4748
if (str) arr = str.split('\n')
4849
arr.forEach(el => {
@@ -88,10 +89,11 @@ const queue = list => {
8889
list = JSON.parse(JSON.stringify(list))
8990
wait(list, (command, cb) => {
9091
let config = {
91-
silent: true,
92-
kill: true,
93-
again: false // 指令执行中断之后是否需要重新执行,类似冲突解决之后的指令,不再需要重复执行
94-
},
92+
silent: true,
93+
postmsg: false,
94+
kill: true,
95+
again: false // 指令执行中断之后是否需要重新执行,类似冲突解决之后的指令,不再需要重复执行
96+
},
9597
cmd = command
9698
// 传入对象形式:{ cmd: '', config: {} }
9799
if (command instanceof Object) {
@@ -119,11 +121,13 @@ const queue = list => {
119121
// 只有silent模式才需要输出信息
120122
config.silent && sh.echo(error(err))
121123
sh.echo(error('指令 ' + cmd + ' 执行失败,中断了进程'))
124+
config.postmsg && postMessage('指令 ' + cmd + ' 执行失败,中断了进程')
122125
rest.length > 0 && sh.echo(error('请处理相关问题之后输入gitm continue继续'))
123126
sh.exit(1)
124127
} else {
125128
if (code === 0) {
126129
sh.echo(success(config.success || '指令 ' + cmd + ' 执行成功'))
130+
config.postmsg && postMessage(config.success || '指令 ' + cmd + ' 执行成功')
127131
} else {
128132
sh.echo(warning(config.fail || '指令 ' + cmd + ' 执行失败'))
129133
}
@@ -178,13 +182,12 @@ const setLog = log => {
178182
const getStatus = async () => {
179183
const data = await queue(['gitm status'])
180184
if (data[0].out.indexOf('Changes to be committed') > -1 || data[0].out.indexOf('Changes not staged for commit') > -1) {
181-
sh.echo(warning('您还有未提交的文件,请处理后再继续') + '\n如果需要暂存文件请执行: gitm save\n恢复时执行:gitm get')
185+
sh.echo(error('您还有未提交的文件,请处理后再继续') + '\n如果需要暂存文件请执行: gitm save\n恢复时执行:gitm get')
182186
sh.exit(1)
183187
return false
184188
} else if (data[0].out.indexOf('Untracked files') > -1) {
185-
sh.echo(warning('您还有未加入版本的文件,请处理后再继续') + '\n如果需要暂存文件请执行: gitm save --force\n恢复时执行:gitm get')
186-
sh.exit(1)
187-
return false
189+
sh.echo(warning('您有未加入版本的文件,') + '\n如果需要暂存文件请执行: gitm save --force\n恢复时执行:gitm get')
190+
return true
188191
} else {
189192
return true
190193
}
@@ -210,6 +213,15 @@ const getCurrent = async () => {
210213
return data[0].out.replace(/^\*\s+/, '')
211214
}
212215

216+
/**
217+
* postMessage
218+
* @description 发送消息
219+
*/
220+
const postMessage = msg => {
221+
msg = msg.replace(/\s/g, '')
222+
config.msgUrl && sh.exec(`curl -i -H "Content-Type: application/json" -X POST -d '{"envParams":{"error_msg":"'${msg}'"}}' "${config.msgUrl}"`)
223+
}
224+
213225
const handleConfigOutput = name => {
214226
if (name === 'user') {
215227
return '请输入Git用户名(必填)'
@@ -219,4 +231,4 @@ const handleConfigOutput = name => {
219231
return '请输入' + name + '分支名称,默认为:' + defaults[name]
220232
}
221233

222-
module.exports = { pwd, warning, error, success, defaults, config, configFrom, wait, queue, getCache, setCache, getStatus, checkBranch, getCurrent, handleConfigOutput }
234+
module.exports = { pwd, warning, error, success, defaults, config, configFrom, wait, queue, getCache, setCache, getStatus, checkBranch, getCurrent, postMessage, handleConfigOutput }

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gitmars",
33
"description": "git tool for newbees",
4-
"version": "1.0.9",
4+
"version": "1.0.10",
55
"main": "bin/gitm.js",
66
"scripts": {
77
"start": "react-scripts start"

0 commit comments

Comments
 (0)