git clone功能
网站登录 → 创建项目 Git Token → clone → 本地修改、commit → push main → 网站工作区刷新后显示最新内容 → 网站手动发布到社区
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
package com.linkerbot.vibemake.api.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.linkerbot.vibemake.common.BusinessException;
|
||||
import com.linkerbot.vibemake.security.GitAuthenticationFilter;
|
||||
import com.linkerbot.vibemake.service.git.*;
|
||||
|
||||
import jakarta.servlet.http.*;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@io.swagger.v3.oas.annotations.Hidden
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class GitProtocolController {
|
||||
private static final Logger log = LoggerFactory.getLogger(GitProtocolController.class);
|
||||
private final GitGateway git;
|
||||
private final LfsGateway lfs;
|
||||
private final ObjectMapper json;
|
||||
|
||||
@RequestMapping("/git/projects/{projectCode}.git/{*endpoint}")
|
||||
public void protocol(
|
||||
@PathVariable String projectCode,
|
||||
@PathVariable String endpoint,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws IOException {
|
||||
GitAccess access = (GitAccess) request.getAttribute(GitAuthenticationFilter.ACCESS);
|
||||
try {
|
||||
if (access == null || !projectCode.equals(access.projectCode()))
|
||||
throw GitTokens.unauthorized();
|
||||
String path = endpoint.startsWith("/") ? endpoint.substring(1) : endpoint;
|
||||
if (path.startsWith("info/lfs/actions/")) {
|
||||
LfsGateway.Action action =
|
||||
(LfsGateway.Action) request.getAttribute(GitAuthenticationFilter.ACTION);
|
||||
if (action == null) throw GitTokens.unauthorized();
|
||||
lfs.action(action, request, response);
|
||||
} else if (path.startsWith("info/lfs/"))
|
||||
lfs.serve(access, path.substring(9), request, response);
|
||||
else git.serve(access, path, request, response);
|
||||
} catch (BusinessException error) {
|
||||
log.warn(
|
||||
"Git 协议请求拒绝 projectCode={} code={} status={}",
|
||||
projectCode,
|
||||
error.code(),
|
||||
error.status());
|
||||
fail(request, response, error);
|
||||
} catch (Exception error) {
|
||||
log.warn(
|
||||
"Git 协议请求中断 projectCode={} errorType={}",
|
||||
projectCode,
|
||||
error.getClass().getSimpleName());
|
||||
fail(
|
||||
request,
|
||||
response,
|
||||
new BusinessException(502, "GIT_UPSTREAM_ERROR", "Git 传输中断,请刷新工作区核对结果"));
|
||||
}
|
||||
}
|
||||
|
||||
private void fail(
|
||||
HttpServletRequest request, HttpServletResponse response, BusinessException error) {
|
||||
try {
|
||||
GitAuthenticationFilter.failure(request, response, json, error);
|
||||
} catch (IOException ignored) {
|
||||
/* 已断开连接不再进入平台 JSON 异常处理器。 */
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.linkerbot.vibemake.api.controller;
|
||||
|
||||
import com.linkerbot.vibemake.bean.GitContracts.*;
|
||||
import com.linkerbot.vibemake.common.*;
|
||||
import com.linkerbot.vibemake.security.CurrentUser;
|
||||
import com.linkerbot.vibemake.service.git.*;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/workspace/projects/{projectCode}/git")
|
||||
public class ProjectGitController {
|
||||
private final GitGateway gateway;
|
||||
private final GitTokens tokens;
|
||||
|
||||
@ModelAttribute
|
||||
public void noStore(HttpServletResponse response) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ApiResponse<ConnectionView> connection(@PathVariable String projectCode) {
|
||||
return ApiResponse.success(gateway.connection(CurrentUser.required(), projectCode));
|
||||
}
|
||||
|
||||
@GetMapping("/tokens")
|
||||
public ApiResponse<PageResponse<TokenView>> list(
|
||||
@PathVariable String projectCode,
|
||||
@RequestParam(defaultValue = "1") long page,
|
||||
@RequestParam(defaultValue = "20") long size) {
|
||||
return ApiResponse.success(tokens.list(CurrentUser.required(), projectCode, page, size));
|
||||
}
|
||||
|
||||
@PostMapping("/tokens")
|
||||
public ApiResponse<IssuedToken> issue(
|
||||
@PathVariable String projectCode,
|
||||
@Valid @RequestBody TokenInput input,
|
||||
HttpServletResponse response) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
return ApiResponse.success(tokens.issue(CurrentUser.required(), projectCode, input));
|
||||
}
|
||||
|
||||
@DeleteMapping("/tokens/{tokenCode}")
|
||||
public ApiResponse<Void> revoke(
|
||||
@PathVariable String projectCode, @PathVariable String tokenCode) {
|
||||
tokens.revoke(CurrentUser.required(), projectCode, tokenCode);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,22 @@ vibemake:
|
||||
gitea:
|
||||
connect-timeout: 5s
|
||||
request-timeout: 30s
|
||||
git:
|
||||
enabled: ${GIT_ENABLED:true}
|
||||
public-base-url: ${GIT_PUBLIC_BASE_URL:}
|
||||
upstream-username: ${GIT_UPSTREAM_USERNAME:}
|
||||
upstream-token: ${GIT_UPSTREAM_TOKEN:}
|
||||
timeout: ${GIT_REQUEST_TIMEOUT:10m}
|
||||
max-pack-bytes: ${GIT_MAX_PACK_BYTES:5368709120}
|
||||
max-lfs-object-bytes: ${GIT_MAX_LFS_OBJECT_BYTES:1073741824}
|
||||
max-metadata-bytes: ${GIT_MAX_METADATA_BYTES:8388608}
|
||||
max-batch-objects: ${GIT_MAX_BATCH_OBJECTS:500}
|
||||
read-concurrent: ${GIT_READ_CONCURRENT:4}
|
||||
push-concurrent: ${GIT_PUSH_CONCURRENT:2}
|
||||
lfs-concurrent: ${GIT_LFS_CONCURRENT:8}
|
||||
git-requests-per-minute: ${GIT_REQUESTS_PER_MINUTE:120}
|
||||
lfs-requests-per-minute: ${GIT_LFS_REQUESTS_PER_MINUTE:600}
|
||||
auth-failures-per-minute: ${GIT_AUTH_FAILURES_PER_MINUTE:20}
|
||||
archive:
|
||||
max-bytes: ${ARCHIVE_MAX_BYTES:1073741824}
|
||||
timeout: ${ARCHIVE_TIMEOUT:5m}
|
||||
|
||||
Reference in New Issue
Block a user