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

feat: file and directory options for status command #646

Merged
merged 1 commit into from
Sep 28, 2023
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
12 changes: 12 additions & 0 deletions src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@
.getBranchProgress(this.projectId, branchId, limit, offset));
}

@Override
public List<LanguageProgress> getFileProgress(Long fileId) {
return executeRequestFullList((limit, offset) -> this.client.getTranslationStatusApi()
.getFileProgress(this.projectId, fileId, limit, offset));

Check warning on line 134 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L133-L134

Added lines #L133 - L134 were not covered by tests
}

@Override
public List<LanguageProgress> getDirectoryProgress(Long directoryId) {
return executeRequestFullList((limit, offset) -> this.client.getTranslationStatusApi()
.getDirectoryProgress(this.projectId, directoryId, limit, offset));

Check warning on line 140 in src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java#L139-L140

Added lines #L139 - L140 were not covered by tests
}

@Override
public Branch addBranch(AddBranchRequest request) {
return executeRequest(() -> this.client.getSourceFilesApi()
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/crowdin/cli/client/ProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ default CrowdinProjectFull downloadFullProject() {

List<LanguageProgress> getBranchProgress(Long branchId);

List<LanguageProgress> getFileProgress(Long fileId);

List<LanguageProgress> getDirectoryProgress(Long directoryId);

SourceString addSourceString(AddSourceStringRequest request);

List<SourceString> listSourceString(Long fileId, Long branchId, String labelIds, String filter, String croql);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NewAction<PropertiesWithFiles, ProjectClient> listTranslations(
NewAction<ProjectProperties, ProjectClient> listLanguages(BaseCli.LanguageCode code, boolean noProgress, boolean plainView);

NewAction<ProjectProperties, ProjectClient> status(
boolean noProgress, String branchName, String languageId, boolean isVerbose, boolean showTranslated, boolean showApproved, boolean failIfIncomplete);
boolean noProgress, String branchName, String languageId, String file, String directory, boolean isVerbose, boolean showTranslated, boolean showApproved, boolean failIfIncomplete);

NewAction<ProjectProperties, ProjectClient> stringAdd(
boolean noProgress, String text, String identifier, Integer maxLength, String context, List<String> files, List<String> labelNames, Boolean hidden);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public NewAction<ProjectProperties, ProjectClient> listLanguages(BaseCli.Languag

@Override
public NewAction<ProjectProperties, ProjectClient> status(
boolean noProgress, String branchName, String languageId, boolean isVerbose, boolean showTranslated, boolean showApproved, boolean failIfIncomplete
boolean noProgress, String branchName, String languageId, String file, String directory, boolean isVerbose, boolean showTranslated, boolean showApproved, boolean failIfIncomplete
) {
return new StatusAction(noProgress, branchName, languageId, isVerbose, showTranslated, showApproved, failIfIncomplete);
return new StatusAction(noProgress, branchName, languageId, file, directory, isVerbose, showTranslated, showApproved, failIfIncomplete);
}

@Override
Expand Down
42 changes: 32 additions & 10 deletions src/main/java/com/crowdin/cli/commands/actions/StatusAction.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.crowdin.cli.commands.actions;

import com.crowdin.cli.client.CrowdinProject;
import com.crowdin.cli.client.CrowdinProjectFull;
import com.crowdin.cli.client.ProjectClient;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.utils.Utils;
import com.crowdin.cli.utils.console.ConsoleSpinner;
import com.crowdin.client.sourcefiles.model.Branch;
import com.crowdin.client.translationstatus.model.LanguageProgress;
Expand All @@ -21,15 +22,19 @@ class StatusAction implements NewAction<ProjectProperties, ProjectClient> {
private boolean noProgress;
private String branchName;
private String languageId;
private String file;
private String directory;
private boolean isVerbose;
private boolean showTranslated;
private boolean showApproved;
private boolean failIfIncomplete;

public StatusAction(boolean noProgress, String branchName, String languageId, boolean isVerbose, boolean showTranslated, boolean showApproved, boolean failIfIncomplete) {
public StatusAction(boolean noProgress, String branchName, String languageId, String file, String directory, boolean isVerbose, boolean showTranslated, boolean showApproved, boolean failIfIncomplete) {
this.noProgress = noProgress;
this.branchName = branchName;
this.languageId = languageId;
this.file = file;
this.directory = directory;
this.isVerbose = isVerbose;
this.showTranslated = showTranslated;
this.showApproved = showApproved;
Expand All @@ -38,8 +43,8 @@ public StatusAction(boolean noProgress, String branchName, String languageId, bo

@Override
public void act(Outputter out, ProjectProperties pb, ProjectClient client) {
CrowdinProject project = ConsoleSpinner.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info",
this.noProgress, false, client::downloadProjectWithLanguages);
CrowdinProjectFull project = ConsoleSpinner.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info",
this.noProgress, false, () -> client.downloadFullProject(branchName));

if (languageId != null) {
project.findLanguageById(languageId, true)
Expand All @@ -53,15 +58,32 @@ public void act(Outputter out, ProjectProperties pb, ProjectClient client) {
.getId();

List<LanguageProgress> progresses;
if (branchId == null) {
progresses = client.getProjectProgress(languageId);
} else {

if (file != null) {
String filePath = Utils.unixPath(Utils.sepAtStart(file));
Long fileId = project.getFileInfos().stream()
.filter(f -> filePath.equals(f.getPath()))
.findFirst()
.orElseThrow(() -> new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.file_not_exists"), file)))
.getId();
progresses = client.getFileProgress(fileId);
} else if (directory != null) {
String directoryPath = Utils.unixPath(Utils.sepAtStart(directory));
Long directoryId = project.getDirectories().values().stream()
.filter(d -> directoryPath.equals(d.getPath()))
.findFirst()
.orElseThrow(() -> new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.dir_not_exists"), directory)))
.getId();
progresses = client.getDirectoryProgress(directoryId);
} else if (branchId != null) {
progresses = client.getBranchProgress(branchId);
if (languageId != null) {
progresses = progresses.stream()
} else {
progresses = client.getProjectProgress(languageId);
}
if (languageId != null) {
progresses = progresses.stream()
.filter(langProgress -> languageId.equals(langProgress.getLanguageId()))
.collect(Collectors.toList());
}
}

if (isVerbose) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import com.crowdin.cli.properties.ProjectProperties;
import picocli.CommandLine;

import java.util.ArrayList;
import java.util.List;

import static java.util.Objects.nonNull;

@CommandLine.Command(
name = CommandNames.STATUS_PROOFREADING,
sortOptions = false
Expand All @@ -18,11 +23,26 @@
@CommandLine.Option(names = {"-b", "--branch"}, paramLabel = "...", order = -2)
protected String branchName;

@CommandLine.Option(names = {"-f", "--file"}, paramLabel = "...", descriptionKey = "crowdin.status.file-path", order = -2)
protected String file;

@CommandLine.Option(names = {"-d", "--directory"}, paramLabel = "...", descriptionKey = "crowdin.status.directory-path", order = -2)
protected String directory;

@CommandLine.Option(names = {"--fail-if-incomplete"}, paramLabel = "...", order = -2)
protected boolean failIfIncomplete;

@Override
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
return actions.status(noProgress, branchName, languageId, isVerbose, false, true, failIfIncomplete);
return actions.status(noProgress, branchName, languageId, file, directory, isVerbose, false, true, failIfIncomplete);
}

@Override
protected List<String> checkOptions() {
List<String> errors = new ArrayList<>();
if (nonNull(directory) && nonNull(file)) {
errors.add(RESOURCE_BUNDLE.getString("error.status.only_one_allowed"));

Check warning on line 44 in src/main/java/com/crowdin/cli/commands/picocli/StatusProofreadingSubcommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/picocli/StatusProofreadingSubcommand.java#L44

Added line #L44 was not covered by tests
}
return errors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import com.crowdin.cli.properties.ProjectProperties;
import picocli.CommandLine;

import java.util.ArrayList;
import java.util.List;

import static java.util.Objects.nonNull;

@CommandLine.Command(
name = CommandNames.STATUS,
sortOptions = false,
Expand All @@ -22,11 +27,26 @@
@CommandLine.Option(names = {"-b", "--branch"}, paramLabel = "...", order = -2)
protected String branchName;

@CommandLine.Option(names = {"-f", "--file"}, paramLabel = "...", descriptionKey = "crowdin.status.file-path", order = -2)
protected String file;

@CommandLine.Option(names = {"-d", "--directory"}, paramLabel = "...", descriptionKey = "crowdin.status.directory-path", order = -2)
protected String directory;

@CommandLine.Option(names = {"--fail-if-incomplete"}, paramLabel = "...", order = -2)
protected boolean failIfIncomplete;

@Override
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
return actions.status(noProgress, branchName, languageId, isVerbose, true, true, failIfIncomplete);
return actions.status(noProgress, branchName, languageId, file, directory, isVerbose, true, true, failIfIncomplete);
}

@Override
protected List<String> checkOptions() {
List<String> errors = new ArrayList<>();
if (nonNull(directory) && nonNull(file)) {
errors.add(RESOURCE_BUNDLE.getString("error.status.only_one_allowed"));

Check warning on line 48 in src/main/java/com/crowdin/cli/commands/picocli/StatusSubcommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/picocli/StatusSubcommand.java#L48

Added line #L48 was not covered by tests
}
return errors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import com.crowdin.cli.properties.ProjectProperties;
import picocli.CommandLine;

import java.util.ArrayList;
import java.util.List;

import static java.util.Objects.nonNull;

@CommandLine.Command(
name = CommandNames.STATUS_TRANSLATION,
sortOptions = false
Expand All @@ -18,11 +23,26 @@
@CommandLine.Option(names = {"-b", "--branch"}, paramLabel = "...", order = -2)
protected String branchName;

@CommandLine.Option(names = {"-f", "--file"}, paramLabel = "...", descriptionKey = "crowdin.status.file-path", order = -2)
protected String file;

@CommandLine.Option(names = {"-d", "--directory"}, paramLabel = "...", descriptionKey = "crowdin.status.directory-path", order = -2)
protected String directory;

@CommandLine.Option(names = {"--fail-if-incomplete"}, paramLabel = "...", order = -2)
protected boolean failIfIncomplete;

@Override
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
return actions.status(noProgress, branchName, languageId, isVerbose, true, false, failIfIncomplete);
return actions.status(noProgress, branchName, languageId, file, directory, isVerbose, true, false, failIfIncomplete);
}

@Override
protected List<String> checkOptions() {
List<String> errors = new ArrayList<>();
if (nonNull(directory) && nonNull(file)) {
errors.add(RESOURCE_BUNDLE.getString("error.status.only_one_allowed"));

Check warning on line 44 in src/main/java/com/crowdin/cli/commands/picocli/StatusTranslationSubcommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/picocli/StatusTranslationSubcommand.java#L44

Added line #L44 was not covered by tests
}
return errors;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ crowdin.status.usage.description=Show translation and proofreading progress for
crowdin.status.usage.customSynopsis=@|fg(green) crowdin status|@ [SUBCOMMAND] [CONFIG OPTIONS] [OPTIONS]
crowdin.status.language=Use this option to show progress for a single specified language. Default: all
crowdin.status.fail-if-incomplete=Fail execution if the current project is not fully approved
crowdin.status.directory-path=Path to the directory in Crowdin
crowdin.status.file-path=Path to the source file in Crowdin

# CROWDIN STATUS TRANSLATION COMMAND
crowdin.status.translation.usage.description=Show only translation progress for a project
Expand Down Expand Up @@ -449,6 +451,8 @@ error.glossary.first_line_contains_header_and_wrong_format='--first-line-contain
error.glossary.no_permission=You do not have permission to manage this glossary
error.glossary.no_language_id='--language' is required for creating new glossary

error.status.only_one_allowed=Only one of the following options can be used at a time: '--file', '--directory'

error.tm.build_tm=Failed to build the translation memory
error.tm.not_found_by_id=Couldn't find translation memory by the specified ID
error.tm.not_found_by_name=Couldn't find translation memory by the specified name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testListTranslations() {

@Test
public void testStatus() {
assertNotNull(actions.status(false, null, null, false, false, false, false));
assertNotNull(actions.status(false, null, null, null, null, false, false, false, false));
}

@Test
Expand Down
Loading