use of com.google.copybara.doc.annotations.DocDefault in project copybara by google.
the class Core method filterReplace.
@SuppressWarnings("unused")
@StarlarkMethod(name = "filter_replace", doc = "Applies an initial filtering to find a substring to be replaced and then applies" + " a `mapping` of replaces for the matched text.", parameters = { @Param(name = "regex", named = true, doc = "A re2 regex to match a substring of the file", allowedTypes = { @ParamType(type = String.class) }), @Param(name = "mapping", named = true, doc = "A mapping function like core.replace_mapper or a dict with mapping values.", defaultValue = "{}"), @Param(name = "group", named = true, allowedTypes = { @ParamType(type = StarlarkInt.class), @ParamType(type = NoneType.class) }, doc = "Extract a regex group from the matching text and pass this as parameter to" + " the mapping instead of the whole matching text.", defaultValue = "None"), @Param(name = "paths", named = true, allowedTypes = { @ParamType(type = Glob.class), @ParamType(type = NoneType.class) }, doc = "A glob expression relative to the workdir representing the files to apply the" + " transformation. For example, glob([\"**.java\"]), matches all java files" + " recursively. Defaults to match all the files recursively.", defaultValue = "None"), @Param(name = "reverse", named = true, allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, doc = "A re2 regex used as reverse transformation", defaultValue = "None") }, useStarlarkThread = true)
@DocDefault(field = "paths", value = "glob([\"**\"])")
@DocDefault(field = "reverse", value = "regex")
@DocDefault(field = "group", value = "Whole text")
@Example(title = "Simple replace with mapping", before = "Simplest mapping", code = SIMPLE_FILTER_REPLACE_EXAMPLE)
@Example(title = "TODO replace", before = "This replace is similar to what it can be achieved with core.todo_replace:", code = TODO_FILTER_REPLACE_EXAMPLE)
public FilterReplace filterReplace(String regex, Object mapping, Object group, Object paths, Object reverse, StarlarkThread thread) throws EvalException {
ReversibleFunction<String, String> func = getMappingFunction(mapping);
String afterPattern = convertFromNoneable(reverse, regex);
int numGroup = convertFromNoneable(group, StarlarkInt.of(0)).toInt("group");
Pattern before = Pattern.compile(regex);
check(numGroup <= before.groupCount(), "group idx is greater than the number of groups defined in '%s'. Regex has %s groups", before.pattern(), before.groupCount());
Pattern after = Pattern.compile(afterPattern);
check(numGroup <= after.groupCount(), "reverse_group idx is greater than the number of groups defined in '%s'." + " Regex has %s groups", after.pattern(), after.groupCount());
return new FilterReplace(workflowOptions, before, after, numGroup, numGroup, func, convertFromNoneable(paths, Glob.ALL_FILES), thread.getCallerLocation());
}
use of com.google.copybara.doc.annotations.DocDefault in project copybara by google.
the class Core method workflow.
@SuppressWarnings({ "unused", "unchecked" })
@StarlarkMethod(name = "workflow", doc = "Defines a migration pipeline which can be invoked via the Copybara command.\n" + "\n" + "Implicit labels that can be used/exposed:\n" + "\n" + " - " + TransformWork.COPYBARA_CONTEXT_REFERENCE_LABEL + ": Requested reference. For example if copybara is invoked as `copybara" + " copy.bara.sky workflow master`, the value would be `master`.\n" + " - " + TransformWork.COPYBARA_LAST_REV + ": Last reference that was migrated\n" + " - " + TransformWork.COPYBARA_CURRENT_REV + ": The current reference being migrated\n" + " - " + TransformWork.COPYBARA_CURRENT_REV_DATE_TIME + ": Date & time for the current reference being migrated in ISO format" + " (Example: \"2011-12-03T10:15:30+01:00\")\n" + " - " + TransformWork.COPYBARA_CURRENT_MESSAGE + ": The current message at this point of the transformations\n" + " - " + TransformWork.COPYBARA_CURRENT_MESSAGE_TITLE + ": The current message title (first line) at this point of the transformations\n" + " - " + TransformWork.COPYBARA_AUTHOR + ": The author of the change\n", parameters = { @Param(name = "name", named = true, doc = "The name of the workflow.", positional = false), @Param(name = "origin", named = true, doc = "Where to read from the code to be migrated, before applying the " + "transformations. This is usually a VCS like Git, but can also be a local " + "folder or even a pending change in a code review system like Gerrit.", positional = false), @Param(name = "destination", named = true, doc = "Where to write to the code being migrated, after applying the " + "transformations. This is usually a VCS like Git, but can also be a local " + "folder or even a pending change in a code review system like Gerrit.", positional = false), @Param(name = "authoring", named = true, doc = "The author mapping configuration from origin to destination.", positional = false), @Param(name = "transformations", named = true, doc = "The transformations to be run for this workflow. They will run in sequence.", positional = false, defaultValue = "[]"), @Param(name = "origin_files", named = true, allowedTypes = { @ParamType(type = Glob.class), @ParamType(type = NoneType.class) }, doc = "A glob relative to the workdir that will be read from the" + " origin during the import. For example glob([\"**.java\"]), all java files," + " recursively, which excludes all other file types.", defaultValue = "None", positional = false), @Param(name = "destination_files", named = true, allowedTypes = { @ParamType(type = Glob.class), @ParamType(type = NoneType.class) }, doc = "A glob relative to the root of the destination repository that matches files that" + " are part of the migration. Files NOT matching this glob will never be" + " removed, even if the file does not exist in the source. For example" + " glob(['**'], exclude = ['**/BUILD']) keeps all BUILD files in destination" + " when the origin does not have any BUILD files. You can also use this to" + " limit the migration to a subdirectory of the destination, e.g." + " glob(['java/src/**'], exclude = ['**/BUILD']) to only affect non-BUILD" + " files in java/src.", defaultValue = "None", positional = false), @Param(name = "mode", named = true, doc = "Workflow mode. Currently we support four modes:<br><ul><li><b>'SQUASH'</b>:" + " Create a single commit in the destination with new tree" + " state.</li><li><b>'ITERATIVE'</b>: Import each origin change" + " individually.</li><li><b>'CHANGE_REQUEST'</b>: Import a pending change to" + " the Source-of-Truth. This could be a GH Pull Request, a Gerrit Change," + " etc. The final intention should be to submit the change in the SoT" + " (destination in this case).</li><li><b>'CHANGE_REQUEST_FROM_SOT'</b>:" + " Import a pending change **from** the Source-of-Truth. This mode is useful" + " when, despite the pending change being already in the SoT, the users want" + " to review the code on a different system. The final intention should never" + " be to submit in the destination, but just review or test</li></ul>", defaultValue = "\"SQUASH\"", positional = false), @Param(name = "reversible_check", named = true, allowedTypes = { @ParamType(type = Boolean.class), @ParamType(type = NoneType.class) }, doc = "Indicates if the tool should try to to reverse all the transformations" + " at the end to check that they are reversible.<br/>The default value is" + " True for 'CHANGE_REQUEST' mode. False otherwise", defaultValue = "None", positional = false), @Param(name = CHECK_LAST_REV_STATE, named = true, doc = "If set to true, Copybara will validate that the destination didn't change" + " since last-rev import for destination_files. Note that this" + " flag doesn't work for CHANGE_REQUEST mode.", defaultValue = "False", positional = false), @Param(name = "ask_for_confirmation", named = true, doc = "Indicates that the tool should show the diff and require user's" + " confirmation before making a change in the destination.", defaultValue = "False", positional = false), @Param(name = "dry_run", named = true, doc = "Run the migration in dry-run mode. Some destination implementations might" + " have some side effects (like creating a code review), but never submit to a" + " main branch.", defaultValue = "False", positional = false), @Param(name = "after_migration", named = true, doc = "Run a feedback workflow after one migration happens. This runs once per" + " change in `ITERATIVE` mode and only once for `SQUASH`.", defaultValue = "[]", positional = false), @Param(name = "after_workflow", named = true, doc = "Run a feedback workflow after all the changes for this workflow run are migrated." + " Prefer `after_migration` as it is executed per change (in ITERATIVE mode)." + " Tasks in this hook shouldn't be critical to execute. These actions" + " shouldn't record effects (They'll be ignored).", defaultValue = "[]", positional = false), @Param(name = "change_identity", named = true, allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, doc = "By default, Copybara hashes several fields so that each change has an unique" + " identifier that at the same time reuses the generated destination change." + " This allows to customize the identity hash generation so that the same" + " identity is used in several workflows. At least ${copybara_config_path}" + " has to be present. Current user is added to the hash" + " automatically.<br><br>Available variables:<ul> " + " <li>${copybara_config_path}: Main config file path</li> " + " <li>${copybara_workflow_name}: The name of the workflow being run</li> " + " <li>${copybara_reference}: The requested reference. In general Copybara" + " tries its best to give a repetable reference. For example Gerrit change" + " number or change-id or GitHub Pull Request number. If it cannot find a" + " context reference it uses the resolved revision.</li> " + " <li>${label:label_name}: A label present for the current change. Exposed" + " in the message or not.</li></ul>If any of the labels cannot be found it" + " defaults to the default identity (The effect would be no reuse of" + " destination change between workflows)", defaultValue = "None", positional = false), @Param(name = "set_rev_id", named = true, doc = "Copybara adds labels like 'GitOrigin-RevId' in the destination in order to" + " track what was the latest change imported. For `CHANGE_REQUEST` " + "workflows it is not used and is purely informational. This field " + "allows to disable it for that mode. Destinations might ignore the flag.", defaultValue = "True", positional = false), @Param(name = "smart_prune", named = true, doc = "By default CHANGE_REQUEST workflows cannot restore scrubbed files. This flag does" + " a best-effort approach in restoring the non-affected snippets. For now we" + " only revert the non-affected files. This only works for CHANGE_REQUEST" + " mode.", defaultValue = "False", positional = false), @Param(name = "migrate_noop_changes", named = true, doc = "By default, Copybara tries to only migrate changes that affect origin_files or" + " config files. This flag allows to include all the changes. Note that it" + " might generate more empty changes errors. In `ITERATIVE` mode it might" + " fail if some transformation is validating the message (Like has to contain" + " 'PUBLIC' and the change doesn't contain it because it is internal).", defaultValue = "False", positional = false), @Param(name = "experimental_custom_rev_id", named = true, allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, doc = "Use this label name instead of the one provided by the origin. This is subject" + " to change and there is no guarantee.", defaultValue = "None", positional = false), @Param(name = "description", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, positional = false, doc = "A description of what this workflow achieves", defaultValue = "None"), @Param(name = "checkout", named = true, positional = false, doc = "Allows disabling the checkout. The usage of this feature is rare. This could" + " be used to update a file of your own repo when a dependant repo version" + " changes and you are not interested on the files of the dependant repo, just" + " the new version.", defaultValue = "True"), @Param(name = "reversible_check_ignore_files", named = true, allowedTypes = { @ParamType(type = Glob.class), @ParamType(type = NoneType.class) }, doc = "Ignore the files matching the glob in the reversible check", defaultValue = "None", positional = false) }, useStarlarkThread = true)
@UsesFlags({ WorkflowOptions.class })
@DocDefault(field = "origin_files", value = "glob([\"**\"])")
@DocDefault(field = "destination_files", value = "glob([\"**\"])")
@DocDefault(field = "reversible_check", value = "True for 'CHANGE_REQUEST' mode. False otherwise")
@DocDefault(field = "reversible_check_ignore_files", value = "None")
public void workflow(String workflowName, // <Revision>, but skylark allows only ?
Origin<?> origin, Destination<?> destination, Authoring authoring, net.starlark.java.eval.Sequence<?> transformations, Object originFiles, Object destinationFiles, String modeStr, Object reversibleCheckObj, boolean checkLastRevState, Boolean askForConfirmation, Boolean dryRunMode, net.starlark.java.eval.Sequence<?> afterMigrations, net.starlark.java.eval.Sequence<?> afterAllMigrations, Object changeIdentityObj, Boolean setRevId, Boolean smartPrune, Boolean migrateNoopChanges, Object customRevIdField, Object description, Boolean checkout, Object reversibleCheckIgnoreFiles, StarlarkThread thread) throws EvalException {
WorkflowMode mode = stringToEnum("mode", modeStr, WorkflowMode.class);
// Overwrite destination for testing workflow locally
if (workflowOptions.toFolder) {
destination = folderModule.destination();
}
Sequence sequenceTransform = Sequence.fromConfig(generalOptions.profiler(), workflowOptions, transformations, "transformations", printHandler, debugOptions::transformWrapper, Sequence.NoopBehavior.NOOP_IF_ANY_NOOP);
Transformation reverseTransform = null;
if (!generalOptions.isDisableReversibleCheck() && convertFromNoneable(reversibleCheckObj, mode == WorkflowMode.CHANGE_REQUEST)) {
try {
reverseTransform = sequenceTransform.reverse();
} catch (NonReversibleValidationException e) {
throw Starlark.errorf("%s", e.getMessage());
}
}
ImmutableList<Token> changeIdentity = getChangeIdentity(changeIdentityObj);
String customRevId = convertFromNoneable(customRevIdField, null);
check(customRevId == null || CUSTOM_REVID_FORMAT.matches(customRevId), "Invalid experimental_custom_rev_id format. Format: %s", CUSTOM_REVID_FORMAT.pattern());
if (setRevId) {
check(mode != WorkflowMode.CHANGE_REQUEST || customRevId == null, "experimental_custom_rev_id is not allowed to be used in CHANGE_REQUEST mode if" + " set_rev_id is set to true. experimental_custom_rev_id is used for looking" + " for the baseline in the origin. No revId is stored in the destination.");
} else {
check(mode == WorkflowMode.CHANGE_REQUEST || mode == WorkflowMode.CHANGE_REQUEST_FROM_SOT, "'set_rev_id = False' is only supported" + " for CHANGE_REQUEST and CHANGE_REQUEST_FROM_SOT mode.");
}
if (smartPrune) {
check(mode == WorkflowMode.CHANGE_REQUEST, "'smart_prune = True' is only supported" + " for CHANGE_REQUEST mode.");
}
if (checkLastRevState) {
check(mode != WorkflowMode.CHANGE_REQUEST, "%s is not compatible with %s", CHECK_LAST_REV_STATE, WorkflowMode.CHANGE_REQUEST);
}
Authoring resolvedAuthoring = authoring;
Author defaultAuthorFlag = workflowOptions.getDefaultAuthorFlag();
if (defaultAuthorFlag != null) {
resolvedAuthoring = new Authoring(defaultAuthorFlag, authoring.getMode(), authoring.getAllowlist());
}
WorkflowMode effectiveMode = generalOptions.squash ? WorkflowMode.SQUASH : mode;
Workflow<Revision, ?> workflow = new Workflow<>(workflowName, convertFromNoneable(description, null), (Origin<Revision>) origin, destination, resolvedAuthoring, sequenceTransform, workflowOptions.getLastRevision(), workflowOptions.isInitHistory(), generalOptions, convertFromNoneable(originFiles, Glob.ALL_FILES), convertFromNoneable(destinationFiles, Glob.ALL_FILES), effectiveMode, workflowOptions, reverseTransform, convertFromNoneable(reversibleCheckIgnoreFiles, null), askForConfirmation, mainConfigFile, allConfigFiles, dryRunMode, checkLastRevState || workflowOptions.checkLastRevState, convertFeedbackActions(afterMigrations, printHandler), convertFeedbackActions(afterAllMigrations, printHandler), changeIdentity, setRevId, smartPrune, workflowOptions.migrateNoopChanges || migrateNoopChanges, customRevId, checkout);
Module module = Module.ofInnermostEnclosingStarlarkFunction(thread);
registerGlobalMigration(workflowName, workflow, module);
}
use of com.google.copybara.doc.annotations.DocDefault in project copybara by google.
the class ModuleLoader method processStarlarkMethod.
private DocFunction processStarlarkMethod(Method method, StarlarkMethod annotation, @Nullable String prefix) {
Type[] genericParameterTypes = method.getGenericParameterTypes();
Param[] starlarkParams = annotation.parameters();
if (genericParameterTypes.length < starlarkParams.length) {
throw new IllegalStateException(String.format("Missing java parameters for: %s\n" + "%s\n" + "%s", method, Arrays.toString(genericParameterTypes), Arrays.toString(starlarkParams)));
}
ImmutableList.Builder<DocParam> params = ImmutableList.builder();
Map<String, DocDefault> docDefaultsMap = stream(method.getAnnotationsByType(DocDefault.class)).collect(Collectors.toMap(DocDefault::field, identity(), (f, v) -> v));
for (int i = 0; i < starlarkParams.length; i++) {
Type parameterType = genericParameterTypes[i];
Param starlarkParam = starlarkParams[i];
// Compute the list of names of allowed types (e.g. string or bool or NoneType).
List<String> allowedTypeNames = new ArrayList<>();
if (starlarkParam.allowedTypes().length > 0) {
for (ParamType param : starlarkParam.allowedTypes()) {
allowedTypeNames.add(skylarkTypeName(param.type()) + (param.generic1() != Object.class ? " of " + skylarkTypeName(param.generic1()) : ""));
}
} else {
// Otherwise use the type of the parameter variable itself.
allowedTypeNames.add(skylarkTypeName(parameterType));
}
DocDefault fieldInfo = docDefaultsMap.get(starlarkParam.name());
if (fieldInfo != null && fieldInfo.allowedTypes().length > 0) {
allowedTypeNames = Arrays.asList(fieldInfo.allowedTypes());
}
params.add(new DocParam(starlarkParam.name(), fieldInfo != null ? fieldInfo.value() : emptyToNull(starlarkParam.defaultValue()), allowedTypeNames, starlarkParam.doc()));
}
String returnType = method.getGenericReturnType().equals(NoneType.class) || method.getGenericReturnType().equals(void.class) ? null : skylarkTypeName(method.getGenericReturnType());
return new DocFunction(prefix != null ? prefix + "." + annotation.name() : annotation.name(), annotation.doc(), returnType, params.build(), generateFlagsInfo(method), stream(method.getAnnotationsByType(Example.class)).map(DocExample::new).collect(toImmutableList()));
}
use of com.google.copybara.doc.annotations.DocDefault in project copybara by google.
the class FormatModule method buildifier.
@StarlarkMethod(name = "buildifier", doc = "Formats the BUILD files using buildifier.", parameters = { @Param(name = "paths", allowedTypes = { @ParamType(type = Glob.class), @ParamType(type = NoneType.class) }, doc = "Paths of the files to format relative to the workdir.", defaultValue = "None", named = true), @Param(name = "type", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, doc = "The type of the files. Can be 'auto', 'bzl', 'build' or 'workspace'. Note that" + " this is not recommended to be set and might break in the future. The" + " default is 'auto'. This mode formats as BUILD files \"BUILD\"," + " \"BUILD.bazel\", \"WORKSPACE\" and \"WORKSPACE.bazel\" files. The rest as" + " bzl files. Prefer to use those names for BUILD files instead of setting" + " this flag.", defaultValue = "'auto'", named = true), @Param(name = "lint", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, doc = "If buildifier --lint should be used. This fixes several common issues. Note that" + " this transformation is difficult to revert. For example if it removes a" + " load statement because is not used after removing a rule, then the reverse" + " workflow needs to add back the load statement (core.replace or similar). " + " Possible values: `OFF`, `FIX`. Default is `OFF`", defaultValue = "None", named = true), @Param(name = "lint_warnings", allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, defaultValue = "[]", doc = "Warnings used in the lint mode. Default is buildifier default`", named = true) })
@DocDefault(field = "lint", value = "\"OFF\"")
@UsesFlags(BuildifierOptions.class)
@Example(title = "Default usage", before = "The default parameters formats all BUILD and bzl files in the checkout directory:", code = "format.buildifier()")
@Example(title = "Enable lint", before = "Enable lint for buildifier", code = "format.buildifier(lint = \"FIX\")")
@Example(title = "Using globs", before = "Globs can be used to match only certain files:", code = "format.buildifier(\n" + " paths = glob([\"foo/BUILD\", \"foo/**/BUILD\"], exclude = [\"foo/bar/BUILD\"])" + "\n)", after = "Formats all the BUILD files inside `foo` except for `foo/bar/BUILD`")
@DocDefault(field = "paths", value = "glob([\"**.bzl\", \"**/BUILD\", \"BUILD\"])")
public Transformation buildifier(// <String>
Object paths, // <String>
Object type, // <String>
Object lint, // <String>
Sequence<?> warnings) throws EvalException {
String typeStr = convertFromNoneable(type, null);
if (typeStr != null) {
check(BUILDIFIER_TYPE_VALUES.contains(typeStr), "Non-valid type: %s. Valid types: %s", typeStr, BUILDIFIER_TYPE_VALUES);
}
LintMode lintMode = stringToEnum("lint", convertFromNoneable(lint, "OFF"), LintMode.class);
check(lintMode != LintMode.OFF || warnings.isEmpty(), "Warnings can only be used when lint is set to FIX");
return new BuildifierFormat(buildifierOptions, generalOptions, convertFromNoneable(paths, DEFAULT_BUILDIFIER_PATHS), lintMode, ImmutableList.copyOf(Sequence.cast(warnings, String.class, "lint_warnings")), typeStr);
}
use of com.google.copybara.doc.annotations.DocDefault in project copybara by google.
the class GitModule method githubPrOrigin.
@SuppressWarnings("unused")
@StarlarkMethod(name = GITHUB_PR_ORIGIN_NAME, doc = "Defines a Git origin for Github pull requests.\n" + "\n" + "Implicit labels that can be used/exposed:\n" + "\n" + " - " + GitHubPrOrigin.GITHUB_PR_NUMBER_LABEL + ": The pull request number if the" + " reference passed was in the form of `https://github.com/project/pull/123`, " + " `refs/pull/123/head` or `refs/pull/123/master`.\n" + " - " + DEFAULT_INTEGRATE_LABEL + ": A label that when exposed, can be used to" + " integrate automatically in the reverse workflow.\n" + " - " + GITHUB_BASE_BRANCH + ": The name of the branch which serves as the base for the Pull Request.\n" + " - " + GITHUB_BASE_BRANCH_SHA1 + ": The SHA-1 of the commit used as baseline. Generally, the baseline commit is the" + " point of divergence between the PR's 'base' and 'head' branches. When `use_merge" + " = True` is specified, the baseline is instead the tip of the PR's base branch.\n" + " - " + GITHUB_PR_USE_MERGE + ": Equal to 'true' if the workflow is importing a GitHub PR 'merge' commit and" + " 'false' when importing a GitHub PR 'head' commit.\n" + " - " + GITHUB_PR_TITLE + ": Title of the Pull Request.\n" + " - " + GITHUB_PR_BODY + ": Body of the Pull Request.\n" + " - " + GITHUB_PR_URL + ": GitHub url of the Pull Request.\n" + " - " + GITHUB_PR_HEAD_SHA + ": The SHA-1 of the head commit of the pull request.\n" + " - " + GITHUB_PR_USER + ": The login of the author the pull request.\n" + " - " + GITHUB_PR_ASSIGNEE + ": A repeated label with the login of the assigned" + " users.\n" + " - " + GITHUB_PR_REVIEWER_APPROVER + ": A repeated label with the login of users" + " that have participated in the review and that can approve the import. Only" + " populated if `review_state` field is set. Every reviewers type matching" + " `review_approvers` will be added to this list.\n" + " - " + GITHUB_PR_REVIEWER_OTHER + ": A repeated label with the login of users" + " that have participated in the review but cannot approve the import. Only" + " populated if `review_state` field is set.\n", parameters = { @Param(name = "url", named = true, doc = "Indicates the URL of the GitHub repository"), @Param(name = "use_merge", defaultValue = "False", named = true, positional = false, doc = "If the content for refs/pull/<ID>/merge should be used instead of the PR" + " head. The GitOrigin-RevId still will be the one from" + " refs/pull/<ID>/head revision."), @Param(name = GitHubUtil.REQUIRED_LABELS, allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, named = true, defaultValue = "[]", doc = "Required labels to import the PR. All the labels need to be present in order to" + " migrate the Pull Request.", positional = false), @Param(name = GitHubUtil.REQUIRED_STATUS_CONTEXT_NAMES, allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, named = true, defaultValue = "[]", doc = "A list of names of services which must all mark the PR with 'success' before it" + " can be imported.<br><br>See" + " https://docs.github.com/en/rest/reference/repos#statuses", positional = false), @Param(name = GitHubUtil.REQUIRED_CHECK_RUNS, allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, named = true, defaultValue = "[]", doc = "A list of check runs which must all have a value of 'success' in order to import" + " the PR.<br><br>See" + " https://docs.github.com/en/rest/guides/getting-started-with-the-checks-api", positional = false), @Param(name = GitHubUtil.RETRYABLE_LABELS, allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class) }, named = true, defaultValue = "[]", doc = "Required labels to import the PR that should be retried. This parameter must" + " be a subset of required_labels.", positional = false), @Param(name = "submodules", defaultValue = "'NO'", named = true, positional = false, doc = "Download submodules. Valid values: NO, YES, RECURSIVE."), @Param(name = "baseline_from_branch", named = true, doc = "WARNING: Use this field only for github -> git CHANGE_REQUEST workflows.<br>" + "When the field is set to true for CHANGE_REQUEST workflows it will find the" + " baseline comparing the Pull Request with the base branch instead of looking" + " for the *-RevId label in the commit message.", defaultValue = "False", positional = false), @Param(name = "first_parent", defaultValue = "True", named = true, doc = "If true, it only uses the first parent when looking for changes. Note that" + " when disabled in ITERATIVE mode, it will try to do a migration for each" + " change of the merged branch.", positional = 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 = "state", defaultValue = "'OPEN'", named = true, positional = false, doc = "Only migrate Pull Request with that state." + " Possible values: `'OPEN'`, `'CLOSED'` or `'ALL'`. Default 'OPEN'"), @Param(name = "review_state", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "Required state of the reviews associated with the Pull Request" + " Possible values: `'HEAD_COMMIT_APPROVED'`, `'ANY_COMMIT_APPROVED'`," + " `'HAS_REVIEWERS'` or `'ANY'`. Default `None`. This field is required if" + " the user wants `" + GITHUB_PR_REVIEWER_APPROVER + "` and `" + GITHUB_PR_REVIEWER_OTHER + "` labels populated"), @Param(name = "review_approvers", allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "The set of reviewer types that are considered for approvals. In order to" + " have any effect, `review_state` needs to be set. " + GITHUB_PR_REVIEWER_APPROVER + "` will be populated for these types." + " See the valid types here:" + " https://developer.github.com/v4/enum/commentauthorassociation/"), @Param(name = "api_checker", allowedTypes = { @ParamType(type = Checker.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "A checker for the GitHub API endpoint provided for after_migration hooks. " + "This field is not required if the workflow hooks don't use the " + "origin/destination endpoints.", named = true, positional = false), @Param(name = PATCH_FIELD, allowedTypes = { @ParamType(type = Transformation.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = PATCH_FIELD_DESC), @Param(name = "branch", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, positional = false, defaultValue = "None", doc = "If set, it will only migrate pull requests for this base branch"), @Param(name = "describe_version", allowedTypes = { @ParamType(type = Boolean.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = DESCRIBE_VERSION_FIELD_DOC) }, useStarlarkThread = true)
@UsesFlags(GitHubPrOriginOptions.class)
@DocDefault(field = "review_approvers", value = "[\"COLLABORATOR\", \"MEMBER\", \"OWNER\"]")
public GitHubPrOrigin githubPrOrigin(String url, Boolean merge, // <String>
Sequence<?> requiredLabels, // <String>
Sequence<?> requiredStatusContextNames, // <String>
Sequence<?> requiredCheckRuns, // <String>
Sequence<?> retryableLabels, String submodules, Boolean baselineFromBranch, Boolean firstParent, Boolean partialClone, String state, Object reviewStateParam, Object reviewApproversParam, Object checkerObj, Object patch, Object branch, Object describeVersion, StarlarkThread thread) throws EvalException {
checkNotEmpty(url, "url");
check(GITHUB_COM.isGitHubUrl(url), "Invalid Github URL: %s", url);
PatchTransformation patchTransformation = maybeGetPatchTransformation(patch);
String reviewStateString = convertFromNoneable(reviewStateParam, null);
Sequence<String> reviewApproversStrings = convertFromNoneable(reviewApproversParam, null);
ReviewState reviewState;
ImmutableSet<AuthorAssociation> reviewApprovers;
if (reviewStateString == null) {
reviewState = null;
check(reviewApproversStrings == null, "'review_approvers' cannot be set if `review_state` is not set");
reviewApprovers = ImmutableSet.of();
} else {
reviewState = ReviewState.valueOf(reviewStateString);
if (reviewApproversStrings == null) {
reviewApproversStrings = StarlarkList.of(/*mutability=*/
null, "COLLABORATOR", "MEMBER", "OWNER");
}
HashSet<AuthorAssociation> approvers = new HashSet<>();
for (String r : reviewApproversStrings) {
boolean added = approvers.add(stringToEnum("review_approvers", r, AuthorAssociation.class));
check(added, "Repeated element %s", r);
}
reviewApprovers = ImmutableSet.copyOf(approvers);
}
GitHubPrOriginOptions prOpts = options.get(GitHubPrOriginOptions.class);
return new GitHubPrOrigin(fixHttp(url, thread.getCallerLocation()), prOpts.overrideMerge != null ? prOpts.overrideMerge : merge, options.get(GeneralOptions.class), options.get(GitOptions.class), options.get(GitOriginOptions.class), options.get(GitHubOptions.class), prOpts, ImmutableSet.copyOf(Sequence.cast(requiredLabels, String.class, GitHubUtil.REQUIRED_LABELS)), ImmutableSet.copyOf(Sequence.cast(requiredStatusContextNames, String.class, GitHubUtil.REQUIRED_STATUS_CONTEXT_NAMES)), ImmutableSet.copyOf(Sequence.cast(requiredCheckRuns, String.class, GitHubUtil.REQUIRED_CHECK_RUNS)), ImmutableSet.copyOf(Sequence.cast(retryableLabels, String.class, GitHubUtil.RETRYABLE_LABELS)), stringToEnum("submodules", submodules, SubmoduleStrategy.class), baselineFromBranch, firstParent, partialClone, stringToEnum("state", state, StateFilter.class), reviewState, reviewApprovers, convertFromNoneable(checkerObj, null), patchTransformation, convertFromNoneable(branch, null), convertDescribeVersion(describeVersion), GITHUB_COM);
}
Aggregations