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

Added 'skip-i18n-push' label handling to GithubPRInfoCommand #14

Merged
merged 1 commit into from
Aug 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,27 @@ public class GithubPRInfoCommand extends Command {
description = "The Github repository owner")
String owner;

@Parameter(
names = {"--skip-i18n-push-label"},
arity = 1,
required = false,
description = "Github label name that is used to trigger skipping i18n push")
String skipI18NPushLabel = "skip-i18n-push";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we plan to customize this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt having an option to configure the label name to monitor for would be more useful than hard-coding it but for our purposes I still intend on using skip-i18n-push


@Parameter(
names = {"--skip-i18n-push-comment"},
arity = 1,
required = false,
description =
"Comment added to PR to indicate that the push to the Mojito backend will be skipped")
String skipI18NPushComment =
":warning: I18N strings will not be pushed to Mojito as '%s' label is applied to this PR.";

@Override
public void execute() throws CommandException {

skipI18NPushComment = String.format(skipI18NPushComment, skipI18NPushLabel);

if (githubClients == null) {
throw new CommandException(
"Github must be configured with properties: l10n.githubClients.<client>.appId, l10n.githubClients.<client>.key and l10n.githubClients.<client>.owner");
Expand Down Expand Up @@ -94,11 +112,26 @@ public void execute() throws CommandException {
} else {
consoleWriterAnsiCodeEnabledFalse.a("MOJITO_SKIP_I18N_CHECKS=false").println();
}

if (github.isLabelAppliedToPR(repository, prNumber, skipI18NPushLabel)) {
addPushSkippedComment(prComments, github);
consoleWriterAnsiCodeEnabledFalse.a("MOJITO_SKIP_I18N_PUSH=true").println();
} else {
consoleWriterAnsiCodeEnabledFalse.a("MOJITO_SKIP_I18N_PUSH=false").println();
}

} catch (GithubException e) {
throw new CommandException(e);
}
}

private void addPushSkippedComment(List<GHIssueComment> prComments, GithubClient github) {
if (!prComments.stream()
.anyMatch(ghIssueComment -> ghIssueComment.getBody().contains(skipI18NPushComment))) {
github.addCommentToPR(repository, prNumber, skipI18NPushComment);
}
}

private static boolean isSkipChecks(List<GHIssueComment> prComments) {
return prComments.stream()
.anyMatch(ghIssueComment -> ghIssueComment.getBody().contains(SKIP_I18N_CHECKS_FLAG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void testExecute() {
verify(consoleWriterMock, times(1)).a("MOJITO_GITHUB_AUTHOR_USERNAME=");
verify(consoleWriterMock, times(1)).a("some");
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_CHECKS=false");
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_PUSH=false");
}

@Test
Expand All @@ -76,6 +77,48 @@ public void testExecuteWithChecksSkipped() throws IOException {
verify(consoleWriterMock, times(1)).a("some");
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_CHECKS=true");
verify(ghIssueCommentMock, times(1)).createReaction(ReactionContent.PLUS_ONE);
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_PUSH=false");
}

@Test
public void testExecuteWithPushSkipped() {
when(githubMock.isLabelAppliedToPR("testRepo", 1, "skip-i18n-push")).thenReturn(true);
githubPRInfoCommand.execute();
verify(consoleWriterMock, times(1)).a("MOJITO_GITHUB_BASE_COMMIT=");
verify(consoleWriterMock, times(1)).a("baseSha");
verify(consoleWriterMock, times(1)).a("MOJITO_GITHUB_AUTHOR_EMAIL=");
verify(consoleWriterMock, times(1)).a("[email protected]");
verify(consoleWriterMock, times(1)).a("MOJITO_GITHUB_AUTHOR_USERNAME=");
verify(consoleWriterMock, times(1)).a("some");
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_CHECKS=false");
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_PUSH=true");
verify(githubMock, times(1))
.addCommentToPR(
"testRepo",
1,
":warning: I18N strings will not be pushed to Mojito as 'skip-i18n-push' label is applied to this PR.");
}

@Test
public void testExecuteWithPushSkippedOnlyCommentsOnce() {
when(githubMock.isLabelAppliedToPR("testRepo", 1, "skip-i18n-push")).thenReturn(true);
when(ghIssueCommentMock.getBody())
.thenReturn(
":warning: I18N strings will not be pushed to Mojito as 'skip-i18n-push' label is applied to this PR.");
githubPRInfoCommand.execute();
verify(consoleWriterMock, times(1)).a("MOJITO_GITHUB_BASE_COMMIT=");
verify(consoleWriterMock, times(1)).a("baseSha");
verify(consoleWriterMock, times(1)).a("MOJITO_GITHUB_AUTHOR_EMAIL=");
verify(consoleWriterMock, times(1)).a("[email protected]");
verify(consoleWriterMock, times(1)).a("MOJITO_GITHUB_AUTHOR_USERNAME=");
verify(consoleWriterMock, times(1)).a("some");
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_CHECKS=false");
verify(consoleWriterMock, times(1)).a("MOJITO_SKIP_I18N_PUSH=true");
verify(githubMock, times(0))
.addCommentToPR(
"testRepo",
1,
":warning: I18N strings will not be pushed to Mojito as 'skip-i18n-push' label is applied to this PR.");
}

@Test(expected = CommandException.class)
Expand Down
Loading