Skip to content

Commit

Permalink
Merge branch 'no-events-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
kovetskiy committed Nov 11, 2019
2 parents 0857bc1 + cd83294 commit 34d3ec2
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 47 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ngs.stash.externalhooks</groupId>
<artifactId>external-hooks</artifactId>
<version>7.5.0</version>
<version>8.0.0</version>
<organization>
<name>reconquest</name>
</organization>
Expand Down Expand Up @@ -149,7 +149,7 @@
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bitbucket.version>6.6.1</bitbucket.version>
<bitbucket.version>6.8.0</bitbucket.version>
<bitbucket.data.version>${bitbucket.version}</bitbucket.data.version>
<atlassian-sal-api.version>3.0.5</atlassian-sal-api.version>
<amps.version>8.0.1</amps.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ExternalAsyncPostReceiveHook

private ExternalHookScript externalHookScript;
private RepositoryHookService repositoryHookService;
public static final String KEY_ID = "external-post-receive-hook";

public ExternalAsyncPostReceiveHook(
AuthenticationContext authenticationContext,
Expand All @@ -51,6 +52,27 @@ public ExternalAsyncPostReceiveHook(
throws IOException {
this.repositoryHookService = repositoryHookService;

this.externalHookScript = getExternalHookScript(
authenticationContext,
permissions,
pluginLicenseManager,
clusterService,
storageProperties,
hookScriptService,
pluginSettingsFactory,
securityService);
}

public static ExternalHookScript getExternalHookScript(
AuthenticationContext authenticationContext,
PermissionService permissions,
PluginLicenseManager pluginLicenseManager,
ClusterService clusterService,
StorageService storageProperties,
HookScriptService hookScriptService,
PluginSettingsFactory pluginSettingsFactory,
SecurityService securityService)
throws IOException {
List<RepositoryHookTrigger> triggers = new ArrayList<RepositoryHookTrigger>();
triggers.add(StandardRepositoryHookTrigger.REPO_PUSH);
triggers.add(StandardRepositoryHookTrigger.FILE_EDIT);
Expand All @@ -60,7 +82,7 @@ public ExternalAsyncPostReceiveHook(
triggers.add(StandardRepositoryHookTrigger.BRANCH_CREATE);
triggers.add(StandardRepositoryHookTrigger.PULL_REQUEST_MERGE);

this.externalHookScript = new ExternalHookScript(
return new ExternalHookScript(
authenticationContext,
permissions,
pluginLicenseManager,
Expand All @@ -69,7 +91,7 @@ public ExternalAsyncPostReceiveHook(
hookScriptService,
pluginSettingsFactory,
securityService,
"external-post-receive-hook",
KEY_ID,
HookScriptType.POST,
triggers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@

public class ExternalHookScript {
public static final String PLUGIN_KEY = "com.ngs.stash.externalhooks.external-hooks";

private final PluginLicenseManager pluginLicenseManager;
private static Logger log = LoggerFactory.getLogger(ExternalHookScript.class.getSimpleName());
public final Escaper SHELL_ESCAPE;
private AuthenticationContext authCtx;
private PermissionService permissions;
private PermissionService permissionService;
private ClusterService clusterService;
private StorageService storageProperties;
private HookScriptService hookScriptService;
Expand All @@ -59,7 +60,7 @@ public class ExternalHookScript {

public ExternalHookScript(
AuthenticationContext authenticationContext,
PermissionService permissions,
PermissionService permissionService,
PluginLicenseManager pluginLicenseManager,
ClusterService clusterService,
StorageService storageProperties,
Expand All @@ -71,7 +72,7 @@ public ExternalHookScript(
List<RepositoryHookTrigger> repositoryHookTriggers)
throws IOException {
this.authCtx = authenticationContext;
this.permissions = permissions;
this.permissionService = permissionService;
this.storageProperties = storageProperties;
this.pluginLicenseManager = pluginLicenseManager;
this.clusterService = clusterService;
Expand All @@ -90,6 +91,10 @@ public ExternalHookScript(
this.hookScriptTemplate = this.getResource("hook-script.template.bash");
}

public String getHookKey() {
return this.hookId;
}

private String getResource(String name) throws IOException {
InputStream resource = ClassLoaderUtils.getResourceAsStream(name, this.getClass());
if (resource == null) {
Expand Down Expand Up @@ -128,7 +133,7 @@ public void validate(
}

if (!settings.getBoolean("safe_path", false)) {
if (!permissions.hasGlobalPermission(Permission.SYS_ADMIN)) {
if (!permissionService.hasGlobalPermission(Permission.SYS_ADMIN)) {
errors.addFieldError(
"exe", "You should be a Bitbucket System Administrator to edit this field "
+ "without \"safe mode\" option.");
Expand Down Expand Up @@ -244,7 +249,7 @@ public void install(@Nonnull Settings settings, @Nonnull Scope scope) {
HookScriptSetConfigurationRequest hookScriptSetConfigurationRequest = configBuilder.build();
hookScriptService.setConfiguration(hookScriptSetConfigurationRequest);

log.info("Successfully created HookScript with id: {}", hookScript.getId());
log.warn("Created HookScript with id: {}", hookScript.getId());
}

public File getExecutable(String path, boolean safeDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class ExternalMergeCheckHook implements RepositoryMergeCheck, SettingsValidator {
private ExternalHookScript externalHookScript;
private RepositoryHookService repositoryHookService;
public static final String KEY_ID = "external-merge-check-hook";

public ExternalMergeCheckHook(
AuthenticationContext authenticationContext,
Expand All @@ -49,11 +50,33 @@ public ExternalMergeCheckHook(
SecurityService securityService)
throws IOException {

this.repositoryHookService = repositoryHookService;

this.externalHookScript = getExternalHookScript(
authenticationContext,
permissions,
pluginLicenseManager,
clusterService,
storageProperties,
hookScriptService,
pluginSettingsFactory,
securityService);
}

public static ExternalHookScript getExternalHookScript(
AuthenticationContext authenticationContext,
PermissionService permissions,
PluginLicenseManager pluginLicenseManager,
ClusterService clusterService,
StorageService storageProperties,
HookScriptService hookScriptService,
PluginSettingsFactory pluginSettingsFactory,
SecurityService securityService)
throws IOException {
List<RepositoryHookTrigger> triggers = new ArrayList<RepositoryHookTrigger>();
triggers.add(StandardRepositoryHookTrigger.PULL_REQUEST_MERGE);

this.repositoryHookService = repositoryHookService;
this.externalHookScript = new ExternalHookScript(
return new ExternalHookScript(
authenticationContext,
permissions,
pluginLicenseManager,
Expand All @@ -62,7 +85,7 @@ public ExternalMergeCheckHook(
hookScriptService,
pluginSettingsFactory,
securityService,
"external-merge-check-hook",
KEY_ID,
HookScriptType.PRE,
triggers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ExternalPreReceiveHook
implements PreRepositoryHook<RepositoryHookRequest>, SettingsValidator {

private ExternalHookScript externalHookScript;
public static final String KEY_ID = "external-pre-receive-hook";

private RepositoryHookService repositoryHookService;

Expand All @@ -51,16 +52,36 @@ public ExternalPreReceiveHook(
RepositoryHookService repositoryHookService,
SecurityService securityService)
throws IOException {
this.repositoryHookService = repositoryHookService;
this.externalHookScript = getExternalHookScript(
authenticationContext,
permissions,
pluginLicenseManager,
clusterService,
storageProperties,
hookScriptService,
pluginSettingsFactory,
securityService);
}

public static ExternalHookScript getExternalHookScript(
AuthenticationContext authenticationContext,
PermissionService permissions,
PluginLicenseManager pluginLicenseManager,
ClusterService clusterService,
StorageService storageProperties,
HookScriptService hookScriptService,
PluginSettingsFactory pluginSettingsFactory,
SecurityService securityService)
throws IOException {
List<RepositoryHookTrigger> triggers = new ArrayList<RepositoryHookTrigger>();
triggers.add(StandardRepositoryHookTrigger.REPO_PUSH);
triggers.add(StandardRepositoryHookTrigger.FILE_EDIT);
triggers.add(StandardRepositoryHookTrigger.TAG_DELETE);
triggers.add(StandardRepositoryHookTrigger.TAG_CREATE);
triggers.add(StandardRepositoryHookTrigger.BRANCH_DELETE);
triggers.add(StandardRepositoryHookTrigger.BRANCH_CREATE);

this.repositoryHookService = repositoryHookService;
this.externalHookScript = new ExternalHookScript(
return new ExternalHookScript(
authenticationContext,
permissions,
pluginLicenseManager,
Expand All @@ -69,7 +90,7 @@ public ExternalPreReceiveHook(
hookScriptService,
pluginSettingsFactory,
securityService,
"external-pre-receive-hook",
KEY_ID,
HookScriptType.PRE,
triggers);
}
Expand Down
Loading

0 comments on commit 34d3ec2

Please sign in to comment.