README 外链图片转存 OSS
This commit is contained in:
@@ -67,6 +67,10 @@ vibemake:
|
||||
worker-enabled: ${ADMIN_IMPORT_WORKER_ENABLED:true}
|
||||
migration-timeout: ${ADMIN_MIGRATION_TIMEOUT:30m}
|
||||
import-concurrency: ${ADMIN_IMPORT_CONCURRENCY:2}
|
||||
readme-images:
|
||||
enabled: ${README_IMAGES_ENABLED:true}
|
||||
max-bytes: ${README_IMAGE_MAX_BYTES:20971520}
|
||||
concurrency: ${README_IMAGE_CONCURRENCY:2}
|
||||
oss:
|
||||
enabled: ${OSS_ENABLED:true}
|
||||
region: ${OSS_REGION:cn-beijing}
|
||||
|
||||
+32
-1
@@ -68,6 +68,14 @@ class AdminWorkflowTest {
|
||||
return new FakeOssObjectStore();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
com.linkerbot.vibemake.service.readme.ReadmeImages fakeReadmeImages(OssProperties oss) {
|
||||
return new com.linkerbot.vibemake.service.readme.ReadmeImages(
|
||||
new com.linkerbot.vibemake.service.config.ReadmeImageProperties(), oss,
|
||||
url -> "https://assets.example.invalid/readme-images/image.png");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
GitHubSourceChecks fakeSources() {
|
||||
@@ -1742,6 +1750,29 @@ class AdminWorkflowTest {
|
||||
.path("data").path("status").asText()).isEqualTo("SUCCEEDED");
|
||||
}
|
||||
|
||||
@Test
|
||||
void githubMigrationReplacesReadmeImagesAndPreservesOriginalShaWithoutPublishing() throws Exception {
|
||||
JsonNode task = createImport();
|
||||
gitea.migrationReadme = "# project\n\n\n\n";
|
||||
imports.run(task.path("taskCode").asText());
|
||||
Project project = projects.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Project>()
|
||||
.eq(Project::getProjectCode, task.path("projectCode").asText()));
|
||||
ProjectImportTask finished = tasks.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<ProjectImportTask>()
|
||||
.eq(ProjectImportTask::getTaskCode, task.path("taskCode").asText()));
|
||||
com.linkerbot.vibemake.service.gitea.GiteaClient.Repository repository = new com.linkerbot.vibemake.service.gitea.GiteaClient.Repository(project.getGiteaRepoId(), project.getGiteaOwner(), project.getGiteaRepoName());
|
||||
com.linkerbot.vibemake.service.readme.ReadmeRepository.State state = com.linkerbot.vibemake.service.readme.ReadmeMigrationReceipt.state(json, finished.getReceiptJson());
|
||||
assertThat(finished.getStatus()).isEqualTo("SUCCEEDED");
|
||||
assertThat(state.baseSha).isEqualTo(finished.getTargetSha()).isNotEqualTo(state.resultSha);
|
||||
assertThat(state.resultSha).isEqualTo(gitea.head(repository));
|
||||
assertThat(project.getPublishStatus()).isEqualTo("UNPUBLISHED");
|
||||
assertThat(new String(gitea.file(repository, state.resultSha, "README.md").bytes(), java.nio.charset.StandardCharsets.UTF_8))
|
||||
.contains("https://assets.example.invalid/readme-images/image.png", "", "https://img.shields.io/badge/build-pass-green.svg");
|
||||
int committed = gitea.commitCalls;
|
||||
imports.run(task.path("taskCode").asText());
|
||||
assertThat(gitea.migrations).isEqualTo(1);
|
||||
assertThat(gitea.commitCalls).isEqualTo(committed);
|
||||
}
|
||||
|
||||
@Test
|
||||
void receiptSurvivesAssociationFailureAndResumesWithoutSecondMigration() throws Exception {
|
||||
JsonNode task = createImport();
|
||||
@@ -1757,7 +1788,7 @@ class AdminWorkflowTest {
|
||||
.eq(ProjectImportTask::getTaskCode, code));
|
||||
assertThat(failed.getStatus()).isEqualTo("REVIEW");
|
||||
assertThat(failed.getReceiptJson()).isNotNull();
|
||||
assertThat(failed.getPhase()).isEqualTo("BRANCH_READY");
|
||||
assertThat(failed.getPhase()).isEqualTo("README_IMAGES");
|
||||
assertThat(
|
||||
jdbc.queryForObject(
|
||||
"SELECT repo_status FROM project WHERE project_code=?",
|
||||
|
||||
@@ -21,6 +21,7 @@ final class FakeGiteaClient implements GiteaClient {
|
||||
private final AtomicLong sequence = new AtomicLong();
|
||||
String lastAuthorCode;
|
||||
int migrations;
|
||||
String migrationReadme;
|
||||
boolean migrationTimeout;
|
||||
boolean migrationRejected;
|
||||
boolean timeoutNextDelete;
|
||||
@@ -55,6 +56,7 @@ final class FakeGiteaClient implements GiteaClient {
|
||||
migrationNames.clear();
|
||||
mainReady.clear();
|
||||
migrations = 0;
|
||||
migrationReadme = null;
|
||||
deletions = 0;
|
||||
migrationDescriptions.clear();
|
||||
migrationTimeout = false;
|
||||
@@ -223,6 +225,8 @@ final class FakeGiteaClient implements GiteaClient {
|
||||
migrations++;
|
||||
migrationNames.add(name);
|
||||
Repository repository = createRepository(name, true);
|
||||
if (migrationReadme != null) repo(repository).snapshots.get(repo(repository).head)
|
||||
.put("README.md", migrationReadme.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
RemoteRepository remote =
|
||||
new RemoteRepository(
|
||||
repository.id(), "vibemake", name, true, false, false, source, "master");
|
||||
|
||||
Reference in New Issue
Block a user