Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 14, 2016
1 parent 85a0f9f commit b9a273d
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 83 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
Changelog of Pull Request Notifier for Bitbucket.

## Unreleased
### No issue
Add comment text for replies

[8b13f16f92c8bbd](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/8b13f16f92c8bbd) Garret Ruh *2016-11-14 15:48:27*

## refs/tags/help
### GitHub [#148](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/148) Grunt identifies a missing semicolon in src/main/resources/utils.js
Adding semicolon at end of statement

[250ec4d56be6f3a](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/250ec4d56be6f3a) Tomas Bjerre *2016-09-28 05:38:11*

### No issue
doc

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/se/bjurr/prnfb/http/Invoker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package se.bjurr.prnfb.http;

public interface Invoker {
HttpResponse invoke(UrlInvoker urlInvoker);
HttpResponse invoke(UrlInvoker urlInvoker);
}
2 changes: 1 addition & 1 deletion src/main/java/se/bjurr/prnfb/http/UrlInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ HttpClientBuilder configureSsl(HttpClientBuilder builder) {
SSLConnectionSocketFactory sslConnSocketFactory = new SSLConnectionSocketFactory(s);
builder.setSSLSocketFactory(sslConnSocketFactory);

Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory> create()
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslConnSocketFactory).build();

HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public enum PrnfbPullRequestAction {
public static PrnfbPullRequestAction fromPullRequestEvent(PullRequestEvent event, PrnfbNotification notification) {
if (event instanceof PullRequestRescopedEvent) {
PullRequestRescopedEvent rescopedEvent = (PullRequestRescopedEvent) event;
boolean toChanged = !rescopedEvent.getPreviousToHash().equals(
rescopedEvent.getPullRequest().getToRef().getLatestCommit());
boolean fromChanged = !rescopedEvent.getPreviousFromHash().equals(
rescopedEvent.getPullRequest().getFromRef().getLatestCommit());
boolean toChanged = !rescopedEvent.getPreviousToHash()
.equals(rescopedEvent.getPullRequest().getToRef().getLatestCommit());
boolean fromChanged = !rescopedEvent.getPreviousFromHash()
.equals(rescopedEvent.getPullRequest().getFromRef().getLatestCommit());
if (fromChanged && !toChanged) {
return RESCOPED_FROM;
} else if (toChanged && !fromChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ public boolean isNotificationTriggeredByAction(PrnfbNotification notification,
}
}

if (notification.getFilterRegexp().isPresent()
&& notification.getFilterString().isPresent()
&& !compile(notification.getFilterRegexp().get()).matcher(
renderer.render(notification.getFilterString().get(), FALSE, clientKeyStore, shouldAcceptAnyCertificate)).find()) {
if (notification.getFilterRegexp().isPresent() && notification.getFilterString().isPresent()
&& !compile(notification.getFilterRegexp().get())
.matcher(renderer.render(notification.getFilterString().get(), FALSE, clientKeyStore, shouldAcceptAnyCertificate))
.find()) {
return FALSE;
}

Expand All @@ -119,8 +119,8 @@ public boolean isNotificationTriggeredByAction(PrnfbNotification notification,

if (notification.getTriggerIfCanMerge() != ALWAYS && pullRequest.isOpen()) {
// Cannot perform canMerge unless PR is open
boolean isConflicted = this.pullRequestService.canMerge(pullRequest.getToRef().getRepository().getId(),
pullRequest.getId()).isConflicted();
boolean isConflicted = this.pullRequestService
.canMerge(pullRequest.getToRef().getRepository().getId(), pullRequest.getId()).isConflicted();
if (ignoreBecauseOfConflicting(notification.getTriggerIfCanMerge(), isConflicted)) {
return FALSE;
}
Expand All @@ -138,8 +138,8 @@ public NotificationResponse notify(final PrnfbNotification notification, PrnfbPu

Optional<String> postContent = absent();
if (notification.getPostContent().isPresent()) {
postContent = of(renderer.render(notification.getPostContent().get(), FALSE, clientKeyStore,
shouldAcceptAnyCertificate));
postContent = of(
renderer.render(notification.getPostContent().get(), FALSE, clientKeyStore, shouldAcceptAnyCertificate));
}
String renderedUrl = renderer.render(notification.getUrl(), TRUE, clientKeyStore, shouldAcceptAnyCertificate);
LOG.info(notification.getName() + " > " //
Expand Down Expand Up @@ -255,8 +255,7 @@ boolean ignoreBecauseOfConflicting(TRIGGER_IF_MERGE triggerIfCanMerge, boolean i
Map<PrnfbVariable, Supplier<String>> populateVariables(final PullRequestEvent pullRequestEvent) {
Map<PrnfbVariable, Supplier<String>> variables = newHashMap();
if (pullRequestEvent instanceof PullRequestCommentEvent) {
variables.put(PULL_REQUEST_COMMENT_TEXT, () -> ((PullRequestCommentEvent) pullRequestEvent).getComment()
.getText());
variables.put(PULL_REQUEST_COMMENT_TEXT, () -> ((PullRequestCommentEvent) pullRequestEvent).getComment().getText());
} else if (pullRequestEvent instanceof PullRequestMergedEvent) {
variables.put(PULL_REQUEST_MERGE_COMMIT, new Supplier<String>() {
@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/se/bjurr/prnfb/presentation/ButtonServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class ButtonServlet {
private final SettingsService settingsService;
private final UserCheckService userCheckService;

public ButtonServlet(ButtonsService buttonsService, SettingsService settingsService, UserCheckService userCheckService) {
public ButtonServlet(ButtonsService buttonsService, SettingsService settingsService,
UserCheckService userCheckService) {
this.buttonsService = buttonsService;
this.settingsService = settingsService;
this.userCheckService = userCheckService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package se.bjurr.prnfb.presentation.dto;

public enum ON_OR_OFF {
on, off
on, off
}
6 changes: 4 additions & 2 deletions src/main/java/se/bjurr/prnfb/service/PrnfbRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class PrnfbRenderer {

PrnfbRenderer(PullRequest pullRequest, PrnfbPullRequestAction pullRequestAction, ApplicationUser applicationUser,
RepositoryService repositoryService, ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification, Map<PrnfbVariable, Supplier<String>> variables, SecurityService securityService) {
PrnfbNotification prnfbNotification, Map<PrnfbVariable, Supplier<String>> variables,
SecurityService securityService) {
this.pullRequest = pullRequest;
this.pullRequestAction = pullRequestAction;
this.applicationUser = applicationUser;
Expand All @@ -53,7 +54,8 @@ public class PrnfbRenderer {
this.securityService = securityService;
}

public String render(String string, Boolean forUrl, ClientKeyStore clientKeyStore, Boolean shouldAcceptAnyCertificate) {
public String render(String string, Boolean forUrl, ClientKeyStore clientKeyStore,
Boolean shouldAcceptAnyCertificate) {
string = renderVariable(string, false, clientKeyStore, shouldAcceptAnyCertificate, EVERYTHING_URL);

for (final PrnfbVariable variable : PrnfbVariable.values()) {
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
import java.util.Set;
import java.util.regex.Matcher;

import se.bjurr.prnfb.http.ClientKeyStore;
import se.bjurr.prnfb.http.HttpResponse;
import se.bjurr.prnfb.http.Invoker;
import se.bjurr.prnfb.http.UrlInvoker;
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
import se.bjurr.prnfb.settings.PrnfbNotification;

import com.atlassian.bitbucket.permission.Permission;
import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.pull.PullRequestParticipant;
Expand All @@ -40,6 +33,13 @@
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;

import se.bjurr.prnfb.http.ClientKeyStore;
import se.bjurr.prnfb.http.HttpResponse;
import se.bjurr.prnfb.http.Invoker;
import se.bjurr.prnfb.http.UrlInvoker;
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
import se.bjurr.prnfb.settings.PrnfbNotification;

public enum PrnfbVariable {

BUTTON_TRIGGER_TITLE(new PrnfbVariableResolver() {
Expand Down Expand Up @@ -505,11 +505,6 @@ public HttpResponse invoke(UrlInvoker urlInvoker) {
}
};

@VisibleForTesting
public static void setInvoker(Invoker invoker) {
PrnfbVariable.mockedInvoker = invoker;
}

private static String cloneUrlFromRepository(RepoProtocol protocol, Repository repository,
RepositoryService repositoryService, SecurityService securityService) {
return securityService//
Expand Down Expand Up @@ -564,18 +559,22 @@ private static String iterableToString(Iterable<String> slist) {
return on(',').join(sorted);
}

@VisibleForTesting
public static void setInvoker(Invoker invoker) {
PrnfbVariable.mockedInvoker = invoker;
}

private PrnfbVariableResolver resolver;

PrnfbVariable(PrnfbVariableResolver resolver) {
this.resolver = resolver;
}

public String resolve(PullRequest pullRequest, PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser, RepositoryService repositoryService,
ApplicationPropertiesService propertiesService, PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables, ClientKeyStore clientKeyStore, boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
return this.resolver.resolve(pullRequest, pullRequestAction, applicationUser, repositoryService, propertiesService,
ApplicationUser applicationUser, RepositoryService repositoryService, ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification, Map<PrnfbVariable, Supplier<String>> variables, ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate, SecurityService securityService) {
return resolver.resolve(pullRequest, pullRequestAction, applicationUser, repositoryService, propertiesService,
prnfbNotification, variables, clientKeyStore, shouldAcceptAnyCertificate, securityService);
}
}
2 changes: 1 addition & 1 deletion src/main/java/se/bjurr/prnfb/service/UserCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean apply(PrnfbButton input) {
}
});
return allowedButtons;
}
}

public boolean isAdmin(UserKey userKey, String projectKey, String repositorySlug) {
boolean isAdmin = this.userManager.isAdmin(userKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public PrnfbNotification(PrnfbNotificationBuilder builder) throws ValidationExce
this.headers = checkNotNull(builder.getHeaders());
this.postContent = emptyToNull(nullToEmpty(builder.getPostContent()).trim());
this.method = HTTP_METHOD.valueOf(firstNonNull(emptyToNull(nullToEmpty(builder.getMethod()).trim()), GET.name()));
this.triggerIfCanMerge = TRIGGER_IF_MERGE.valueOf(firstNonNull(
emptyToNull(nullToEmpty(builder.getTriggerIfCanMerge()).trim()), ALWAYS.name()));
this.triggerIfCanMerge = TRIGGER_IF_MERGE
.valueOf(firstNonNull(emptyToNull(nullToEmpty(builder.getTriggerIfCanMerge()).trim()), ALWAYS.name()));
if (nullToEmpty(builder.getUrl()).trim().isEmpty()) {
throw new ValidationException(FIELDS.url.name(), "URL not set!");
}
Expand All @@ -79,8 +79,8 @@ public PrnfbNotification(PrnfbNotificationBuilder builder) throws ValidationExce
try {
compile(builder.getFilterRegexp());
} catch (final Exception e) {
throw new ValidationException(filter_regexp.name(), "Filter regexp not valid! "
+ e.getMessage().replaceAll("\n", " "));
throw new ValidationException(filter_regexp.name(),
"Filter regexp not valid! " + e.getMessage().replaceAll("\n", " "));
}
if (nullToEmpty(builder.getFilterString()).trim().isEmpty()) {
throw new ValidationException(filter_string.name(), "Filter string not set, nothing to match regexp against!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ public static PrnfbNotification getPrnfbNotification(AdminFormValues adminFormVa
prnfbNotificationBuilder.withInjectionUrl(find(adminFormValues, predicate(injection_url.name())).get(VALUE));
}
if (tryFind(adminFormValues, predicate(injection_url_regexp.name())).isPresent()) {
prnfbNotificationBuilder.withInjectionUrlRegexp(find(adminFormValues, predicate(injection_url_regexp.name())).get(
VALUE));
prnfbNotificationBuilder
.withInjectionUrlRegexp(find(adminFormValues, predicate(injection_url_regexp.name())).get(VALUE));
}
if (tryFind(adminFormValues, predicate(trigger_if_isconflicting.name())).isPresent()) {
prnfbNotificationBuilder.withTriggerIfCanMerge(find(adminFormValues, predicate(trigger_if_isconflicting.name()))
.get(VALUE));
prnfbNotificationBuilder
.withTriggerIfCanMerge(find(adminFormValues, predicate(trigger_if_isconflicting.name())).get(VALUE));
}
for (final Map<String, String> event : filter(adminFormValues, predicate(trigger_ignore_state.name()))) {
prnfbNotificationBuilder.withTriggerIgnoreState(PullRequestState.valueOf(event.get(VALUE)));
Expand Down Expand Up @@ -221,8 +221,8 @@ public static PrnfbSettings getPrnfbSettings(PluginSettings pluginSettings) thro
prnfbSettingsBuilder.setKeyStoreType(tryFind(adminFormValues, predicate(key_store_type.name())).get().get(VALUE));
}
if (tryFind(adminFormValues, predicate(key_store_password.name())).isPresent()) {
prnfbSettingsBuilder.setKeyStorePassword(tryFind(adminFormValues, predicate(key_store_password.name())).get().get(
VALUE));
prnfbSettingsBuilder
.setKeyStorePassword(tryFind(adminFormValues, predicate(key_store_password.name())).get().get(VALUE));
}
}
return prnfbSettingsBuilder.build();
Expand Down Expand Up @@ -295,7 +295,7 @@ private static AdminFormValues injectConfigurationName(AdminFormValues adminForm
if (nameMapOpt.isPresent()) {
return adminFormValues;
}
adminFormValues.add(ImmutableMap.<String, String> builder()//
adminFormValues.add(ImmutableMap.<String, String>builder()//
.put(NAME, name.name())//
.put(VALUE, DEFAULT_NAME)//
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public static PrnfbButton toPrnfbButton(ButtonDTO buttonDto) {
return new PrnfbButton(//
buttonDto.getUUID(), //
buttonDto.getName(), //
buttonDto.getUserLevel(),//
buttonDto.getConfirmation(),//
buttonDto.getProjectKey().orNull(),//
buttonDto.getUserLevel(), //
buttonDto.getConfirmation(), //
buttonDto.getProjectKey().orNull(), //
buttonDto.getRepositorySlug().orNull());//
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/se/bjurr/prnfb/http/UrlInvokerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ HttpResponse doInvoke(HttpRequestBase httpRequest, HttpClientBuilder builder) {
}
}
}//
.withUrlParam("http://url.com/");
.withUrlParam("http://url.com/");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class PrnfbPullRequestEventListenerTest {
@Before
public void before() throws ValidationException {
initMocks(this);
this.sut = new PrnfbPullRequestEventListener(this.prnfbRendererFactory, this.pullRequestService,
this.executorService, this.settingsService);
this.sut = new PrnfbPullRequestEventListener(this.prnfbRendererFactory, this.pullRequestService, this.executorService,
this.settingsService);
setInvoker(new Invoker() {
@Override
public HttpResponse invoke(UrlInvoker urlInvoker) {
Expand Down
11 changes: 5 additions & 6 deletions src/test/java/se/bjurr/prnfb/presentation/ButtonServletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ public void testThatButtonCanBeListedPerProject() throws Exception {

@Test
public void testThatButtonCanBeListedPerProjectAndRepo() throws Exception {
when(
this.settingsService.getButtons(this.buttonDto1.getProjectKey().orNull(), this.buttonDto1.getRepositorySlug()
.orNull()))//
.thenReturn(newArrayList(this.button1));
when(this.settingsService.getButtons(this.buttonDto1.getProjectKey().orNull(),
this.buttonDto1.getRepositorySlug().orNull()))//
.thenReturn(newArrayList(this.button1));
allowAll();

Response actual = this.sut
.get(this.buttonDto1.getProjectKey().orNull(), this.buttonDto1.getRepositorySlug().orNull());
Response actual = this.sut.get(this.buttonDto1.getProjectKey().orNull(),
this.buttonDto1.getRepositorySlug().orNull());
@SuppressWarnings("unchecked")
Iterable<ButtonDTO> actualList = (Iterable<ButtonDTO>) actual.getEntity();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ public void testThatNotificationCanBeListedPerProject() throws Exception {

@Test
public void testThatNotificationCanBeListedPerProjectAndRepo() throws Exception {
when(
this.settingsService.getNotifications(this.notificationDto1.getProjectKey(),
this.notificationDto1.getRepositorySlug()))//
.thenReturn(newArrayList(this.notification1));
when(this.settingsService.getNotifications(this.notificationDto1.getProjectKey(),
this.notificationDto1.getRepositorySlug()))//
.thenReturn(newArrayList(this.notification1));

Response actual = this.sut.get(this.notificationDto1.getProjectKey(), this.notificationDto1.getRepositorySlug());
@SuppressWarnings("unchecked")
Expand Down
21 changes: 9 additions & 12 deletions src/test/java/se/bjurr/prnfb/service/ButtonsServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ public void before() throws ValidationException {
initMocks(this);
this.sut = new ButtonsService(this.pullRequestService, this.prnfbPullRequestEventListener, this.prnfbRendererFactory,
this.settingsService, this.userCheckService);
when(
this.prnfbRendererFactory.create(any(PullRequest.class), any(PrnfbPullRequestAction.class),
any(PrnfbNotification.class), anyMap()))//
.thenReturn(this.renderer);
when(this.prnfbRendererFactory.create(any(PullRequest.class), any(PrnfbPullRequestAction.class),
any(PrnfbNotification.class), anyMap()))//
.thenReturn(this.renderer);

this.buttonDto1 = populatedInstanceOf(ButtonDTO.class);
this.buttonDto1.setProjectKey(null);
Expand Down Expand Up @@ -151,14 +150,12 @@ public void testThatButtonsCanBeRetrievedWhenAllAllowed() {
.thenReturn(true);
when(this.userCheckService.isAllowedUseButton(this.button3))//
.thenReturn(true);
when(
this.prnfbPullRequestEventListener.isNotificationTriggeredByAction(this.notification1, this.pullRequestAction,
this.renderer, this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate))//
.thenReturn(true);
when(
this.prnfbPullRequestEventListener.isNotificationTriggeredByAction(this.notification2, this.pullRequestAction,
this.renderer, this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate))//
.thenReturn(true);
when(this.prnfbPullRequestEventListener.isNotificationTriggeredByAction(this.notification1, this.pullRequestAction,
this.renderer, this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate))//
.thenReturn(true);
when(this.prnfbPullRequestEventListener.isNotificationTriggeredByAction(this.notification2, this.pullRequestAction,
this.renderer, this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate))//
.thenReturn(true);
when(this.pullRequest.getToRef()).thenReturn(this.prRef);
when(this.prRef.getRepository()).thenReturn(this.repository);
when(this.repository.getSlug()).thenReturn(this.button3.getRepositorySlug().get());
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/se/bjurr/prnfb/service/PrnfbRendererTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ public HttpResponse invoke(UrlInvoker toInvoke) {

@Test
public void testThatEverythingCanBeRendered() throws UnsupportedEncodingException {
String actual = this.sut.getRenderedStringResolved("asd ${" + EVERYTHING_URL.name() + "} asd", this.forUrl, this.sut
.regexp(EVERYTHING_URL), EVERYTHING_URL.resolve(this.pullRequest, this.pullRequestAction, this.applicationUser,
this.repositoryService, this.propertiesService, this.prnfbNotification, this.variables, this.clientKeyStore,
this.shouldAcceptAnyCertificate, this.securityService));
String actual = this.sut.getRenderedStringResolved("asd ${" + EVERYTHING_URL.name() + "} asd", this.forUrl,
this.sut.regexp(EVERYTHING_URL),
EVERYTHING_URL.resolve(this.pullRequest, this.pullRequestAction, this.applicationUser, this.repositoryService,
this.propertiesService, this.prnfbNotification, this.variables, this.clientKeyStore,
this.shouldAcceptAnyCertificate, this.securityService));

assertThat(actual)//
.isEqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void before() throws InterruptedException {
.auth().preemptive().basic("admin", "admin")//
.accept(JSON)//
.contentType(JSON);
RestAssured.config().logConfig(
logConfig().enableLoggingOfRequestAndResponseIfValidationFails().enablePrettyPrinting(true));
RestAssured.config()
.logConfig(logConfig().enableLoggingOfRequestAndResponseIfValidationFails().enablePrettyPrinting(true));
RestAssured.responseSpecification = new ResponseSpecBuilder()//
.build();

Expand Down

0 comments on commit b9a273d

Please sign in to comment.