Search in sources :

Example 6 with RepoException

use of com.google.copybara.exception.RepoException in project copybara by google.

the class GerritApiTransportImpl method get.

@Override
public <T> T get(String path, Type responseType) throws RepoException, ValidationException {
    HttpRequestFactory requestFactory = getHttpRequestFactory(getCredentialsIfPresent(uri.toString()));
    GenericUrl url = getUrl(path);
    try {
        return execute(responseType, requestFactory.buildGetRequest(url));
    } catch (IOException e) {
        throw new RepoException("Error running Gerrit API operation " + url, e);
    }
}
Also used : HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) RepoException(com.google.copybara.exception.RepoException)

Example 7 with RepoException

use of com.google.copybara.exception.RepoException in project copybara by google.

the class GerritApiTransportImpl method post.

@Override
public <T> T post(String path, Object request, Type responseType) throws RepoException, ValidationException {
    HttpRequestFactory requestFactory = getHttpRequestFactory(getCredentials(uri.toString()));
    GenericUrl url = getUrl(path);
    try {
        return execute(responseType, requestFactory.buildPostRequest(url, new JsonHttpContent(JSON_FACTORY, request)));
    } catch (IOException e) {
        throw new RepoException("Error running Gerrit API operation " + url, e);
    }
}
Also used : HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) GenericUrl(com.google.api.client.http.GenericUrl) JsonHttpContent(com.google.api.client.http.json.JsonHttpContent) IOException(java.io.IOException) RepoException(com.google.copybara.exception.RepoException)

Example 8 with RepoException

use of com.google.copybara.exception.RepoException in project copybara by google.

the class GitRepoTypeTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("testRepo");
    fileRepoDir = Files.createTempDirectory("fileRepo");
    // We mock by default to avoid accidental network calls.
    testRepo = new GitRepository(repoGitDir, null, /*verbose=*/
    true, getGitEnv()) {

        @Override
        public GitRevision fetchSingleRef(String url, String ref) throws RepoException {
            interceptedFetches.add(new String[] { url, ref });
            return new GitRevision(this, Strings.repeat("0", 40));
        }
    };
    testRepo.init();
    prepareFileRepo();
    console = new TestingConsole();
    generalOptions = new OptionsBuilder().setConsole(console).build().get(GeneralOptions.class);
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GeneralOptions(com.google.copybara.GeneralOptions) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) Before(org.junit.Before)

Example 9 with RepoException

use of com.google.copybara.exception.RepoException in project copybara by google.

the class GithubPrDestinationTest method setup.

@Before
public void setup() throws Exception {
    repoGitDir = Files.createTempDirectory("GithubPrDestinationTest-repoGitDir");
    workdir = Files.createTempDirectory("workdir");
    localHub = Files.createTempDirectory("localHub");
    git("init", "--bare", repoGitDir.toString());
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    options.git = new TestGitOptions(localHub, () -> GithubPrDestinationTest.this.options.general);
    options.github = new GithubOptions(() -> options.general, options.git) {

        @Override
        public GithubApi getApi(String project) throws RepoException {
            assertThat(project).isEqualTo(expectedProject);
            return super.getApi(project);
        }

        @Override
        protected HttpTransport getHttpTransport() {
            return gitApiMockHttpTransport;
        }
    };
    Path credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
    options.git.credentialHelperStorePath = credentialsFile.toString();
    options.gitDestination = new GitDestinationOptions(() -> options.general, options.git);
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    skylark = new SkylarkTestExecutor(options, GitModule.class);
}
Also used : Path(java.nio.file.Path) TestGitOptions(com.google.copybara.testing.git.GitTestUtil.TestGitOptions) GithubApi(com.google.copybara.git.github.api.GithubApi) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Before(org.junit.Before)

Example 10 with RepoException

use of com.google.copybara.exception.RepoException in project copybara by google.

the class GerritDestinationTest method setup.

@Before
public void setup() throws Exception {
    workdir = Files.createTempDirectory("workdir");
    console = new TestingConsole();
    options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
    urlMapper = Files.createTempDirectory("url_mapper");
    options.git = new TestGitOptions(urlMapper, () -> options.general);
    options.gerrit = new GerritOptions(() -> options.general, options.git) {

        @Override
        protected GerritApiTransportImpl getGerritApiTransport(URI uri) throws RepoException {
            return new GerritApiTransportImpl(repo(), uri, gitApiMockHttpTransport);
        }
    };
    options.gitDestination = new GitDestinationOptions(() -> options.general, options.git);
    options.gitDestination.committerEmail = "commiter@email";
    options.gitDestination.committerName = "Bara Kopi";
    excludedDestinationPaths = ImmutableList.of();
    repoGitDir = localGerritRepo("localhost:33333/foo/bar").getGitDir();
    url = "https://localhost:33333/foo/bar";
    repo().init();
    skylark = new SkylarkTestExecutor(options, GitModule.class);
    gitApiMockHttpTransport = new GitApiMockHttpTransport() {

        @Override
        protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request) throws IOException {
            if (method.equals("GET") && url.startsWith("https://localhost:33333/changes/")) {
                String result = "[" + "{" + "  change_id : \"" + changeIdFromRequest(url) + "\"," + "  status : \"NEW\"" + "}]";
                return result.getBytes(UTF_8);
            }
            throw new IllegalArgumentException(method + " " + url);
        }
    };
}
Also used : TestGitOptions(com.google.copybara.testing.git.GitTestUtil.TestGitOptions) RepoException(com.google.copybara.exception.RepoException) IOException(java.io.IOException) URI(java.net.URI) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) GerritApiTransportImpl(com.google.copybara.git.gerritapi.GerritApiTransportImpl) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) Before(org.junit.Before)

Aggregations

RepoException (com.google.copybara.exception.RepoException)28 IOException (java.io.IOException)14 ValidationException (com.google.copybara.exception.ValidationException)11 ImmutableList (com.google.common.collect.ImmutableList)8 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)8 Path (java.nio.file.Path)8 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)7 Before (org.junit.Before)7 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)6 TestGitOptions (com.google.copybara.testing.git.GitTestUtil.TestGitOptions)6 HttpTransport (com.google.api.client.http.HttpTransport)5 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)5 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)5 Glob (com.google.copybara.util.Glob)5 GenericUrl (com.google.api.client.http.GenericUrl)4 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)4 Iterables (com.google.common.collect.Iterables)4 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)4 DummyRevision (com.google.copybara.testing.DummyRevision)4 GitApiMockHttpTransport (com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport)4