Search in sources :

Example 1 with GeneralOptions

use of com.google.copybara.GeneralOptions in project copybara by google.

the class GerritDestination method newGerritDestination.

static GerritDestination newGerritDestination(Options options, String url, String fetch, String pushToRefsFor, boolean submit, ChangeIdPolicy changeIdPolicy) {
    GeneralOptions generalOptions = options.get(GeneralOptions.class);
    if (pushToRefsFor.isEmpty()) {
        pushToRefsFor = fetch;
    }
    GerritOptions gerritOptions = options.get(GerritOptions.class);
    String push;
    if (submit) {
        push = pushToRefsFor;
    } else {
        push = Strings.isNullOrEmpty(gerritOptions.gerritTopic) ? String.format("refs/for/%s", pushToRefsFor) : String.format("refs/for/%s%%topic=%s", pushToRefsFor, gerritOptions.gerritTopic);
    }
    GitDestinationOptions destinationOptions = options.get(GitDestinationOptions.class);
    return new GerritDestination(new GitDestination(url, fetch, push, destinationOptions, options.get(GitOptions.class), generalOptions, /*skipPush=*/
    false, new CommitGenerator(gerritOptions, url, destinationOptions.getCommitter(), generalOptions.console(), changeIdPolicy), new GerritProcessPushOutput(generalOptions.console()), NO_GIT_DESTINATION_INTEGRATES), submit);
}
Also used : GeneralOptions(com.google.copybara.GeneralOptions)

Example 2 with GeneralOptions

use of com.google.copybara.GeneralOptions 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 3 with GeneralOptions

use of com.google.copybara.GeneralOptions in project copybara by google.

the class GithubPROrigin method newReader.

@Override
public Reader<GitRevision> newReader(Glob originFiles, Authoring authoring) throws ValidationException {
    return new ReaderImpl(url, originFiles, authoring, gitOptions, gitOriginOptions, generalOptions, /*includeBranchCommitLogs=*/
    false, submoduleStrategy, firstParent) {

        /**
         * Disable rebase since this is controlled by useMerge field.
         */
        @Override
        protected void maybeRebase(GitRepository repo, GitRevision ref, Path workdir) throws RepoException, CannotResolveRevisionException {
        }

        @Override
        public Optional<Baseline<GitRevision>> findBaseline(GitRevision startRevision, String label) throws RepoException, ValidationException {
            if (!baselineFromBranch) {
                return super.findBaseline(startRevision, label);
            }
            return findBaselinesWithoutLabel(startRevision, /*limit=*/
            1).stream().map(e -> new Baseline<>(e.getSha1(), e)).findFirst();
        }

        @Override
        public ImmutableList<GitRevision> findBaselinesWithoutLabel(GitRevision startRevision, int limit) throws RepoException, ValidationException {
            String baseline = startRevision.associatedLabels().get(GITHUB_BASE_BRANCH_SHA1);
            Preconditions.checkNotNull(baseline, "%s label should be present in %s", GITHUB_BASE_BRANCH_SHA1, startRevision);
            GitRevision baselineRev = getRepository().resolveReference(baseline);
            // Don't skip the first change as it is already the baseline
            BaselinesWithoutLabelVisitor<GitRevision> visitor = new BaselinesWithoutLabelVisitor<>(originFiles, limit, /*skipFirst=*/
            false);
            visitChanges(baselineRev, visitor);
            return visitor.getResult();
        }

        @Override
        public Endpoint getFeedbackEndPoint() {
            return new GitHubEndPoint(githubOptions, url);
        }

        /**
         * Deal with the case of useMerge. We have a new commit (the merge) and first-parent from that
         * commit doesn't work for this case.
         */
        @Override
        public ChangesResponse<GitRevision> changes(@Nullable GitRevision fromRef, GitRevision toRef) throws RepoException {
            if (!useMerge) {
                return super.changes(fromRef, toRef);
            }
            GitLogEntry merge = Iterables.getOnlyElement(getRepository().log(toRef.getSha1()).withLimit(1).run());
            // Fast-forward merge
            if (merge.getParents().size() == 1) {
                return super.changes(fromRef, toRef);
            }
            // HEAD of the Pull Request
            GitRevision gitRevision = merge.getParents().get(1);
            ChangesResponse<GitRevision> prChanges = super.changes(fromRef, gitRevision);
            // origin_files
            if (prChanges.isEmpty()) {
                return prChanges;
            }
            try {
                return ChangesResponse.forChanges(ImmutableList.<Change<GitRevision>>builder().addAll(prChanges.getChanges()).add(change(merge.getCommit())).build());
            } catch (EmptyChangeException e) {
                throw new RepoException("Error getting the merge commit information: " + merge, e);
            }
        }

        @Nullable
        @Override
        public String getGroupIdentity(GitRevision rev) throws RepoException {
            return rev.associatedLabels().get(GITHUB_PR_NUMBER_LABEL);
        }
    };
}
Also used : Path(java.nio.file.Path) Iterables(com.google.common.collect.Iterables) Origin(com.google.copybara.Origin) ValidationException.checkCondition(com.google.copybara.exception.ValidationException.checkCondition) RepoException(com.google.copybara.exception.RepoException) Collections2(com.google.common.collect.Collections2) SubmoduleStrategy(com.google.copybara.git.GitOrigin.SubmoduleStrategy) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Change(com.google.copybara.Change) BaselinesWithoutLabelVisitor(com.google.copybara.BaselinesWithoutLabelVisitor) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) Endpoint(com.google.copybara.Endpoint) Issue(com.google.copybara.git.github.api.Issue) Splitter(com.google.common.base.Splitter) GeneralOptions(com.google.copybara.GeneralOptions) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Label(com.google.copybara.git.github.api.Issue.Label) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) ImmutableMap(com.google.common.collect.ImmutableMap) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) CharMatcher(com.google.common.base.CharMatcher) ValidationException(com.google.copybara.exception.ValidationException) ReaderImpl(com.google.copybara.git.GitOrigin.ReaderImpl) Set(java.util.Set) Console(com.google.copybara.util.console.Console) Sets(com.google.common.collect.Sets) GithubUtil.getProjectNameFromUrl(com.google.copybara.git.github.util.GithubUtil.getProjectNameFromUrl) TimeUnit(java.util.concurrent.TimeUnit) Authoring(com.google.copybara.authoring.Authoring) Glob(com.google.copybara.util.Glob) PullRequest(com.google.copybara.git.github.api.PullRequest) GithubUtil.asGithubUrl(com.google.copybara.git.github.util.GithubUtil.asGithubUrl) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) GithubUtil(com.google.copybara.git.github.util.GithubUtil) Collections(java.util.Collections) GithubPrUrl(com.google.copybara.git.github.util.GithubUtil.GithubPrUrl) ReaderImpl(com.google.copybara.git.GitOrigin.ReaderImpl) Change(com.google.copybara.Change) RepoException(com.google.copybara.exception.RepoException) BaselinesWithoutLabelVisitor(com.google.copybara.BaselinesWithoutLabelVisitor) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Nullable(javax.annotation.Nullable) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry)

Example 4 with GeneralOptions

use of com.google.copybara.GeneralOptions in project copybara by google.

the class GerritOptionsTest method setup.

@Before
public void setup() {
    Supplier<GeneralOptions> generalOptionsSupplier = Suppliers.ofInstance(new GeneralOptions(FileSystems.getDefault(), /*verbose=*/
    true, LogConsole.writeOnlyConsole(System.out, /*verbose=*/
    true)));
    options = new GerritOptions(generalOptionsSupplier, new GitOptions(generalOptionsSupplier));
    jcommander = new JCommander(ImmutableList.of(options));
}
Also used : GeneralOptions(com.google.copybara.GeneralOptions) JCommander(com.beust.jcommander.JCommander) Before(org.junit.Before)

Aggregations

GeneralOptions (com.google.copybara.GeneralOptions)4 RepoException (com.google.copybara.exception.RepoException)2 JCommander (com.beust.jcommander.JCommander)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CharMatcher (com.google.common.base.CharMatcher)1 Preconditions (com.google.common.base.Preconditions)1 Splitter (com.google.common.base.Splitter)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 BaselinesWithoutLabelVisitor (com.google.copybara.BaselinesWithoutLabelVisitor)1 Change (com.google.copybara.Change)1 Endpoint (com.google.copybara.Endpoint)1 Origin (com.google.copybara.Origin)1 Authoring (com.google.copybara.authoring.Authoring)1 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)1