feat: Use current user as commit author
This commit is contained in:
parent
1765c9c652
commit
8f3a6ed9f3
@ -1,7 +1,15 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
/* global appdata, appconfig */
|
||||||
|
|
||||||
|
const _ = require('lodash')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sanitizeCommitUser (user) {
|
sanitizeCommitUser (user) {
|
||||||
|
let wlist = new RegExp('(?!([^a-zA-Z0-9-_.\',& ]|' + appdata.regex.cjk.source + '))', 'g')
|
||||||
|
return {
|
||||||
|
name: _.chain(user.name).replace(wlist, '').trim().value(),
|
||||||
|
email: appconfig.git.showUserEmail ? user.email : appconfig.git.serverEmail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ const fs = Promise.promisifyAll(require('fs'))
|
|||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const URL = require('url')
|
const URL = require('url')
|
||||||
|
|
||||||
|
const securityHelper = require('../helpers/security')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Git Model
|
* Git Model
|
||||||
*/
|
*/
|
||||||
@ -207,7 +209,8 @@ module.exports = {
|
|||||||
commitMsg = (isTracked) ? 'Updated ' + gitFilePath : 'Added ' + gitFilePath
|
commitMsg = (isTracked) ? 'Updated ' + gitFilePath : 'Added ' + gitFilePath
|
||||||
return self._git.add(gitFilePath)
|
return self._git.add(gitFilePath)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return self._git.exec('commit', ['-m', commitMsg, '--author="' + author.name + ' <' + author.email + '>"']).catch((err) => {
|
let commitUsr = securityHelper.sanitizeCommitUser(author)
|
||||||
|
return self._git.exec('commit', ['-m', commitMsg, '--author="' + commitUsr.name + ' <' + commitUsr.email + '>"']).catch((err) => {
|
||||||
if (_.includes(err.stdout, 'nothing to commit')) { return true }
|
if (_.includes(err.stdout, 'nothing to commit')) { return true }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user