Skip to content

Commit

Permalink
Fix for test template preview and execute
Browse files Browse the repository at this point in the history
  • Loading branch information
netwolfuk committed Apr 3, 2024
1 parent 9588c12 commit eff1bba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import webhook.teamcity.payload.WebHookTemplateManager;
import webhook.teamcity.payload.WebHookTemplateManager.TemplateState;
import webhook.teamcity.settings.config.WebHookTemplateConfig;
import webhook.teamcity.testing.WebHookUserRequestedExecutor;

@JerseyInjectable
@Component
Expand All @@ -26,12 +27,14 @@ public class TemplateDataProvider extends DataProvider {
@NotNull private final WebHookPayloadManager myPayloadManager;
@NotNull private final TemplateFinder myTemplateFinder;
@NotNull private final WebHookManager myWebHookManager;
@NotNull private final WebHookUserRequestedExecutor myWebHookUserRequestedExecutor;

public TemplateDataProvider(SBuildServer server,
RootUrlHolder rootUrlHolder,
PermissionChecker permissionChecker,
WebHookPayloadManager payloadManager,
WebHookTemplateManager templateManager,
WebHookTemplateManager templateManager,
WebHookUserRequestedExecutor userRequestedExecutor,
TemplateFinder templateFinder,
ProjectManager projectManager,
WebHookManager webHookManager,
Expand All @@ -41,10 +44,11 @@ public TemplateDataProvider(SBuildServer server,
super(server, rootUrlHolder, permissionChecker, projectManager,
projectIdResolver, securityContext);

this.myWebHookManager = webHookManager;
this.myTemplateManager = templateManager;
this.myPayloadManager = payloadManager;
this.myTemplateManager = templateManager;
this.myTemplateFinder = templateFinder;
this.myWebHookManager = webHookManager;
this.myWebHookUserRequestedExecutor = userRequestedExecutor;
}

public List<WebHookTemplateConfigWrapper> getWebHookTemplates(){
Expand Down Expand Up @@ -75,6 +79,10 @@ public WebHookTemplateManager getTemplateManager() {
return this.myTemplateManager;
}

public WebHookUserRequestedExecutor getWebHookUserRequestedExecutor() {
return myWebHookUserRequestedExecutor;
}

public TemplateFinder getTemplateFinder() {
return this.myTemplateFinder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package webhook.teamcity.server.rest.jersey;

import javax.ws.rs.ext.Provider;

import org.springframework.stereotype.Service;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import jetbrains.buildServer.server.rest.jersey.provider.annotated.JerseyInjectableBeanProvider;
import webhook.teamcity.testing.WebHookUserRequestedExecutor;

@Service
@SuppressWarnings("squid:S1191")
@Component
@Configuration
public class WebHookUserRequestedExecutorProvider implements JerseyInjectableBeanProvider {

private final WebHookUserRequestedExecutor myExecutor;

public WebHookUserRequestedExecutorProvider(WebHookUserRequestedExecutor executor) {
myExecutor = executor;
}

@Bean
public WebHookUserRequestedExecutor getBean() {
return this.myExecutor;
}

@Override
public Class<?> getBeanClass() {
return WebHookUserRequestedExecutor.class;
}

@Override
public Class<?> getBeanClass() {
return WebHookUserRequestedExecutor.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jetbrains.buildServer.serverSide.auth.Permission;
import webhook.teamcity.BuildStateEnum;
import webhook.teamcity.history.WebHookHistoryItem;
import webhook.teamcity.server.rest.data.TemplateDataProvider;
import webhook.teamcity.server.rest.errors.TemplatePermissionException;
import webhook.teamcity.server.rest.errors.UnprocessableEntityException;
import webhook.teamcity.server.rest.model.template.ErrorResult;
Expand All @@ -38,7 +39,7 @@ public class TemplateTestRequest {
public static final String API_TEMPLATE_TEST_URL = Constants.API_URL + "/test/template";
private static final Permission templateTestPermission = Permission.CHANGE_SERVER_SETTINGS;

@Context @NotNull private WebHookUserRequestedExecutor myWebHookUserRequestedExecutor;
@Context @NotNull private TemplateDataProvider myTemplateDataProvider;
@Context @NotNull private PermissionChecker myPermissionChecker;

@POST
Expand Down Expand Up @@ -69,7 +70,7 @@ public TemplateTestHistoryItem executeWebHookTemplateRequest(TemplateTestExecuti
.testBuildState(BuildStateEnum.findBuildState(executionRequest.getBuildStateName()))
.build();

WebHookHistoryItem webHookHistoryItem = myWebHookUserRequestedExecutor.requestWebHookExecution(templateExecutionRequest);
WebHookHistoryItem webHookHistoryItem = myTemplateDataProvider.getWebHookUserRequestedExecutor().requestWebHookExecution(templateExecutionRequest);

ErrorStatus error = null;
if (webHookHistoryItem.getWebhookErrorStatus() != null) {
Expand Down Expand Up @@ -115,7 +116,7 @@ public Response previewWebHookTemplateRequest(TemplateTestExecutionRequest execu
.url("")
.build();

WebHookRenderResult webHookRenderResult = myWebHookUserRequestedExecutor.requestWebHookPreview(templateExecutionRequest);
WebHookRenderResult webHookRenderResult = myTemplateDataProvider.getWebHookUserRequestedExecutor().requestWebHookPreview(templateExecutionRequest);

if (!webHookRenderResult.getErrored()) {
Response.ResponseBuilder rb = Response.ok(webHookRenderResult.getHtml());
Expand Down

0 comments on commit eff1bba

Please sign in to comment.