Search in sources :

Example 1 with WorkflowOptions

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

the class GitModule method gitHubDestination.

@SuppressWarnings("unused")
@StarlarkMethod(name = "github_destination", doc = "Creates a commit in a GitHub repository branch (for example master). For creating Pull" + "Request use git.github_pr_destination.", parameters = { @Param(name = "url", named = true, doc = "Indicates the URL to push to as well as the URL from which to get the parent " + "commit"), @Param(name = "push", named = true, doc = "Reference to use for pushing the change, for example 'main'.", defaultValue = "'master'"), @Param(name = "fetch", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, doc = "Indicates the ref from which to get the parent commit. Defaults to push value" + " if None", defaultValue = "None"), @Param(name = "pr_branch_to_update", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, doc = "A template string that refers to a pull request branch in the same repository" + " will be updated to current commit of this push branch only if" + " pr_branch_to_update exists. The reason behind this field is that" + " presubmiting changes creates and leaves a pull request open. By using" + " this, we can automerge/close this type of pull requests. As a result," + " users will see this pr_branch_to_update as merged to this push branch." + " Usage: Users can use a string or a string with a label. For instance" + " ${label}_pr_branch_name. And the value of label must be in changes' label" + " list. Otherwise, nothing will happen.", defaultValue = "None"), @Param(name = "partial_fetch", defaultValue = "False", named = true, doc = "This is an experimental feature that only works for certain origin globs."), @Param(name = "delete_pr_branch", allowedTypes = { @ParamType(type = Boolean.class), @ParamType(type = NoneType.class) }, named = true, doc = "When `pr_branch_to_update` is enabled, it will delete the branch reference" + " after the push to the branch and main branch (i.e master) happens. This" + " allows to cleanup temporary branches created for testing.", defaultValue = "None"), @Param(name = "integrates", named = true, allowedTypes = { @ParamType(type = Sequence.class, generic1 = GitIntegrateChanges.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "Integrate changes from a url present in the migrated change" + " label. Defaults to a semi-fake merge if COPYBARA_INTEGRATE_REVIEW label is" + " present in the message", positional = false), @Param(name = "api_checker", allowedTypes = { @ParamType(type = Checker.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "A checker for the Gerrit 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 = "primary_branch_migration", allowedTypes = { @ParamType(type = Boolean.class) }, defaultValue = "False", named = true, positional = false, doc = "When enabled, copybara will ignore the 'push' and 'fetch' params if either is" + " 'master' or 'main' and instead try to establish the default git branch. If" + " this fails, it will fall back to the param's declared value.\n" + "This is intended to help migrating to the new standard of using 'main'" + " without breaking users relying on the legacy default."), @Param(name = "tag_name", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, positional = false, doc = "A template string that specifies to a tag name. If the tag already exists, " + "copybara will only overwrite it if the --git-tag-overwrite flag is set." + "\nNote that tag creation is " + "best-effort and the migration will succeed even if the tag cannot be " + "created. " + "Usage: Users can use a string or a string with a label. " + "For instance ${label}_tag_name. And the value of label must be " + "in changes' label list. Otherwise, tag won't be created.", defaultValue = "None"), @Param(name = "tag_msg", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, positional = false, doc = "A template string that refers to the commit msg for a tag. If set, copybara will" + "create an annotated tag with this custom message\n" + "Usage: Labels in the string will be resolved. E.g. .${label}_message." + "By default, the tag will be created with the labeled commit's message.", defaultValue = "None"), @Param(name = "checker", allowedTypes = { @ParamType(type = Checker.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "A checker that validates the commit files & message. If `api_checker` is not" + " set, it will also be used for checking API calls. If only `api_checker`" + "is used, that checker will only apply to API calls.", named = true, positional = false) }, useStarlarkThread = true)
@UsesFlags(GitDestinationOptions.class)
// Used to detect in the future users that don't set it and change the default
@DocDefault(field = "delete_pr_branch", value = "False")
public GitDestination gitHubDestination(String url, String push, Object fetch, Object prBranchToUpdate, Boolean partialFetch, Object deletePrBranchParam, Object integrates, Object apiChecker, Boolean primaryBranchMigration, Object tagName, Object tagMsg, Object checker, StarlarkThread thread) throws EvalException {
    GitDestinationOptions destinationOptions = options.get(GitDestinationOptions.class);
    String resolvedPush = checkNotEmpty(firstNotNull(destinationOptions.push, push), "push");
    GeneralOptions generalOptions = options.get(GeneralOptions.class);
    String repoUrl = fixHttp(checkNotEmpty(firstNotNull(destinationOptions.url, url), "url"), thread.getCallerLocation());
    String branchToUpdate = convertFromNoneable(prBranchToUpdate, null);
    Boolean deletePrBranch = convertFromNoneable(deletePrBranchParam, null);
    check(branchToUpdate != null || deletePrBranch == null, "'delete_pr_branch' can only be set if 'pr_branch_to_update' is used");
    GitHubOptions gitHubOptions = options.get(GitHubOptions.class);
    WorkflowOptions workflowOptions = options.get(WorkflowOptions.class);
    String effectivePrBranchToUpdate = branchToUpdate;
    if (options.get(WorkflowOptions.class).isInitHistory()) {
        generalOptions.console().infoFmt("Ignoring field 'pr_branch_to_update' as '--init-history' is set.");
        effectivePrBranchToUpdate = null;
    }
    // First flag has priority, then field, and then (for now) we set it to false.
    // TODO(malcon): Once this is stable the default will be 'branchToUpdate != null'
    boolean effectiveDeletePrBranch = gitHubOptions.gitHubDeletePrBranch != null ? gitHubOptions.gitHubDeletePrBranch : deletePrBranch != null ? deletePrBranch : false;
    Checker apiCheckerObj = convertFromNoneable(apiChecker, null);
    Checker checkerObj = convertFromNoneable(checker, null);
    return new GitDestination(repoUrl, checkNotEmpty(firstNotNull(destinationOptions.fetch, convertFromNoneable(fetch, null), resolvedPush), "fetch"), resolvedPush, partialFetch, primaryBranchMigration, convertFromNoneable(tagName, null), convertFromNoneable(tagMsg, null), destinationOptions, options.get(GitOptions.class), generalOptions, new GitHubWriteHook(generalOptions, repoUrl, gitHubOptions, effectivePrBranchToUpdate, effectiveDeletePrBranch, getGeneralConsole(), apiCheckerObj != null ? apiCheckerObj : checkerObj, GITHUB_COM), Starlark.isNullOrNone(integrates) ? defaultGitIntegrate : Sequence.cast(integrates, GitIntegrateChanges.class, "integrates"), checkerObj);
}
Also used : GeneralOptions(com.google.copybara.GeneralOptions) Checker(com.google.copybara.checks.Checker) WorkflowOptions(com.google.copybara.WorkflowOptions) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) UsesFlags(com.google.copybara.doc.annotations.UsesFlags) DocDefault(com.google.copybara.doc.annotations.DocDefault)

Aggregations

GeneralOptions (com.google.copybara.GeneralOptions)1 WorkflowOptions (com.google.copybara.WorkflowOptions)1 Checker (com.google.copybara.checks.Checker)1 DocDefault (com.google.copybara.doc.annotations.DocDefault)1 UsesFlags (com.google.copybara.doc.annotations.UsesFlags)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1