Search in sources :

Example 1 with Repository

use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.

the class GitServiceIntTest method testGetOrCheckoutRepositoryForExistingRepo.

@Test
public void testGetOrCheckoutRepositoryForExistingRepo() throws IOException, GitAPIException {
    Participation participation = new Participation();
    participation.setRepositoryUrl(remoteTestRepo);
    Repository repo = gitService.getOrCheckoutRepository(participation);
    Repository repo2 = gitService.getOrCheckoutRepository(participation);
    assertThat(repo.getDirectory()).isEqualTo(repo2.getDirectory());
    assertThat(repo2.getBranch()).isEqualTo("master");
    assertThat(repo2.getDirectory()).exists();
    gitService.deleteLocalRepository(repo2);
}
Also used : Participation(de.tum.in.www1.artemis.domain.Participation) Repository(de.tum.in.www1.artemis.domain.Repository) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Repository

use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.

the class GitServiceIntTest method testDeleteLocalRepository.

@Test
public void testDeleteLocalRepository() throws IOException, GitAPIException {
    Participation participation = new Participation();
    participation.setRepositoryUrl(remoteTestRepo);
    Repository repo = gitService.getOrCheckoutRepository(participation);
    assertThat(repo.getDirectory()).exists();
    gitService.deleteLocalRepository(repo);
    assertThat(repo.getDirectory()).doesNotExist();
}
Also used : Participation(de.tum.in.www1.artemis.domain.Participation) Repository(de.tum.in.www1.artemis.domain.Repository) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Repository

use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.

the class GitServiceIntTest method testListFiles.

@Test
public void testListFiles() throws IOException, GitAPIException {
    Participation participation = new Participation();
    participation.setRepositoryUrl(remoteTestRepo);
    Repository repo = gitService.getOrCheckoutRepository(participation);
    Collection<de.tum.in.www1.artemis.domain.File> files = gitService.listFiles(repo);
    assertThat(files.size()).isGreaterThan(0);
    gitService.deleteLocalRepository(repo);
}
Also used : Participation(de.tum.in.www1.artemis.domain.Participation) Repository(de.tum.in.www1.artemis.domain.Repository) File(java.io.File) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Repository

use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.

the class BambooService method updatePlanRepository.

/**
 * Updates the configured repository for a given plan to the given Bitbucket Server repository.
 *
 * @param bambooProject        The key of the Bamboo plan's project, e.g. 'EIST16W1'.
 * @param bambooPlan           The plan key, which is usually the name, e.g. 'ga56hur'.
 * @param bambooRepositoryName The name of the configured repository in the Bamboo plan.
 * @param bitbucketProject     The key for the Bitbucket Server (formerly Stash) project to which we want to update the plan.
 * @param bitbucketRepository  The name/slug for the Bitbucket Server (formerly Stash) repository to which we want to update the plan.
 */
public String updatePlanRepository(String bambooProject, String bambooPlan, String bambooRepositoryName, String bitbucketProject, String bitbucketRepository) throws BambooException {
    final BambooClient bambooClient = new BambooClient();
    String[] args = new String[] { "--field1", "repository.stash.projectKey", "--value1", bitbucketProject, // Doesn't seem to be required
    "--field2", // Doesn't seem to be required
    "repository.stash.repositoryId", // Doesn't seem to be required
    "--value2", // Doesn't seem to be required
    "2499", "--field3", "repository.stash.repositorySlug", "--value3", bitbucketRepository, // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
    "--field4", // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
    "repository.stash.repositoryUrl", // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
    "--value4", // e.g. "ssh://git@repobruegge.in.tum.de:7999/madm/helloworld.git"
    buildSshRepositoryUrl(bitbucketProject, bitbucketRepository), "--field5", "repository.stash.server", "--value5", BITBUCKET_APPLICATION_LINK_ID, "--field6", "repository.stash.branch", "--value6", "master", "-s", BAMBOO_SERVER_URL.toString(), "--user", BAMBOO_USER, "--password", BAMBOO_PASSWORD };
    // workaround to pass additional fields
    bambooClient.doWork(args);
    try {
        log.info("Update plan repository for build plan " + bambooProject + "-" + bambooPlan);
        String message = bambooClient.getRepositoryHelper().addOrUpdateRepository(bambooRepositoryName, null, null, bambooProject + "-" + bambooPlan, "STASH", null, false, true, true);
        log.info("Update plan repository for build plan " + bambooProject + "-" + bambooPlan + " was successful." + message);
        return message;
    } catch (CliClient.ClientException | CliClient.RemoteRestException e) {
        log.error(e.getMessage(), e);
        throw new BambooException("Something went wrong while updating the plan repository", e);
    }
}
Also used : BambooException(de.tum.in.www1.artemis.exception.BambooException) BambooClient(org.swift.bamboo.cli.BambooClient)

Example 5 with Repository

use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.

the class BitbucketService method giveWritePermission.

/**
 * Gives user write permissions for a repository.
 *
 * @param projectKey     The project key of the repository's project.
 * @param repositorySlug The repository's slug.
 * @param username       The user whom to give write permissions.
 */
private void giveWritePermission(String projectKey, String repositorySlug, String username) throws BitbucketException {
    // NAME&PERMISSION
    String baseUrl = BITBUCKET_SERVER_URL + "/rest/api/1.0/projects/" + projectKey + "/repos/" + repositorySlug + "/permissions/users?name=";
    HttpHeaders headers = HeaderUtil.createAuthorization(BITBUCKET_USER, BITBUCKET_PASSWORD);
    HttpEntity<?> entity = new HttpEntity<>(headers);
    RestTemplate restTemplate = new RestTemplate();
    try {
        restTemplate.exchange(baseUrl + username + "&permission=REPO_WRITE", HttpMethod.PUT, entity, Map.class);
    } catch (Exception e) {
        log.error("Could not give write permission", e);
        throw new BitbucketException("Error while giving repository permissions");
    }
}
Also used : BitbucketException(de.tum.in.www1.artemis.exception.BitbucketException) RestTemplate(org.springframework.web.client.RestTemplate) MalformedURLException(java.net.MalformedURLException) BitbucketException(de.tum.in.www1.artemis.exception.BitbucketException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Aggregations

Repository (de.tum.in.www1.artemis.domain.Repository)9 Participation (de.tum.in.www1.artemis.domain.Participation)7 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Path (java.nio.file.Path)5 BitbucketException (de.tum.in.www1.artemis.exception.BitbucketException)4 IOException (java.io.IOException)4 MalformedURLException (java.net.MalformedURLException)4 Git (org.eclipse.jgit.api.Git)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)4 RestTemplate (org.springframework.web.client.RestTemplate)4 File (de.tum.in.www1.artemis.domain.File)3 BambooException (de.tum.in.www1.artemis.exception.BambooException)3 ExerciseRepository (de.tum.in.www1.artemis.repository.ExerciseRepository)3 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)3 Transactional (org.springframework.transaction.annotation.Transactional)3 File (java.io.File)2 URL (java.net.URL)2 Files (java.nio.file.Files)2