mirror of
https://github.com/OBKoro1/autoCommit.git
synced 2025-01-05 12:35:39 +08:00
数据格式重构以及完成测试模式
This commit is contained in:
parent
5e7b687ccf
commit
54b79a2ed3
@ -2,7 +2,7 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-30 16:59:30
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2019-12-31 18:00:43
|
||||
* LastEditTime : 2020-01-01 17:32:41
|
||||
* FilePath : /autoCommit/src/models/commitHandle.ts
|
||||
* Description : commit 具体操作
|
||||
* https://github.com/OBKoro1
|
||||
@ -13,99 +13,144 @@ import * as moment from 'moment';
|
||||
import * as fs from 'fs';
|
||||
import { execSync } from 'child_process';
|
||||
import { RandomNumber } from '../util/util';
|
||||
import { getPanelWebview, outputLog } from '../util/vscodeUtil';
|
||||
import { getPanelWebview, outputLog, isProduction } from '../util/vscodeUtil';
|
||||
import WebView from './WebView';
|
||||
|
||||
interface timeElement {
|
||||
value: Array<string>;
|
||||
commitNumber: number;
|
||||
}
|
||||
|
||||
interface dayTime {
|
||||
value: string;
|
||||
commitNumber: number;
|
||||
}
|
||||
|
||||
class CommitHandle {
|
||||
public paramsObj: any;
|
||||
public timeArr: Array<string>;
|
||||
public timeArr: Array<dayTime>;
|
||||
public autoCommitView: WebView;
|
||||
|
||||
private userCancel: boolean;
|
||||
constructor(message: webviewMsg) {
|
||||
this.paramsObj = message.data;
|
||||
this.timeArr = [];
|
||||
this.timeHandle();
|
||||
this.autoCommitView = getPanelWebview();
|
||||
this.userCancel = false;
|
||||
}
|
||||
// 处理所有时间段
|
||||
timeHandle() {
|
||||
// 处理所有时间范围
|
||||
this.paramsObj.formatTime.forEach((item: Array<string>) => {
|
||||
this.paramsObj.timeArr.forEach((item: timeElement) => {
|
||||
// 获取每个时间范围的具体日期
|
||||
let detailTimeArr = this.getAllDay(item[0], item[1]);
|
||||
// 日期去重
|
||||
detailTimeArr = detailTimeArr.filter(ele => {
|
||||
return !this.timeArr.includes(ele);
|
||||
let detailTimeArr = this.getAllDay(item.value[0], item.value[1]);
|
||||
// 日期去重 组织数据
|
||||
detailTimeArr.forEach(ele => {
|
||||
let index = this.timeArr.findIndex(element => {
|
||||
return element.value === ele;
|
||||
});
|
||||
// 添加不存在的日期
|
||||
if (index === -1) {
|
||||
this.timeArr.push({
|
||||
value: ele,
|
||||
commitNumber: item.commitNumber
|
||||
});
|
||||
}
|
||||
});
|
||||
// TODO: commit number
|
||||
// if(){
|
||||
|
||||
// }
|
||||
// detailTimeArr.map(element=>{
|
||||
// return {
|
||||
// time: element
|
||||
// }
|
||||
// })
|
||||
this.timeArr.push(...detailTimeArr);
|
||||
});
|
||||
this.sortTime();
|
||||
}
|
||||
// 日期排序
|
||||
sortTime() {
|
||||
this.timeArr = this.timeArr.sort((item1: string, item2: string): number => {
|
||||
const dateArr1: Array<any> = item1.split('-');
|
||||
const dateArr2: Array<any> = item2.split('-');
|
||||
if (dateArr1[0] === dateArr2[0]) {
|
||||
if (dateArr1[1] === dateArr2[1]) {
|
||||
// 日期不同就比较日期
|
||||
return dateArr1[2] - dateArr2[2];
|
||||
this.timeArr = this.timeArr.sort(
|
||||
(item1: dayTime, item2: dayTime): number => {
|
||||
const dateArr1: Array<any> = item1.value.split('-');
|
||||
const dateArr2: Array<any> = item2.value.split('-');
|
||||
if (dateArr1[0] === dateArr2[0]) {
|
||||
if (dateArr1[1] === dateArr2[1]) {
|
||||
// 日期不同就比较日期
|
||||
return dateArr1[2] - dateArr2[2];
|
||||
} else {
|
||||
// 月份不同就比较月份
|
||||
return dateArr1[1] - dateArr2[1];
|
||||
}
|
||||
} else {
|
||||
// 月份不同就比较月份
|
||||
return dateArr1[1] - dateArr2[1];
|
||||
// 年份不同就比较年份
|
||||
return dateArr1[0] - dateArr2[0];
|
||||
}
|
||||
} else {
|
||||
// 年份不同就比较年份
|
||||
return dateArr1[0] - dateArr2[0];
|
||||
}
|
||||
});
|
||||
);
|
||||
this.commitFn();
|
||||
}
|
||||
// TODO: 中断
|
||||
commitFn() {
|
||||
outputLog('将要commit的日期:', this.timeArr);
|
||||
outputLog('每个日期提交次数:', this.paramsObj.commitNumber);
|
||||
async commitFn() {
|
||||
outputLog('将要commit的日期:', JSON.stringify(this.timeArr));
|
||||
let totalNum = 0; // 总commit次数
|
||||
// 遍历日期
|
||||
this.timeArr.forEach(item => {
|
||||
for (let item of this.timeArr.values()) {
|
||||
if (this.cancelCommit()) break;
|
||||
// 每个日期commit次数
|
||||
for (let i = 0; i < this.paramsObj.commitNumber; i++) {
|
||||
let time = this.formatTime(item); // 2019-01-02 08:00
|
||||
let dayCommitNumber = this.paramsObj.commitNumber;
|
||||
if (item.commitNumber !== 0) {
|
||||
// 如果该范围有commit次数 则用该范围的
|
||||
dayCommitNumber = item.commitNumber;
|
||||
}
|
||||
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)}`;
|
||||
const commitContent = `${time} \n随机数:${RandomNumber(
|
||||
1,
|
||||
100000
|
||||
)}\n提交次数:${totalNum + 1}`;
|
||||
fs.writeFileSync(
|
||||
`${this.paramsObj.itemSrc}/${this.paramsObj.fileSrc}`,
|
||||
`${this.paramsObj.itemSrc}/${this.paramsObj.fileName}`,
|
||||
commitContent,
|
||||
'utf-8'
|
||||
);
|
||||
const res = this.myExecSync(
|
||||
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${time}' && git pull && git push origin master`
|
||||
);
|
||||
console.log('res 结束', res);
|
||||
// 当前最新版本commit 信息
|
||||
const cmd = `git log -1 \
|
||||
--date=iso --pretty=format:'{"commit": "%h","author": "%aN <%aE>","date": "%ad","message": "%s"},' \
|
||||
$@ | \
|
||||
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
|
||||
perl -pe 's/},]/}]/'`;
|
||||
// [{"commit": "a6b5f3d","author": "OBKoro1 <1677593011@qq.com>","date": "2019-12-26 21:05:57 +0800","message": "init"}]
|
||||
const log = this.myExecSync(cmd);
|
||||
console.log('log 开始', log);
|
||||
const isDebug = true; // 手动更改调试模拟是否提交git
|
||||
if (!isProduction() && !isDebug) {
|
||||
// TODO: 测试提交 以及接受log
|
||||
const res = this.myExecSync(
|
||||
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${time}' && git pull && git push origin master`
|
||||
);
|
||||
console.log('res 结束', res);
|
||||
// 当前最新版本commit 信息
|
||||
const cmd = `git log -1 \
|
||||
--date=iso --pretty=format:'{"commit": "%h","author": "%aN <%aE>","date": "%ad","message": "%s"},' \
|
||||
$@ | \
|
||||
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
|
||||
perl -pe 's/},]/}]/'`;
|
||||
// [{"commit": "a6b5f3d","author": "OBKoro1 <1677593011@qq.com>","date": "2019-12-26 21:05:57 +0800","message": "init"}]
|
||||
const log = this.myExecSync(cmd);
|
||||
console.log('log 开始', log);
|
||||
} else {
|
||||
// 模拟git提交
|
||||
const test = await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
outputLog('延迟一秒');
|
||||
resolve('延迟一秒');
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
totalNum++;
|
||||
outputLog('commit内容', commitContent);
|
||||
}
|
||||
outputLog(`总commit次数${totalNum}`);
|
||||
outputLog('自动commit完成');
|
||||
});
|
||||
}
|
||||
this.commitEnd(totalNum);
|
||||
}
|
||||
commitEnd(totalNum: number) {
|
||||
this.userCancel = false; // 重新打开终止开关
|
||||
this.autoCommitView.postMessage('commit 完成', 'commit 完成')
|
||||
outputLog('自动commit完成', `总commit次数${totalNum}`);
|
||||
}
|
||||
cancelCommit() {
|
||||
if (this.userCancel) {
|
||||
outputLog('终止自动commit');
|
||||
}
|
||||
return this.userCancel;
|
||||
}
|
||||
public closeCommit() {
|
||||
this.userCancel = true;
|
||||
}
|
||||
// 格式化日期
|
||||
formatTime(time: string) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Author : OBKoro1
|
||||
* Date : 2019-12-25 17:08:18
|
||||
* LastEditors : OBKoro1
|
||||
* LastEditTime : 2019-12-31 16:42:46
|
||||
* LastEditTime : 2020-01-01 17:20:11
|
||||
* FilePath : /autoCommit/src/models/index.ts
|
||||
* Description : 插件逻辑入口
|
||||
* https://github.com/OBKoro1
|
||||
@ -20,7 +20,6 @@ class ExtensionLogic {
|
||||
public MessageCallBack: any;
|
||||
public autoCommitView: WebView;
|
||||
public CommitHandle: any;
|
||||
public isDebug: boolean;
|
||||
|
||||
public constructor(context: vscode.ExtensionContext) {
|
||||
this.context = context;
|
||||
@ -28,7 +27,6 @@ class ExtensionLogic {
|
||||
this.context,
|
||||
this.messageCallBack.bind(this)
|
||||
);
|
||||
this.isDebug = true;
|
||||
setPanelWebview(this.autoCommitView);
|
||||
this.createView();
|
||||
}
|
||||
@ -47,8 +45,11 @@ class ExtensionLogic {
|
||||
this.CommitHandle = new CommitHandle(message);
|
||||
} else if (message.command === 'choose-item') {
|
||||
this.publishChooseFile();
|
||||
} else if(message.command === 'cancel autoCommit'){
|
||||
this.CommitHandle.closeCommit()
|
||||
}
|
||||
}
|
||||
// 选择项目文件夹
|
||||
async publishChooseFile() {
|
||||
const urlArr: any = await vscode.window.showOpenDialog({
|
||||
canSelectFiles: false, // 允许选择文件
|
||||
|
@ -13,10 +13,9 @@
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="form-title">Github自动提交commit工具</div>
|
||||
<div>{{ event }}</div>
|
||||
<el-container>
|
||||
<el-main>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="160px">
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="180px">
|
||||
<el-form-item class="form_item" prop="itemSrc">
|
||||
<label slot="label">
|
||||
<el-tooltip class="item" content="要提交commit的仓库文件夹" placement="top-start">
|
||||
@ -46,52 +45,69 @@
|
||||
</el-form-item>
|
||||
<el-form-item class="form_item" prop="commitNumber">
|
||||
<label slot="label">
|
||||
<el-tooltip class="item" content="时间范围内每个日期需要commit的次数" placement="top-start">
|
||||
<span>commit次数 :</span>
|
||||
<el-tooltip class="item" content="时间范围内默认每个日期需要commit的次数" placement="top-start">
|
||||
<span>默认commit次数 :</span>
|
||||
</el-tooltip>
|
||||
</label>
|
||||
<el-input-number v-model="form.commitNumber" :min="1" :max="100" size="mini"></el-input-number>
|
||||
<el-input-number v-model="form.commitNumber" :step="1" :min="1" :max="100" 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'
|
||||
}">
|
||||
<label slot="label">
|
||||
<!-- TODO: wiki:一个日期只能选中一次 去重 sort排序 切割字符串 单独比较 -->
|
||||
<el-tooltip class="item" content="要commit的时间范围,可多选" placement="top-start">
|
||||
<el-tooltip class="item" content="要commit的日期范围" placement="top-start">
|
||||
<span>commit日期范围{{index+1}} :</span>
|
||||
</el-tooltip>
|
||||
</label>
|
||||
<el-date-picker v-model="ele.value" size="middle" type="daterange" value-format="yyyy-MM-dd"
|
||||
<el-date-picker v-model="ele.value" type="daterange" value-format="yyyy-MM-dd"
|
||||
range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
|
||||
</el-date-picker>
|
||||
<el-button @click.prevent="removeTime(index)" :disabled="index === 0">删除</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item v-for="(ele, index) in form.timeArr" :key="index">
|
||||
<label slot="label">
|
||||
<el-tooltip class="item" content="可选(默认使用默认commit次数):对应index的日期范围每个日期的commit次数" placement="top-start">
|
||||
<span>该范围每天提交次数{{index+1}} :</span>
|
||||
</el-tooltip>
|
||||
</label>
|
||||
<el-input-number v-model="ele.commitNumber" :step="1" :min="0" :max="100" ></el-input-number>
|
||||
<el-button @click.prevent="removeTime(index)" :disabled="index === 0">删除</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">新增时间范围</el-button>
|
||||
<el-button @click="reset" :disabled="runNow === 1">取消commit</el-button>
|
||||
<el-button @click="clearLog" :disabled="showText.logStr !== ''">清空日志</el-button>
|
||||
<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 @click="clearLog" :disabled="showText.logStr === ''">清空日志</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="form-title2">日志和文档</div>
|
||||
<el-main>
|
||||
<div class="log_form_father">
|
||||
<el-form label-width="160px">
|
||||
<el-form-item label="插件运行日志 :">
|
||||
<el-form-item>
|
||||
<label slot="label">
|
||||
<el-tooltip content="通过日志了解插件运行信息" placement="top-start">
|
||||
<span>插件运行日志 :</span>
|
||||
</el-tooltip>
|
||||
</label>
|
||||
<el-input @input="formatLog" type="textarea"
|
||||
:autosize="{ minRows: 1, maxRows: 8}"
|
||||
placeholder="无法输入 仅用于展示" v-model="showText.logStr" :disabled="runNow === 1 || runNow === 0">
|
||||
</el-form-item>
|
||||
<el-form-item label="开始commit的参数 :">
|
||||
<el-form-item>
|
||||
<label slot="label">
|
||||
<el-tooltip content="点击开始commit,插件运行所需要的参数" placement="top-start">
|
||||
<span>程序参数 :</span>
|
||||
</el-tooltip>
|
||||
</label>
|
||||
<el-input @input="watchParamsChange" type="textarea"
|
||||
:autosize="{ minRows: 1, maxRows: 4}"
|
||||
placeholder="无法输入 仅用于展示" v-model="showText.paramsStr" :disabled="showText.paramsStr === ''">
|
||||
</el-form-item>
|
||||
<el-form-item label="wiki文档 :">
|
||||
<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-form-item>
|
||||
<div class="tip">觉得这个插件还不错的话, 请给我点个<el-link href="https://element.eleme.io" type="primary" target="_blank">Star⭐️</el-link>吧~</div>
|
||||
<div class="tip">觉得这个插件还不错的话, 请给我点个<el-link href="https://github.com/OBKoro1/autoCommit" type="primary" target="_blank">Star⭐️</el-link>吧~</div>
|
||||
</div>
|
||||
</el-form>
|
||||
</el-input>
|
||||
@ -104,7 +120,13 @@
|
||||
<script src="../assets/scripts/vue.min.js"></script>
|
||||
<script src="../assets/scripts/element2.13.min.js"></script>
|
||||
<script>
|
||||
const vscode = acquireVsCodeApi()
|
||||
let isWeb = false // 是否网页 不在vscode插件生态内
|
||||
let vscode;
|
||||
try{
|
||||
vscode = acquireVsCodeApi()
|
||||
}catch(err){
|
||||
isWeb = true
|
||||
}
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
@ -117,7 +139,8 @@
|
||||
}
|
||||
}
|
||||
return {
|
||||
isProduction: false,
|
||||
isProduction: false, // 是否为调试模式
|
||||
mockLogTime: null, // 模拟数据的定时器
|
||||
showText:{
|
||||
oldParams: '', // 保存的参数
|
||||
paramsStr: '', // commit参数
|
||||
@ -126,13 +149,15 @@
|
||||
},
|
||||
runNow: 0, // 0 初始化 1运行中 2运行结束 3取消运行
|
||||
form: {
|
||||
// TODO: 保存其他几个参数
|
||||
// itemSrc: '/Users/koro/work/web_my/testCommit',
|
||||
itemSrc: '点击选择要commit的项目文件夹',
|
||||
fileName: 'commit.md',
|
||||
commitMsg: 'autoCommit',
|
||||
timeArr: [
|
||||
{
|
||||
value: ''
|
||||
value: '',
|
||||
commitNumber: 0
|
||||
}
|
||||
],
|
||||
commitNumber: 1,
|
||||
@ -167,6 +192,9 @@
|
||||
},
|
||||
mounted() {
|
||||
this.initListener();
|
||||
if(isWeb){
|
||||
this.form.itemSrc = '随便一个地址'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submitForm(formName) {
|
||||
@ -180,13 +208,15 @@
|
||||
},
|
||||
// 开始commit
|
||||
runCommit() {
|
||||
let params = this.form
|
||||
params.formatTime = this.mapTimeData()
|
||||
this.runNow = 1
|
||||
this.showText.paramsStr = JSON.stringify(params)
|
||||
this.clearLog()
|
||||
this.showText.paramsStr = JSON.stringify(this.form)
|
||||
this.showText.oldParams = this.showText.paramsStr
|
||||
// this.mockLog()
|
||||
this.postMessage('commit', params);
|
||||
if(isWeb){
|
||||
this.mockLog()
|
||||
}else{
|
||||
this.postMessage('commit', this.form);
|
||||
}
|
||||
},
|
||||
// 发送消息到插件
|
||||
postMessage(command, data) {
|
||||
@ -200,6 +230,7 @@
|
||||
this.showText.logArr.unshift(`数据: ${data}`);
|
||||
this.formatLog()
|
||||
},
|
||||
// 接收日志
|
||||
acceptLogFn(paramArr){
|
||||
const logStr = paramArr.join(' ')
|
||||
this.showText.logArr.unshift(logStr);
|
||||
@ -219,9 +250,13 @@
|
||||
message: `${data}根目录没有.git文件夹`,
|
||||
duration: 0
|
||||
});
|
||||
} else if(command === 'commit 完成'){
|
||||
// commit 完成
|
||||
this.runNow = 2
|
||||
} else if(command === 'console-log'){
|
||||
this.acceptLogFn(data)
|
||||
}else if(command === 'isProduction'){
|
||||
// 调试模式 查看通信
|
||||
this.isProduction = data
|
||||
}
|
||||
if(!this.isProduction){
|
||||
@ -231,12 +266,15 @@
|
||||
},
|
||||
// 重置: commit成功和中断commit
|
||||
reset() {
|
||||
// TODO: runNow 3 取消运行
|
||||
this.runNow = 2;
|
||||
this.showText.paramsStr = ''
|
||||
this.showText.oldParams = ''
|
||||
this.runNow = 3;
|
||||
if(isWeb){
|
||||
clearInterval(this.mockLogTime)
|
||||
this.mockLogTime = null
|
||||
} else{
|
||||
this.postMessage('cancel autoCommit')
|
||||
}
|
||||
},
|
||||
// 写html时用
|
||||
// 模拟日志 写html时用
|
||||
mockLog(){
|
||||
this.showText.logArr = [
|
||||
'res 开始 undefined',
|
||||
@ -247,14 +285,13 @@
|
||||
'总commit次数1'
|
||||
]
|
||||
let num = 0;
|
||||
let timeId = setInterval(() => {
|
||||
this.mockLogTime = setInterval(() => {
|
||||
if(num< 100){
|
||||
num++
|
||||
this.showText.logArr.unshift(`一些文字${num}`)
|
||||
this.formatLog()
|
||||
}else{
|
||||
this.reset()
|
||||
clearInterval(timeId)
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
@ -272,19 +309,14 @@
|
||||
removeTime(index) {
|
||||
this.form.timeArr.splice(index, 1)
|
||||
},
|
||||
// format 一下时间 少嵌套一层
|
||||
mapTimeData() {
|
||||
return this.form.timeArr.map(item => {
|
||||
return item.value
|
||||
})
|
||||
},
|
||||
chooseItem() {
|
||||
this.postMessage('choose-item')
|
||||
},
|
||||
// 增加时间范围选择
|
||||
addTimeRange() {
|
||||
this.form.timeArr.push({
|
||||
value: ''
|
||||
value: '',
|
||||
commitNumber: 0
|
||||
});
|
||||
},
|
||||
fileNameChange(value) {
|
||||
@ -298,7 +330,7 @@
|
||||
}
|
||||
},
|
||||
}
|
||||
}).$mount('#xpLogin');
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user