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);
}
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();
}
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);
}
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);
}
}
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");
}
}
Aggregations