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;
}
Aggregations