use of net.starlark.java.annot.StarlarkMethod in project copybara by google.
the class MetadataModule method mapReferences.
@SuppressWarnings("unused")
@StarlarkMethod(name = "map_references", doc = "Allows updating links to references in commit messages to match the destination's " + "format. Note that this will only consider the 5000 latest commits.", parameters = { @Param(name = "before", named = true, doc = "Template for origin references in the change message. Use a '${reference}'" + " token to capture the actual references. E.g. if the origin uses links" + " like 'http://changes?1234', the template would be " + "'http://changes?${reference}', with reference_regex = '[0-9]+'"), @Param(name = "after", named = true, doc = "Format for destination references in the change message. Use a '${reference}'" + " token to represent the destination reference. E.g. if the destination uses" + " links like 'http://changes?1234', the template would be " + "'http://changes?${reference}', with reference_regex = '[0-9]+'"), @Param(name = "regex_groups", defaultValue = "{}", named = true, doc = "Regexes for the ${reference} token's content. Requires one 'before_ref' entry" + " matching the ${reference} token's content on the before side. Optionally" + " accepts one 'after_ref' used for validation." + " Copybara uses [re2](https://github.com/google/re2/wiki/Syntax) syntax."), @Param(name = "additional_import_labels", named = true, allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, defaultValue = "[]", doc = "Meant to be used when migrating from another tool: Per default, copybara will" + " only recognize the labels defined in the workflow's endpoints. The tool" + " will use these additional labels to find labels created by other" + " invocations and tools.") }, useStarlarkThread = true)
@Example(title = "Map references, origin source of truth", before = "Finds links to commits in change messages, searches destination to find the equivalent" + " reference in destination. Then replaces matches of 'before' with 'after'," + " replacing the subgroup matched with the destination reference. Assume a message" + " like 'Fixes bug introduced in origin/abcdef', where the origin change 'abcdef'" + " was migrated as '123456' to the destination.", code = "metadata.map_references(\n" + " before = \"origin/${reference}\",\n" + " after = \"destination/${reference}\",\n" + " regex_groups = {\n" + " \"before_ref\": \"[0-9a-f]+\",\n" + " \"after_ref\": \"[0-9]+\",\n" + " },\n" + ")", after = "This would be translated into 'Fixes bug introduced in destination/123456', provided" + " that a change with the proper label was found - the message remains unchanged " + "otherwise.")
public ReferenceMigrator mapReferences(String originPattern, String destinationFormat, // <String, String>
Dict<?, ?> groups, // <String>
Sequence<?> labels, StarlarkThread thread) throws EvalException {
Map<String, String> groupsMap = Dict.cast(groups, String.class, String.class, "regex_groups");
check(groupsMap.containsKey("before_ref") && (groupsMap.size() != 2 || groupsMap.containsKey("after_ref")) && groupsMap.size() <= 2, "Invalid 'regex_groups' - Should only contain 'before_ref' and " + "optionally 'after_ref'. Was: %s.", groupsMap.keySet());
Pattern beforePattern;
Pattern afterPattern = null;
try {
beforePattern = Pattern.compile(groupsMap.get("before_ref"));
} catch (java.util.regex.PatternSyntaxException exception) {
throw Starlark.errorf("Invalid before_ref regex '%s'.", groupsMap.get("before_ref"));
}
if (groupsMap.containsKey("after_ref")) {
try {
afterPattern = Pattern.compile(groupsMap.get("after_ref"));
} catch (java.util.regex.PatternSyntaxException exception) {
throw Starlark.errorf("Invalid after_ref regex '%s'.", groupsMap.get("after_ref"));
}
}
return ReferenceMigrator.create(originPattern, destinationFormat, beforePattern, afterPattern, ImmutableList.copyOf(SkylarkUtil.convertStringList(labels, "labels")), thread.getCallerLocation());
}
use of net.starlark.java.annot.StarlarkMethod in project copybara by google.
the class PatchModule method quiltApply.
@SuppressWarnings("unused")
@StarlarkMethod(name = "quilt_apply", doc = "A transformation that applies and updates patch files using Quilt. Compared to" + " `patch.apply`, this transformation supports updating the content of patch files" + " if they can be successfully applied with fuzz. The patch files must be included" + " in the destination_files glob in order to get updated. Underneath, Copybara" + " runs `quilt import; quilt push; quilt refresh` for each patch file in the" + " `series` file in order. Currently, all patch files and the `series` file must" + " reside in a \"patches\" sub-directory under the root directory containing the" + " migrated code. This means it has the limitation that the migrated code itself" + " cannot contain a directory with the name \"patches\".", parameters = { @Param(name = "series", named = true, positional = false, doc = "A file which contains a list of patches to apply. It is similar to the `series`" + " parameter in `patch.apply` transformation, and is required for Quilt." + " Patches listed in this file will be applied relative to the checkout dir," + " and the leading path component is stripped via the `-p1` flag. Currently" + " this file should be the `patches/series` file in the root directory" + " of the migrated code.") }, useStarlarkThread = true)
@Example(title = "Workflow to apply and update patches", before = "Suppose the destination repository's directory structure looks like:\n" + "```\n" + "source_root/BUILD\n" + "source_root/copy.bara.sky\n" + "source_root/migrated_file1\n" + "source_root/migrated_file2\n" + "source_root/patches/series\n" + "source_root/patches/patch1.patch\n" + "```\n" + "Then the transformations in `source_root/copy.bara.sky` should look like:", code = "[\n" + " patch.quilt_apply(series = \"patches/series\"),\n" + " core.move(\"\", \"source_root\"),\n" + "]", after = "In this example, `patch1.patch` is applied to `migrated_file1` and/or `migrated_file2`." + " `patch1.patch` itself will be updated during the migration if it is applied with" + " fuzz.")
@UsesFlags(PatchingOptions.class)
public QuiltTransformation quiltApply(String series, StarlarkThread thread) throws EvalException {
ImmutableList.Builder<ConfigFile> builder = ImmutableList.builder();
ConfigFile seriesFile = parseSeries(series, builder);
return new QuiltTransformation(seriesFile, builder.build(), patchingOptions, /*reverse=*/
false, thread.getCallerLocation());
}
Aggregations