-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
…-test-data
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.tum.in.www1.artemis.config.localvcci; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.jgit.http.server.GitServlet; | ||
import org.eclipse.jgit.transport.ReceivePack; | ||
|
||
import de.tum.in.www1.artemis.service.connectors.localci.LocalCIConnectorService; | ||
import de.tum.in.www1.artemis.service.connectors.localvc.LocalVCFetchFilter; | ||
import de.tum.in.www1.artemis.service.connectors.localvc.LocalVCPostPushHook; | ||
import de.tum.in.www1.artemis.service.connectors.localvc.LocalVCPrePushHook; | ||
import de.tum.in.www1.artemis.service.connectors.localvc.LocalVCPushFilter; | ||
import de.tum.in.www1.artemis.service.connectors.localvc.LocalVCServletService; | ||
|
||
/** | ||
* This class configures the JGit Servlet, which is used to receive Git push and fetch requests for local VC. | ||
*/ | ||
public class ArtemisGitServlet extends GitServlet { | ||
|
||
/** | ||
* Constructor for ArtemisGitServlet. | ||
* | ||
* @param localVCServletService the service for authenticating and authorizing users and retrieving the repository from disk | ||
* @param localCIConnectorService the service for triggering a new build after a successful push | ||
*/ | ||
public ArtemisGitServlet(LocalVCServletService localVCServletService, Optional<LocalCIConnectorService> localCIConnectorService) { | ||
this.setRepositoryResolver((req, name) -> { | ||
// req – the current request, may be used to inspect session state including cookies or user authentication. | ||
// name – name of the repository, as parsed out of the URL (everything after /git/). | ||
|
||
// Return the opened repository instance. | ||
return localVCServletService.resolveRepository(name); | ||
}); | ||
|
||
// Add filters that every request to the JGit Servlet goes through, one for each fetch request, and one for each push request. | ||
this.addUploadPackFilter(new LocalVCFetchFilter(localVCServletService)); | ||
this.addReceivePackFilter(new LocalVCPushFilter(localVCServletService)); | ||
|
||
this.setReceivePackFactory((req, db) -> { | ||
ReceivePack receivePack = new ReceivePack(db); | ||
// Add a hook that prevents illegal actions on push (delete branch, rename branch, force push). | ||
receivePack.setPreReceiveHook(new LocalVCPrePushHook()); | ||
// Add a hook that triggers the creation of a new submission after the push went through successfully. | ||
receivePack.setPostReceiveHook(new LocalVCPostPushHook(localCIConnectorService)); | ||
return receivePack; | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package de.tum.in.www1.artemis.config.localvcci; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.jgit.http.server.GitServlet; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
import de.tum.in.www1.artemis.service.connectors.localci.LocalCIConnectorService; | ||
import de.tum.in.www1.artemis.service.connectors.localvc.LocalVCServletService; | ||
|
||
/** | ||
* Configuration of the JGit Servlet that handles fetch and push requests for local Version Control. | ||
*/ | ||
@Configuration | ||
@Profile("localvc") | ||
public class JGitServletConfiguration { | ||
|
||
private final Logger log = LoggerFactory.getLogger(JGitServletConfiguration.class); | ||
|
||
private final LocalVCServletService localVCServletService; | ||
|
||
private final Optional<LocalCIConnectorService> localCIConnectorService; | ||
|
||
public JGitServletConfiguration(LocalVCServletService localVCServletService, Optional<LocalCIConnectorService> localCIConnectorService) { | ||
this.localVCServletService = localVCServletService; | ||
this.localCIConnectorService = localCIConnectorService; | ||
} | ||
|
||
/** | ||
* @return GitServlet (Git server implementation by JGit) configured with a repository resolver and filters for fetch and push requests. | ||
*/ | ||
@Bean | ||
public ServletRegistrationBean<GitServlet> jgitServlet() { | ||
ArtemisGitServlet gitServlet = new ArtemisGitServlet(localVCServletService, localCIConnectorService); | ||
log.info("Registering ArtemisGitServlet for handling fetch and push requests to [Artemis URL]/git/[Project Key]/[Repository Slug].git"); | ||
return new ServletRegistrationBean<>(gitServlet, "/git/*"); | ||
} | ||
} |