Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
Avoiding NPE when user not authenticated #75
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Aug 7, 2017
1 parent 975020f commit f52c2a5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Changelog of Simple Bitbucket Commit Checker.

## Unreleased
### No issue
doc

[975020fd5483f13](https://github.com/tomasbjerre/simple-bitbucket-commit-checker/commit/975020fd5483f13) Tomas Bjerre *2017-08-03 17:27:46*

## 3.7
### No issue
move CSS and JS into /static so they get loaded automatically when the form is displayed
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/se/bjurr/sbcc/SbccRepositoryMergeCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import static com.atlassian.bitbucket.hook.repository.RepositoryHookResult.accepted;
import static com.atlassian.bitbucket.repository.RefChangeType.ADD;
import static java.util.logging.Level.SEVERE;
import static se.bjurr.sbcc.settings.SbccSettings.sscSettings;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import se.bjurr.sbcc.commits.ChangeSetsService;
import se.bjurr.sbcc.settings.SbccSettings;
import se.bjurr.sbcc.settings.ValidationException;

import com.atlassian.applinks.api.ApplicationLinkService;
Expand Down Expand Up @@ -55,27 +55,29 @@ public SbccRepositoryMergeCheck(
@Override
public RepositoryHookResult preUpdate(
PreRepositoryHookContext context, PullRequestMergeHookRequest request) {
PullRequest pullRequest = request.getPullRequest();
ScmHookDetails scmHookDetails = request.getScmHookDetails().orElse(null);
Repository repositoryWithCommits = request.getFromRef().getRepository();
Repository repositoryWithSettings = request.getToRef().getRepository();
Optional<Settings> settings = repositoryHook.findSettings(repositoryWithSettings);
final PullRequest pullRequest = request.getPullRequest();
final ScmHookDetails scmHookDetails = request.getScmHookDetails().orElse(null);
final Repository repositoryWithCommits = request.getFromRef().getRepository();
final Repository repositoryWithSettings = request.getToRef().getRepository();
final Optional<Settings> settings = repositoryHook.findSettings(repositoryWithSettings);

if (!settings.isPresent()) {
return accepted();
}

try {
boolean shouldCheckPr = SbccSettings.sscSettings(settings.get()).shouldCheckPullRequests();
final boolean shouldCheckPr =
sscSettings(settings.get()) //
.shouldCheckPullRequests();
if (!shouldCheckPr) {
return accepted();
}
} catch (ValidationException e) {
} catch (final ValidationException e) {
logger.log(SEVERE, "Could not read settings", e);
return accepted();
}
List<RefChange> refChanges = new ArrayList<>();
RefChange refChange =
final List<RefChange> refChanges = new ArrayList<>();
final RefChange refChange =
new RefChange() {
@Override
public RefChangeType getType() {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/se/bjurr/sbcc/UserValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public boolean shouldIgnoreChecksForUser() {

private boolean shouldIgnoreByUserNamePattern() {
return settings.getIgnoreUsersPattern().isPresent()
&& matches(settings.getIgnoreUsersPattern().get(), currentUser.getName());
&& (currentUser == null
|| matches(settings.getIgnoreUsersPattern().get(), currentUser.getName()));
}

private boolean shouldIgnoreServiceUser() {
return settings.allowServiceUsers() && currentUser.getType().equals(SERVICE);
return settings.allowServiceUsers()
&& currentUser != null
&& currentUser.getType().equals(SERVICE);
}
}
4 changes: 2 additions & 2 deletions src/main/java/se/bjurr/sbcc/settings/SbccSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static SbccSettings sscSettings(Settings settings) throws ValidationExcep
if (!isNullOrEmpty(settings.getString(SETTING_SIZE))) {
sbccSettings.withCheckCommitSize(parseInt(settings.getString(SETTING_SIZE)));
}
} catch (Exception e) {
} catch (final Exception e) {
throw new ValidationException(SETTING_SIZE, "Not an integer!");
}
for (int g = 0; g < 1000; g++) {
Expand Down Expand Up @@ -228,7 +228,7 @@ private SbccSettings withRequireMatchingCommitterNameSlug(
}

private void withIgnoreUsersPattern(String string) {
this.ignoreUsersPattern = emptyToNull(string);
this.ignoreUsersPattern = emptyToNull(nullToEmpty(string).trim());
}

private SbccSettings withShouldCheckPullRequestsMessage(String string) {
Expand Down

0 comments on commit f52c2a5

Please sign in to comment.