Search in sources :

Example 6 with Module

use of net.starlark.java.eval.Module in project copybara by google.

the class GitModule method mirror.

@SuppressWarnings("unused")
@StarlarkMethod(name = "mirror", doc = "Mirror git references between repositories", parameters = { @Param(name = "name", named = true, doc = "Migration name"), @Param(name = "origin", named = true, doc = "Indicates the URL of the origin git repository"), @Param(name = "destination", named = true, doc = "Indicates the URL of the destination git repository"), @Param(name = "refspecs", allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, named = true, defaultValue = "['refs/heads/*']", doc = "Represents a list of git refspecs to mirror between origin and destination." + " For example 'refs/heads/*:refs/remotes/origin/*' will mirror any reference" + " inside refs/heads to refs/remotes/origin."), @Param(name = "prune", named = true, doc = "Remove remote refs that don't have a origin counterpart. Prune is ignored if" + " actions are used (Action is in charge of doing the pruning)", defaultValue = "False"), @Param(name = "partial_fetch", defaultValue = "False", named = true, positional = false, doc = "This is an experimental feature that only works for certain origin globs."), @Param(name = "description", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, positional = false, doc = "A description of what this migration achieves", defaultValue = "None"), @Param(name = "actions", doc = "Experimental feature. " + "A list of mirror actions to perform, with the following semantics:\n" + "  - There is no guarantee of the order of execution.\n" + "  - Actions need to be independent from each other.\n" + "  - Failure in one action might prevent other actions from executing." + " --force can be used to continue for 'user' errors like non-fast-forward" + " errors.\n" + "\n" + "Actions will be in charge of doing the fetch, push, rebases, merges,etc." + "Only fetches/pushes for the declared refspec are allowed", defaultValue = "[]", positional = false, named = true) }, useStarlarkThread = true)
@UsesFlags(GitMirrorOptions.class)
public NoneType mirror(String name, String origin, String destination, // <String>
Sequence<?> strRefSpecs, Boolean prune, Boolean partialFetch, Object description, net.starlark.java.eval.Sequence<?> mirrorActions, StarlarkThread thread) throws EvalException {
    GeneralOptions generalOptions = options.get(GeneralOptions.class);
    GitOptions gitOptions = options.get(GitOptions.class);
    List<Refspec> refspecs = new ArrayList<>();
    for (String refspec : Sequence.cast(strRefSpecs, String.class, "refspecs")) {
        try {
            refspecs.add(Refspec.create(gitOptions.getGitEnvironment(generalOptions.getEnvironment()), generalOptions.getCwd(), refspec));
        } catch (InvalidRefspecException e) {
            throw Starlark.errorf("%s", e.getMessage());
        }
    }
    ImmutableList<Action> actions = convertActions(mirrorActions, printHandler);
    Module module = Module.ofInnermostEnclosingStarlarkFunction(thread);
    GlobalMigrations.getGlobalMigrations(module).addMigration(name, new Mirror(generalOptions, gitOptions, name, fixHttp(origin, thread.getCallerLocation()), fixHttp(destination, thread.getCallerLocation()), refspecs, options.get(GitMirrorOptions.class), prune, partialFetch, mainConfigFile, convertFromNoneable(description, null), actions));
    return Starlark.NONE;
}
Also used : GeneralOptions(com.google.copybara.GeneralOptions) StarlarkAction(com.google.copybara.action.StarlarkAction) Action(com.google.copybara.action.Action) ArrayList(java.util.ArrayList) LabelsAwareModule(com.google.copybara.config.LabelsAwareModule) Module(net.starlark.java.eval.Module) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) UsesFlags(com.google.copybara.doc.annotations.UsesFlags)

Aggregations

Module (net.starlark.java.eval.Module)6 LabelsAwareModule (com.google.copybara.config.LabelsAwareModule)3 UsesFlags (com.google.copybara.doc.annotations.UsesFlags)3 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)3 Action (com.google.copybara.action.Action)2 StarlarkAction (com.google.copybara.action.StarlarkAction)2 FolderModule (com.google.copybara.folder.FolderModule)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GeneralOptions (com.google.copybara.GeneralOptions)1 Author (com.google.copybara.authoring.Author)1 Authoring (com.google.copybara.authoring.Authoring)1 DocDefault (com.google.copybara.doc.annotations.DocDefault)1 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)1 ValidationException (com.google.copybara.exception.ValidationException)1 Feedback (com.google.copybara.feedback.Feedback)1 Token (com.google.copybara.templatetoken.Token)1 Sequence (com.google.copybara.transform.Sequence)1 SkylarkTransformation (com.google.copybara.transform.SkylarkTransformation)1 Transformations.toTransformation (com.google.copybara.transform.Transformations.toTransformation)1 IOException (java.io.IOException)1