Skip to content

Commit

Permalink
Platform refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
dukris committed Feb 14, 2024
1 parent 8518ac4 commit d3c00d3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 62 deletions.
11 changes: 4 additions & 7 deletions src/main/java/git/tracehub/pmo/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Map;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.cactoos.Scalar;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
Expand Down Expand Up @@ -115,12 +114,10 @@ public Project employ(
new ProjectFromReq(project)
);
final String provider = new IdProvider(jwt).value();
final Scalar<String> token = new IdpToken(jwt, provider, this.url);
final Scalar<String> location = new RepoPath(created.getLocation());
final Platform platform = this.platforms.get(provider);
platform.inviteCollaborator(token, location);
platform.createLabel(token, location);
platform.createWebhook(token, location);
this.platforms.get(provider).prepare(
new IdpToken(jwt, provider, this.url),
new RepoPath(created.getLocation())
);
return created;
}

Expand Down
20 changes: 2 additions & 18 deletions src/main/java/git/tracehub/pmo/platforms/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,11 @@
public interface Platform {

/**
* Create webhook.
* Prepare.
*
* @param token Token
* @param location Repository location
*/
void createWebhook(Scalar<String> token, Scalar<String> location);

/**
* Create label.
*
* @param token Token
* @param location Repository location
*/
void createLabel(Scalar<String> token, Scalar<String> location);

/**
* Invite collaborator.
*
* @param token Token
* @param location Repository location
*/
void inviteCollaborator(Scalar<String> token, Scalar<String> location);
void prepare(Scalar<String> token, Scalar<String> location);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,63 +27,44 @@
import lombok.SneakyThrows;
import org.cactoos.Scalar;
import org.cactoos.list.ListOf;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* Github platform.
*
* @checkstyle DesignForExtensionCheck (70 lines)
* @since 0.0.0
*/
@Component("github")
@RequiredArgsConstructor
public class GithubPlatform implements Platform {
public final class Github implements Platform {

/**
* Github host.
* Host.
*/
@Value("${platforms.github}")
private String host;
private final String host;

@Override
@SneakyThrows
public void createWebhook(
public void prepare(
final Scalar<String> token,
final Scalar<String> location
) {
new CreateWebhook(
this.host,
token.value(),
location.value(),
"http://it/webhook",
new ListOf<>("push", "issues")
final String tkn = token.value();
final String loc = location.value();
new InviteCollaborator(
new RtGithub(tkn).repos()
.get(new Coordinates.Simple(loc)),
"tracehubgit"
).exec();
}

@Override
@SneakyThrows
public void createLabel(
final Scalar<String> token,
final Scalar<String> location
) {
new CreateLabels(
new RtGithub(token.value()).repos()
.get(new Coordinates.Simple(location.value())),
new RtGithub(tkn).repos()
.get(new Coordinates.Simple(loc)),
new ListOf<>(new Label("new", Color.PINK))
).exec();
}

@Override
@SneakyThrows
public void inviteCollaborator(
final Scalar<String> token,
final Scalar<String> location
) {
new InviteCollaborator(
new RtGithub(token.value()).repos()
.get(new Coordinates.Simple(location.value())),
"tracehubgit"
new CreateWebhook(
this.host,
tkn,
loc,
"http://it/webhook",
new ListOf<>("push", "issues")
).exec();
}
}
23 changes: 23 additions & 0 deletions src/main/java/git/tracehub/pmo/security/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package git.tracehub.pmo.security;

import git.tracehub.pmo.platforms.Platform;
import git.tracehub.pmo.platforms.github.Github;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand All @@ -25,7 +27,10 @@
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import java.util.Map;
import lombok.SneakyThrows;
import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -58,6 +63,12 @@ public class WebConfig {
@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
private String url;

/**
* Github host.
*/
@Value("${platforms.github}")
private String github;

/**
* Filter.
*
Expand Down Expand Up @@ -140,4 +151,16 @@ name, new SecurityScheme()
);
}

/**
* Platforms.
*
* @return Map of implemented platforms
*/
@Bean
public Map<String, Platform> platforms() {
return new MapOf<>(
new MapEntry<>("github", new Github(this.github))
);
}

}

0 comments on commit d3c00d3

Please sign in to comment.