mirror of
https://github.com/OBKoro1/autoCommit.git
synced 2024-12-23 01:29:20 +08:00
V1.0.0
This commit is contained in:
parent
06a2bab9a3
commit
ae8c685f6c
@ -2,15 +2,9 @@
|
||||
|
||||
### 如果觉得本插件还不错的话,给个[Star](https://github.com/OBKoro1/autoCommit)吧~
|
||||
|
||||
<!-- TODO: wiki readme -->
|
||||
<!-- TODO: npm包形式 -->
|
||||
<!-- webview 的icon -->
|
||||
|
||||
<!-- TODO: 支持谷歌插件 -->
|
||||
<!-- TODO: html的链接 -->
|
||||
|
||||
<!-- TODO: commit的颜色 -->
|
||||
|
||||
|
||||
### [V1.0.0]
|
||||
|
||||
|
49
README.md
49
README.md
@ -1,5 +1,52 @@
|
||||
# autoCommit
|
||||
> 一个用于Git自动commit的VSCode插件,它可以用来补充之前忘记提交commit,帮助你把首页的绿色格子填满。
|
||||
|
||||
# 用于学习交流
|
||||
### 功能特性
|
||||
|
||||
1. **选择多个日期范围**:一次操作即可提交不同日期`commit`
|
||||
2. **控制每个日期的commit次数**: 可以用它来控制绿色格子的颜色,了解[commit次数与颜色](https://github.com/OBKoro1/autoCommit/wiki/%E4%BD%BF%E7%94%A8%E9%A1%BB%E7%9F%A5#commit%E6%AC%A1%E6%95%B0%E4%B8%8E%E9%A2%9C%E8%89%B2)
|
||||
3. **随机commit次数**:随机commit次数让我们的提交看起来更加逼真。
|
||||
4. **取消commit**: 用于在`commit`期间取消并回滚到未提交版本
|
||||
5. 超过100次提交,将强制考虑10秒是否要取消commit。
|
||||
6. 插件成功运行后,将自动保存配置参数,无须每次都要一通操作。
|
||||
7. 提交完善的日志: 清晰的了解插件的运行情况
|
||||
8. 后台运行,不影响编码、浏览网页等。
|
||||
9. 运行超快,如下图187次commit,20秒搞定。
|
||||
10. 还有超多细节优化。
|
||||
|
||||
### 使用效果
|
||||
|
||||
在19年12月份我建了一个测试账号,如今
|
||||
|
||||
![](https://github.com/OBKoro1/autoCommit/blob/master/images/autoCommit.gif?raw=true)
|
||||
|
||||
### 插件入口
|
||||
|
||||
1. 使用快捷键打开VSCode的命令面板。
|
||||
* `mac`: `command + p` window: `ctrl + p`
|
||||
2. 输入`> auto commit`将会看到如下图所示的命令选项,然后用鼠标点击或者回车都可启动插件。
|
||||
|
||||
* 实际上可以输入下方选项的任何一段文字,都可以匹配到插件命令选项。
|
||||
|
||||
![](https://github.com/OBKoro1/autoCommit/blob/master/images/command.png?raw=true)
|
||||
|
||||
|
||||
### 阅读使用文档
|
||||
|
||||
了解具体的使用方法,git相关内容,插件运行机制,请阅读[使用须知](https://github.com/OBKoro1/autoCommit/wiki/%E4%BD%BF%E7%94%A8%E9%A1%BB%E7%9F%A5)
|
||||
|
||||
### License
|
||||
|
||||
[MIT](http://opensource.org/licenses/MIT)
|
||||
|
||||
### Star一下吧
|
||||
|
||||
如果插件觉得还不错的话,就给个 [Star](https://github.com/OBKoro1/autoCommit) ⭐️ 鼓励一下我吧~
|
||||
|
||||
[前端进阶积累](http://obkoro1.com/web_accumulate/)、[公众号](https://user-gold-cdn.xitu.io/2018/5/1/1631b6f52f7e7015?w=344&h=344&f=jpeg&s=8317)、[GitHub](https://github.com/OBKoro1)
|
||||
|
||||
### 插件声明
|
||||
|
||||
插件是本人兴之所至创建的个人项目,仅用于学习交流,禁止任何人商用以及用于非法之途。
|
||||
|
||||
插件如构成侵权,请通过邮件联系我。
|
@ -2,7 +2,7 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-30 16:59:30
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2020-01-08 14:28:37
|
||||
* LastEditTime : 2020-01-08 16:52:47
|
||||
* FilePath : /autoCommit/src/models/commitHandle.ts
|
||||
* Description : commit 具体操作
|
||||
* https://github.com/OBKoro1
|
||||
@ -95,28 +95,10 @@ class CommitHandle {
|
||||
for (let item of this.timeArr.values()) {
|
||||
if (this.cancelCommit()) break;
|
||||
// 每个日期commit次数
|
||||
let dayCommitNumber = this.paramsObj.commitNumber;
|
||||
if (this.paramsObj.randomCommit) {
|
||||
// 随机commit次数
|
||||
dayCommitNumber = RandomNumber(1, this.paramsObj.commitNumber);
|
||||
}
|
||||
if (item.commitNumber !== 0) {
|
||||
// 如果该范围有commit次数 则用该范围的
|
||||
dayCommitNumber = item.commitNumber;
|
||||
}
|
||||
let dayCommitNumber = this.getDayCommitNumber(item);
|
||||
for (let i = 0; i < dayCommitNumber; i++) {
|
||||
if (this.cancelCommit()) break;
|
||||
let time = this.formatTime(item.value); // 2019-01-02 08:00
|
||||
time = moment(time).format(); // 2019-01-02T00:00:00+0800
|
||||
const commitContent = `${time} \n随机数:${RandomNumber(
|
||||
1,
|
||||
100000
|
||||
)}\n提交次数:${totalNum + 1}`;
|
||||
fs.writeFileSync(
|
||||
`${this.paramsObj.itemSrc}/${this.paramsObj.fileName}`,
|
||||
commitContent,
|
||||
'utf-8'
|
||||
);
|
||||
let commitContent = this.commitFileContent(item, totalNum);
|
||||
let commitMsg: string = '';
|
||||
const isDebug = false; // 手动更改调试模拟是否提交git
|
||||
if (!isProduction() || !isDebug) {
|
||||
@ -167,20 +149,7 @@ class CommitHandle {
|
||||
}
|
||||
if (this.cancelCommit()) {
|
||||
if (totalNum === 0) return;
|
||||
outputLog('回滚中...');
|
||||
await new Promise((resolve, reject) => {
|
||||
let cmd = `cd ${this.paramsObj.itemSrc} && git reset --hard HEAD~${totalNum}`;
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
outputLog(`执行命令出错:${cmd}`);
|
||||
outputLog(`回滚失败:${error}`, stderr);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
outputLog('回滚成功:', stdout);
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
await this.resetCommit(totalNum);
|
||||
} else {
|
||||
outputLog('提交中...');
|
||||
this.autoCommitView.postMessage('提交中...', '提交中');
|
||||
@ -190,6 +159,9 @@ class CommitHandle {
|
||||
if (error) {
|
||||
outputLog(`执行命令出错:${cmd}`);
|
||||
outputLog(`错误信息:${error}`, stderr);
|
||||
outputLog(
|
||||
`git push失败很可能是你的网络有问题,请换到一个网络状况比较良好的地方,然后再项目下执行 git push操作。`
|
||||
);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
@ -200,6 +172,23 @@ class CommitHandle {
|
||||
}
|
||||
this.commitEnd(totalNum);
|
||||
}
|
||||
async resetCommit(totalNum: number) {
|
||||
this.autoCommitView.postMessage('回滚', '回滚');
|
||||
outputLog('回滚中...');
|
||||
return await new Promise((resolve, reject) => {
|
||||
let cmd = `cd ${this.paramsObj.itemSrc} && git reset --hard HEAD~${totalNum}`;
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
outputLog(`执行命令出错:${cmd}`);
|
||||
outputLog(`回滚失败:${error}`, stderr);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
outputLog(`回滚${totalNum}次commit成功:`, stdout);
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
commitEnd(totalNum: number) {
|
||||
this.userCancel = false; // 重新打开终止开关
|
||||
this.autoCommitView.postMessage('commit 完成', this.paramsObj);
|
||||
@ -216,6 +205,34 @@ class CommitHandle {
|
||||
public closeCommit() {
|
||||
this.userCancel = true;
|
||||
}
|
||||
// 组织commit文件的内容
|
||||
commitFileContent(item: dayTime, totalNum: number) {
|
||||
let time = this.formatTime(item.value); // 2019-01-02 08:00
|
||||
time = moment(time).format(); // 2019-01-02T00:00:00+0800
|
||||
const commitContent = `${time}\n随机数:${RandomNumber(
|
||||
1,
|
||||
100000
|
||||
)}\n提交次数:${totalNum + 1}`;
|
||||
// 写入内容
|
||||
fs.writeFileSync(
|
||||
`${this.paramsObj.itemSrc}/${this.paramsObj.fileName}`,
|
||||
commitContent,
|
||||
'utf-8'
|
||||
);
|
||||
return commitContent
|
||||
}
|
||||
getDayCommitNumber(item: dayTime) {
|
||||
let dayCommitNumber = this.paramsObj.commitNumber;
|
||||
if (this.paramsObj.randomCommit) {
|
||||
// 随机commit次数
|
||||
dayCommitNumber = RandomNumber(1, this.paramsObj.commitNumber);
|
||||
}
|
||||
if (item.commitNumber !== 0) {
|
||||
// 如果该范围有commit次数 则用该范围的
|
||||
dayCommitNumber = item.commitNumber;
|
||||
}
|
||||
return dayCommitNumber;
|
||||
}
|
||||
// 获取当天的随机时间
|
||||
formatTime(time: string) {
|
||||
const hour1 = RandomNumber(0, 2);
|
||||
|
@ -62,7 +62,7 @@
|
||||
<span>随机commit次数 :</span>
|
||||
</el-tooltip>
|
||||
</label>
|
||||
<el-input-number v-model="form.commitNumber" :step="1" :min="2" :max="20" size="large"></el-input-number>
|
||||
<el-input-number v-model="form.commitNumber" :step="1" :min="2" :max="30" size="large"></el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item class="form_item" prop="commitNumber" v-else>
|
||||
<label slot="label">
|
||||
@ -70,7 +70,7 @@
|
||||
<span>默认commit次数 :</span>
|
||||
</el-tooltip>
|
||||
</label>
|
||||
<el-input-number v-model="form.commitNumber" :step="1" :min="1" :max="20" size="large"></el-input-number>
|
||||
<el-input-number v-model="form.commitNumber" :step="1" :min="1" :max="0" size="large"></el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item v-for="(ele, index) in form.timeArr" :key="index" :prop="'timeArr.' + index + '.value'" :rules="{
|
||||
required: true, message: '日期不能为空', trigger: 'blur'
|
||||
@ -94,9 +94,9 @@
|
||||
<el-button @click.prevent="removeTime(index)" :disabled="form.timeArr.length === 1">删除</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitForm('form')" :disabled="runNow === 1 && runNow !== 0">开始commit</el-button>
|
||||
<el-button @click="addTimeRange" :disabled="runNow === 1">新增日期范围</el-button>
|
||||
<el-button @click="reset" :disabled="runNow !== 1">取消commit</el-button>
|
||||
<el-button type="primary" @click="submitForm('form')" :disabled="(runNow === 4 || runNow === 1) && runNow !== 0">开始commit</el-button>
|
||||
<el-button @click="addTimeRange" :disabled="runNow === 1 || runNow === 4">新增日期范围</el-button>
|
||||
<el-button @click="reset" :disabled="runNow !== 1 || runNow !== 4">取消commit</el-button>
|
||||
<el-button @click="clearLog" :disabled="showText.logStr === ''">清空日志</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@ -124,10 +124,10 @@
|
||||
:autosize="{ minRows: 1, maxRows: 4}"
|
||||
placeholder="无法输入 仅用于展示" v-model="showText.paramsStr" :disabled="showText.paramsStr === ''">
|
||||
</el-form-item>
|
||||
<!-- TODO: 链接 -->
|
||||
<el-form-item label="请先阅读文档 :">
|
||||
<el-link href="https://element.eleme.io" type="primary" target="_blank">Readme</el-link>
|
||||
<el-link href="https://element.eleme.io" type="primary" target="_blank">更新日志</el-link>
|
||||
<el-link href="https://github.com/OBKoro1/autoCommit/wiki" type="primary" target="_blank">Readme</el-link>
|
||||
<el-link href="https://github.com/OBKoro1/autoCommit/wiki/%E4%BD%BF%E7%94%A8%E9%A1%BB%E7%9F%A5" type="primary" target="_blank">使用文档</el-link>
|
||||
<el-link href="https://github.com/OBKoro1/autoCommit/wiki/ChangeLog" type="primary" target="_blank">更新日志</el-link>
|
||||
</el-form-item>
|
||||
<div class="tip">觉得这个插件还不错的话, 请给我点个<el-link href="https://github.com/OBKoro1/autoCommit" type="primary" target="_blank">Star⭐️</el-link>吧~</div>
|
||||
<div v-if="!isProduction">
|
||||
@ -271,12 +271,6 @@
|
||||
if(command === 'init-formData'){
|
||||
if (data) {
|
||||
this.form = data
|
||||
// this.form.timeArr = [
|
||||
// {
|
||||
// value: '',
|
||||
// commitNumber: 0
|
||||
// }
|
||||
// ]
|
||||
}
|
||||
} else if (command === 'choose item success') {
|
||||
// 选择文件夹成功
|
||||
@ -288,8 +282,10 @@
|
||||
message: `${data}根目录没有.git文件夹`,
|
||||
duration: 0
|
||||
});
|
||||
} else if(command === ''){
|
||||
|
||||
} else if(command === '回滚'){
|
||||
this.runNow = 3;
|
||||
}else if(command === '提交中...'){
|
||||
this.runNow = 4
|
||||
}else if(command === 'commit 完成'){
|
||||
// commit 完成
|
||||
this.runNow = 2
|
||||
@ -306,7 +302,6 @@
|
||||
},
|
||||
// 重置: commit成功和中断commit
|
||||
reset() {
|
||||
this.runNow = 3;
|
||||
if(isWeb){
|
||||
clearInterval(this.mockLogTime)
|
||||
this.mockLogTime = null
|
||||
|
Loading…
Reference in New Issue
Block a user