Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check strings upload status #836

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.crowdin.client.languages.model.Language;
import com.crowdin.client.projectsgroups.model.Type;
import com.crowdin.client.sourcefiles.model.*;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -316,7 +317,31 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {
String.format(RESOURCE_BUNDLE.getString("error.upload_to_storage"), sourceFile.getAbsolutePath()));
}
try {
client.addSourceStringsBased(request);
ConsoleSpinner.execute(
out,
"message.spinner.uploading_strings",
"message.spinner.upload_strings_failed",
this.plainView,
this.plainView,
() -> {
UploadStringsProgress uploadStrings = client.addSourceStringsBased(request);
String uploadId = uploadStrings.getIdentifier();

while (!"finished".equalsIgnoreCase(uploadStrings.getStatus())) {
ConsoleSpinner.update(
String.format(RESOURCE_BUNDLE.getString("message.spinner.uploading_strings_percents"),
uploadStrings.getProgress()));
Thread.sleep(1000);

uploadStrings = client.getUploadStringsStatus(uploadId);

if ("failed".equalsIgnoreCase(uploadStrings.getStatus())) {
throw new RuntimeException(RESOURCE_BUNDLE.getString("message.spinner.upload_strings_failed"));
}
}
ConsoleSpinner.update(String.format(RESOURCE_BUNDLE.getString("message.spinner.uploading_strings_percents"), 100));
return uploadStrings;
});
} catch (Exception e) {
errorsPresented.set(true);
throw ExitCodeExceptionMapper.remap(e, String.format(RESOURCE_BUNDLE.getString("error.uploading_file"), fileFullPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.crowdin.client.sourcefiles.model.SpreadsheetFileImportOptions;
import com.crowdin.client.sourcefiles.model.UpdateFileRequest;
import com.crowdin.client.sourcestrings.model.ImportOptions;
import com.crowdin.client.sourcestrings.model.UploadStringsProgress;
import com.crowdin.client.sourcestrings.model.UploadStringsRequest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -797,23 +798,27 @@ public void testUploadOneSource_StringBasedProject() throws ResponseException {
ProjectClient client = mock(ProjectClient.class);
CrowdinProjectFull build = ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).addBranches(2L, "main").build();
build.setType(Type.STRINGS_BASED);
UploadStringsRequest uploadStringsRequest = new UploadStringsRequest() {
{
setStorageId(1L);
setBranchId(2L);
setImportOptions(new ImportOptions());
}};
UploadStringsProgress uploadStringsProgress = new UploadStringsProgress();
uploadStringsProgress.setIdentifier("testid");
uploadStringsProgress.setStatus("finished");
when(client.downloadFullProject())
.thenReturn(build);
when(client.uploadStorage(eq("first.po"), any()))
.thenReturn(1L);
when(client.addSourceStringsBased(eq(uploadStringsRequest))).thenReturn(uploadStringsProgress);

NewAction<PropertiesWithFiles, ProjectClient> action = new UploadSourcesAction("main", false, false, true, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
verify(client).listLabels();
verify(client).uploadStorage(eq("first.po"), any());
UploadStringsRequest uploadStringsRequest = new UploadStringsRequest() {
{
setStorageId(1L);
setBranchId(2L);
setImportOptions(new ImportOptions());
}};
verify(client).addSourceStringsBased(eq(uploadStringsRequest));
verifyNoMoreInteractions(client);
}
Expand Down
Loading