Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
def7 2021-10-14 18:44:18 +08:00
commit 397f4acfb0
4 changed files with 21 additions and 26 deletions

View File

@ -138,9 +138,9 @@ public class BuildInfoManage extends BaseBuild implements Runnable {
* @param delay 延迟执行的时间 单位秒
* @return this
*/
public static BuildInfoManage create(BuildInfoModel buildInfoModel,
RepositoryModel repositoryModel,
UserModel userModel,
public static BuildInfoManage create(final BuildInfoModel buildInfoModel,
final RepositoryModel repositoryModel,
final UserModel userModel,
Integer delay) {
if (BUILD_MANAGE_MAP.containsKey(buildInfoModel.getId())) {
throw new JpomRuntimeException("当前构建还在进行中");
@ -279,7 +279,7 @@ public class BuildInfoManage extends BaseBuild implements Runnable {
BuildInfoManage.this.log("初始化构建记录失败,异常结束");
return false;
}
this.log("start build in file : " + FileUtil.getAbsolutePath(this.gitFile));
this.log("#" + this.buildInfoModel.getBuildId() + " start build in file : " + FileUtil.getAbsolutePath(this.gitFile));
if (delay != null && delay > 0) {
// 延迟执行
this.log("Execution delayed by " + delay + " seconds");

View File

@ -27,6 +27,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.LineHandler;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.validator.ValidatorConfig;
import cn.jiangzeyin.common.validator.ValidatorItem;
@ -51,6 +52,7 @@ import io.jpom.service.dblog.DbBuildHistoryLogService;
import io.jpom.service.dblog.RepositoryService;
import io.jpom.util.LimitQueue;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@ -88,25 +90,17 @@ public class BuildInfoManageController extends BaseServerController {
@Feature(method = MethodFeature.EXECUTE)
public String start(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据")) String id) {
BuildInfoModel item = buildInfoService.getByKey(id);
if (item == null) {
return JsonMessage.getString(404, "没有对应数据");
}
Assert.notNull(item, "没有对应数据");
String e = buildInfoService.checkStatus(item.getStatus());
if (e != null) {
return e;
}
Assert.isNull(e, e);
// set buildId field
if (item.getBuildId() == null) {
item.setBuildId(0);
}
item.setBuildId(item.getBuildId() + 1);
int buildId = ObjectUtil.defaultIfNull(item.getBuildId(), 0);
item.setBuildId(buildId + 1);
// userModel
UserModel userModel = getUser();
String optUserName = userModel == null ? "openApi" : UserModel.getOptUserName(userModel);
item.setModifyUser(optUserName);
buildInfoService.update(item);
// 执行构建
return buildInfoService.start(item, userModel, null);
}
@ -176,16 +170,13 @@ public class BuildInfoManageController extends BaseServerController {
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "没有buildId") int buildId,
@ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "line") int line) {
BuildInfoModel item = buildInfoService.getByKey(id);
if (item == null) {
return JsonMessage.getString(404, "没有对应数据");
}
Assert.notNull(item, "没有对应数据");
if (buildId > item.getBuildId()) {
return JsonMessage.getString(405, "还没有对应的构建记录");
}
File file = BuildUtil.getLogFile(item.getId(), buildId);
if (file.isDirectory()) {
return JsonMessage.getString(300, "日志文件错误");
}
Assert.state(FileUtil.isFile(file), "日志文件错误");
if (!file.exists()) {
if (buildId == item.getBuildId()) {
return JsonMessage.getString(201, "还没有日志文件");

View File

@ -79,7 +79,7 @@ public class BuildInfoService extends BaseDbService<BuildInfoModel> {
* @param delay 延迟的时间
* @return json
*/
public String start(BuildInfoModel buildInfoModel, UserModel userModel, Integer delay) {
public String start(final BuildInfoModel buildInfoModel, final UserModel userModel, Integer delay) {
// load repository
RepositoryModel repositoryModel = repositoryService.getByKey(buildInfoModel.getRepositoryId());
if (null == repositoryModel) {
@ -104,7 +104,7 @@ public class BuildInfoService extends BaseDbService<BuildInfoModel> {
Objects.requireNonNull(nowStatus);
if (BuildStatus.Ing == nowStatus ||
BuildStatus.PubIng == nowStatus) {
return JsonMessage.getString(501, "当前还在:" + nowStatus.getDesc());
return "当前还在:" + nowStatus.getDesc();
}
return null;
}

View File

@ -16,6 +16,7 @@ export default {
return {
logTimer: null,
logText: "loading...",
line: 1,
};
},
beforeDestroy() {
@ -34,7 +35,7 @@ export default {
const params = {
id: this.temp.id,
buildId: this.temp.buildId,
line: 1,
line: this.line,
};
loadBuildLog(params).then((res) => {
if (res.code === 200) {
@ -43,10 +44,13 @@ export default {
clearInterval(this.logTimer);
}
//
this.logText = "";
if (this.logText === "loading...") {
this.logText = "";
}
res.data.dataLines.forEach((element) => {
this.logText += `${element}\r\n`;
});
this.line = res.data.line;
//
this.$nextTick(() => {
setTimeout(() => {