Search in sources :

Example 11 with UsesFlags

use of com.google.copybara.doc.annotations.UsesFlags 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)

Example 12 with UsesFlags

use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.

the class GitModule method gerritDestination.

@SuppressWarnings("unused")
@StarlarkMethod(name = "gerrit_destination", doc = "Creates a change in Gerrit using the transformed worktree. If this is used in iterative" + " mode, then each commit pushed in a single Copybara invocation will have the" + " correct commit parent. The reviews generated can then be easily done in the" + " correct order without rebasing.", 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 = "fetch", named = true, doc = "Indicates the ref from which to get the parent commit"), @Param(name = "push_to_refs_for", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, doc = "Review branch to push the change to, for example setting this to 'feature_x'" + " causes the destination to push to 'refs/for/feature_x'. It defaults to " + "'fetch' value."), @Param(name = "submit", named = true, doc = "If true, skip the push thru Gerrit refs/for/branch and directly push to branch." + " This is effectively a git.destination that sets a Change-Id", defaultValue = "False"), @Param(name = "partial_fetch", defaultValue = "False", named = true, doc = "This is an experimental feature that only works for certain origin globs."), @Param(name = "notify", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, doc = "" + "Type of Gerrit notify option (https://gerrit-review.googlesource.com/Docum" + "entation/user-upload.html#notify). Sends notifications by default.", defaultValue = "None"), @Param(name = "change_id_policy", defaultValue = "'FAIL_IF_PRESENT'", named = true, doc = "What to do in the presence or absent of Change-Id in message:" + "<ul>" + "  <li>`'REQUIRE'`: Require that the change_id is present in the message as a" + " valid label</li>" + "  <li>`'FAIL_IF_PRESENT'`: Fail if found in message</li>" + "  <li>`'REUSE'`: Reuse if present. Otherwise generate a new one</li>" + "  <li>`'REPLACE'`: Replace with a new one if found</li>" + "</ul>"), @Param(name = "allow_empty_diff_patchset", named = true, doc = "By default Copybara will upload a new PatchSet to Gerrit without checking the" + " previous one. If this set to false, Copybara will download current PatchSet" + " and check the diff against the new diff.", defaultValue = "True"), @Param(name = "reviewers", named = true, defaultValue = "[]", doc = "The list of the reviewers will be added to gerrit change reviewer listThe element" + " in the list is: an email, for example: \"foo@example.com\" or label for" + " example: ${SOME_GERRIT_REVIEWER}. These are under the condition of" + " assuming that users have registered to gerrit repos"), @Param(name = "cc", named = true, defaultValue = "[]", doc = "The list of the email addresses or users that will be CCed in the review. Can" + " use labels as the `reviewers` field."), @Param(name = "labels", named = true, defaultValue = "[]", doc = "The list of labels to be pushed with the change. The format is the label " + "along with the associated value. For example: Run-Presubmit+1"), @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 = "integrates", allowedTypes = { @ParamType(type = Sequence.class, generic1 = GitIntegrateChanges.class), @ParamType(type = NoneType.class) }, named = true, 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 = "topic", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "" + "Sets the topic of the Gerrit change created.<br><br>" + "By default it sets no topic. This field accepts a template with labels. " + "For example: `\"topic_${CONTEXT_REFERENCE}\"`"), @Param(name = "gerrit_submit", defaultValue = "False", named = true, positional = false, doc = "By default, Copybara uses git commit/push to the main branch when submit = True." + "  If this flag is enabled, it will update the Gerrit change with the " + "latest commit and submit using Gerrit."), @Param(name = "primary_branch_migration", allowedTypes = { @ParamType(type = Boolean.class) }, defaultValue = "False", named = true, positional = false, doc = "When enabled, copybara will ignore the 'push_to_refs_for' 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 = "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)
@DocDefault(field = "push_to_refs_for", value = "fetch value")
public GerritDestination gerritDestination(String url, String fetch, Object pushToRefsFor, Boolean submit, Boolean partialFetch, Object notifyOptionObj, String changeIdPolicy, Boolean allowEmptyPatchSet, // <String>
Sequence<?> reviewers, // <String>
Sequence<?> ccParam, // <String>
Sequence<?> labelsParam, Object apiChecker, Object integrates, Object topicObj, Boolean gerritSubmit, Boolean primaryBranchMigrationMode, Object checker, StarlarkThread thread) throws EvalException {
    checkNotEmpty(url, "url");
    if (gerritSubmit) {
        Preconditions.checkArgument(submit, "Only set gerrit_submit if submit is true");
    }
    List<String> newReviewers = SkylarkUtil.convertStringList(reviewers, "reviewers");
    List<String> cc = SkylarkUtil.convertStringList(ccParam, "cc");
    List<String> labels = SkylarkUtil.convertStringList(labelsParam, "labels");
    String notifyOptionStr = convertFromNoneable(notifyOptionObj, null);
    check(!(submit && notifyOptionStr != null), "Cannot set 'notify' with 'submit = True' in git.gerrit_destination().");
    String topicStr = convertFromNoneable(topicObj, null);
    check(!(submit && topicStr != null), "Cannot set 'topic' with 'submit = True' in git.gerrit_destination().");
    NotifyOption notifyOption = notifyOptionStr == null ? null : stringToEnum("notify", notifyOptionStr, NotifyOption.class);
    Checker apiCheckerObj = convertFromNoneable(apiChecker, null);
    Checker checkerObj = convertFromNoneable(checker, null);
    return GerritDestination.newGerritDestination(options, fixHttp(url, thread.getCallerLocation()), checkNotEmpty(firstNotNull(options.get(GitDestinationOptions.class).fetch, fetch), "fetch"), checkNotEmpty(firstNotNull(convertFromNoneable(pushToRefsFor, null), options.get(GitDestinationOptions.class).fetch, fetch), "push_to_refs_for"), submit, partialFetch, notifyOption, stringToEnum("change_id_policy", changeIdPolicy, ChangeIdPolicy.class), allowEmptyPatchSet, newReviewers, cc, labels, apiCheckerObj != null ? apiCheckerObj : checkerObj, Starlark.isNullOrNone(integrates) ? defaultGitIntegrate : Sequence.cast(integrates, GitIntegrateChanges.class, "integrates"), topicStr, gerritSubmit, primaryBranchMigrationMode, checkerObj);
}
Also used : NotifyOption(com.google.copybara.git.GerritDestination.NotifyOption) Checker(com.google.copybara.checks.Checker) ChangeIdPolicy(com.google.copybara.git.GerritDestination.ChangeIdPolicy) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) UsesFlags(com.google.copybara.doc.annotations.UsesFlags) DocDefault(com.google.copybara.doc.annotations.DocDefault)

Example 13 with UsesFlags

use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.

the class GitModule method gerritApi.

@SuppressWarnings("unused")
@StarlarkMethod(name = GERRIT_API, doc = "" + "Defines a feedback API endpoint for Gerrit, that exposes relevant Gerrit API " + "operations.", parameters = { @Param(name = "url", doc = "Indicates the Gerrit repo URL.", named = true), @Param(name = "checker", allowedTypes = { @ParamType(type = Checker.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "A checker for the Gerrit API transport.", named = true) }, useStarlarkThread = true)
@UsesFlags(GerritOptions.class)
public EndpointProvider<GerritEndpoint> gerritApi(String url, Object checkerObj, StarlarkThread thread) throws EvalException {
    checkNotEmpty(url, "url");
    String cleanedUrl = fixHttp(url, thread.getCallerLocation());
    Checker checker = convertFromNoneable(checkerObj, null);
    validateEndpointChecker(checker, GERRIT_API);
    GerritOptions gerritOptions = options.get(GerritOptions.class);
    return EndpointProvider.wrap(new GerritEndpoint(gerritOptions.newGerritApiSupplier(cleanedUrl, checker), cleanedUrl, getGeneralConsole()));
}
Also used : Checker(com.google.copybara.checks.Checker) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) UsesFlags(com.google.copybara.doc.annotations.UsesFlags)

Example 14 with UsesFlags

use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.

the class GitModule method gitHubTrigger.

@SuppressWarnings("unused")
@StarlarkMethod(name = GITHUB_TRIGGER, doc = "Defines a feedback trigger based on updates on a GitHub PR.", parameters = { @Param(name = "url", doc = "Indicates the GitHub repo URL.", named = true), @Param(name = "checker", allowedTypes = { @ParamType(type = Checker.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "A checker for the GitHub API transport provided by this trigger.", named = true), @Param(name = "events", allowedTypes = { @ParamType(type = Sequence.class, generic1 = String.class), @ParamType(type = Dict.class, generic1 = Sequence.class) }, named = true, defaultValue = "[]", doc = "Type of events to subscribe. Valid values are: `'ISSUES'`, `'ISSUE_COMMENT'`," + " `'PULL_REQUEST'`,  `'PULL_REQUEST_REVIEW_COMMENT'`, `'PUSH'`," + " `'STATUS'`, `'CHECK_RUNS'`") }, useStarlarkThread = true)
@UsesFlags(GitHubOptions.class)
public GitHubTrigger gitHubTrigger(String url, Object checkerObj, Object events, StarlarkThread thread) throws EvalException {
    checkNotEmpty(url, "url");
    url = fixHttp(url, thread.getCallerLocation());
    Checker checker = convertFromNoneable(checkerObj, null);
    LinkedHashSet<EventTrigger> eventBuilder = new LinkedHashSet<>();
    LinkedHashSet<GitHubEventType> types = new LinkedHashSet<>();
    ImmutableSet<EventTrigger> parsedEvents = handleEventTypes(events, eventBuilder, types);
    validateEndpointChecker(checker, GITHUB_TRIGGER);
    GitHubOptions gitHubOptions = options.get(GitHubOptions.class);
    return new GitHubTrigger(gitHubOptions.newGitHubApiSupplier(url, checker, GITHUB_COM), url, parsedEvents, getGeneralConsole(), GITHUB_COM);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Checker(com.google.copybara.checks.Checker) GitHubEventType(com.google.copybara.git.github.api.GitHubEventType) StarlarkMethod(net.starlark.java.annot.StarlarkMethod) UsesFlags(com.google.copybara.doc.annotations.UsesFlags)

Example 15 with UsesFlags

use of com.google.copybara.doc.annotations.UsesFlags 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

UsesFlags (com.google.copybara.doc.annotations.UsesFlags)17 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)16 Checker (com.google.copybara.checks.Checker)8 GeneralOptions (com.google.copybara.GeneralOptions)7 DocDefault (com.google.copybara.doc.annotations.DocDefault)5 LabelsAwareModule (com.google.copybara.config.LabelsAwareModule)3 Example (com.google.copybara.doc.annotations.Example)3 Module (net.starlark.java.eval.Module)3 Action (com.google.copybara.action.Action)2 StarlarkAction (com.google.copybara.action.StarlarkAction)2 FolderModule (com.google.copybara.folder.FolderModule)2 LinkedHashSet (java.util.LinkedHashSet)2 Parameter (com.beust.jcommander.Parameter)1 ImmutableList (com.google.common.collect.ImmutableList)1 WorkflowOptions (com.google.copybara.WorkflowOptions)1 Author (com.google.copybara.authoring.Author)1 Authoring (com.google.copybara.authoring.Authoring)1 ConfigFile (com.google.copybara.config.ConfigFile)1 DocElement (com.google.copybara.doc.annotations.DocElement)1 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)1