use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.
the class GitModule method gerritTrigger.
@SuppressWarnings("unused")
@StarlarkMethod(name = GERRIT_TRIGGER, doc = "Defines a feedback trigger based on updates on a Gerrit change.", 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 provided by this trigger.", named = true) }, useStarlarkThread = true)
@UsesFlags(GerritOptions.class)
public GerritTrigger gerritTrigger(String url, Object checkerObj, StarlarkThread thread) throws EvalException {
checkNotEmpty(url, "url");
url = fixHttp(url, thread.getCallerLocation());
Checker checker = convertFromNoneable(checkerObj, null);
validateEndpointChecker(checker, GERRIT_TRIGGER);
GerritOptions gerritOptions = options.get(GerritOptions.class);
return new GerritTrigger(gerritOptions.newGerritApiSupplier(url, checker), url, getGeneralConsole());
}
use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.
the class GitModule method githubPrDestination.
@SuppressWarnings("unused")
@StarlarkMethod(name = "github_pr_destination", doc = "Creates changes in a new pull request in the destination.", parameters = { @Param(name = "url", named = true, doc = "Url of the GitHub project. For example" + " \"https://github.com/google/copybara'\""), @Param(name = "destination_ref", named = true, doc = "Destination reference for the change.", defaultValue = "'master'"), @Param(name = "pr_branch", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "Customize the pull request branch. Any variable present in the message in the " + "form of ${CONTEXT_REFERENCE} will be replaced by the corresponding stable " + "reference (head, PR number, Gerrit change number, etc.)."), @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 = "allow_empty_diff", defaultValue = "True", named = true, positional = false, doc = "By default, copybara migrates changes without checking existing PRs. " + "If set, copybara will skip pushing a change to an existing PR " + "only if the git three of the pending migrating change is the same " + "as the existing PR."), @Param(name = "title", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "When creating (or updating if `update_description` is set) a pull request, use" + " this title. By default it uses the change first line. This field accepts" + " a template with labels. For example: `\"Change ${CONTEXT_REFERENCE}\"`"), @Param(name = "body", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "When creating (or updating if `update_description` is set) a pull request, use" + " this body. By default it uses the change summary. This field accepts" + " a template with labels. For example: `\"Change ${CONTEXT_REFERENCE}\"`"), @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 = "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 = "update_description", defaultValue = "False", named = true, positional = false, doc = "By default, Copybara only set the title and body of the PR when creating" + " the PR. If this field is set to true, it will update those fields for" + " every update."), @Param(name = "primary_branch_migration", defaultValue = "False", named = true, positional = false, doc = "When enabled, copybara will ignore the 'desination_ref' param if it 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, GitHubDestinationOptions.class })
@Example(title = "Common usage", before = "Create a branch by using copybara's computerIdentity algorithm:", code = "git.github_pr_destination(\n" + " url = \"https://github.com/google/copybara\",\n" + " destination_ref = \"master\",\n" + " )")
@Example(title = "Using pr_branch with label", before = "Customize pr_branch with context reference:", code = "git.github_pr_destination(\n" + " url = \"https://github.com/google/copybara\",\n" + " destination_ref = \"master\",\n" + " pr_branch = 'test_${CONTEXT_REFERENCE}',\n" + " )")
@Example(title = "Using pr_branch with constant string", before = "Customize pr_branch with a constant string:", code = "git.github_pr_destination(\n" + " url = \"https://github.com/google/copybara\",\n" + " destination_ref = \"master\",\n" + " pr_branch = 'test_my_branch',\n" + " )")
public GitHubPrDestination githubPrDestination(String url, String destinationRef, Object prBranch, Boolean partialFetch, Boolean allowEmptyDiff, Object title, Object body, Object integrates, Object apiChecker, Boolean updateDescription, Boolean primaryBranchMigrationMode, Object checker, StarlarkThread thread) throws EvalException {
GeneralOptions generalOptions = options.get(GeneralOptions.class);
// This restricts to github.com, we will have to revisit this to support setups like GitHub
// Enterprise.
check(GITHUB_COM.isGitHubUrl(url), "'%s' is not a valid GitHub url", url);
GitDestinationOptions destinationOptions = options.get(GitDestinationOptions.class);
GitHubOptions gitHubOptions = options.get(GitHubOptions.class);
String destinationPrBranch = convertFromNoneable(prBranch, null);
Checker apiCheckerObj = convertFromNoneable(apiChecker, null);
Checker checkerObj = convertFromNoneable(checker, null);
return new GitHubPrDestination(fixHttp(checkNotEmpty(firstNotNull(destinationOptions.url, url), "url"), thread.getCallerLocation()), destinationRef, convertFromNoneable(prBranch, null), partialFetch, generalOptions, options.get(GitHubOptions.class), destinationOptions, options.get(GitHubDestinationOptions.class), options.get(GitOptions.class), new GitHubPrWriteHook(generalOptions, url, gitHubOptions, destinationPrBranch, partialFetch, allowEmptyDiff, getGeneralConsole(), GITHUB_COM), Starlark.isNullOrNone(integrates) ? defaultGitIntegrate : Sequence.cast(integrates, GitIntegrateChanges.class, "integrates"), convertFromNoneable(title, null), convertFromNoneable(body, null), mainConfigFile, apiCheckerObj != null ? apiCheckerObj : checkerObj, updateDescription, GITHUB_COM, primaryBranchMigrationMode, checkerObj);
}
use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.
the class GitModule method destination.
@SuppressWarnings("unused")
@StarlarkMethod(name = "destination", doc = "Creates a commit in a git repository using the transformed worktree.<br><br>For" + " GitHub use git.github_destination. For creating Pull Requests in GitHub, use" + " git.github_pr_destination. For creating a Gerrit change use" + " git.gerrit_destination.<br><br>Given that Copybara doesn't ask" + " for user/password in the console when doing the push to remote repos, you have to" + " use ssh protocol, have the credentials cached or use a credential manager.", 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 = "tag_name", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, named = true, doc = "A template string that refers to a tag name. If tag_name exists, overwrite " + "this tag only if flag git-tag-overwrite is set. Note that tag creation is " + "best-effort and 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, doc = "A template string that refers to the commit msg of a tag. If set, we will " + "create an annotated tag when tag_name is set. Usage: Users can use a string " + "or a string with a label. For instance ${label}_message. And the value of " + "label must be in changes' label list. Otherwise, tag will be created with " + "sha1's commit msg.", defaultValue = "None"), @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 = "partial_fetch", defaultValue = "False", named = true, positional = false, doc = "This is an experimental feature that only works for certain origin globs."), @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 = "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 = "checker", allowedTypes = { @ParamType(type = Checker.class), @ParamType(type = NoneType.class) }, defaultValue = "None", doc = "A checker that can check leaks or other checks in the commit created. ", named = true, positional = false) }, useStarlarkThread = true)
@UsesFlags(GitDestinationOptions.class)
public GitDestination destination(String url, String push, Object tagName, Object tagMsg, Object fetch, boolean partialFetch, Object integrates, Boolean primaryBranchMigration, 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);
Checker maybeChecker = convertFromNoneable(checker, null);
if (maybeChecker != null && options.get(GitDestinationOptions.class).skipGitChecker) {
maybeChecker = null;
getGeneralConsole().warn("Skipping git checker for git.destination. Note that this could" + " cause leaks or other problems");
}
return new GitDestination(fixHttp(checkNotEmpty(firstNotNull(destinationOptions.url, url), "url"), thread.getCallerLocation()), 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 DefaultWriteHook(), Starlark.isNullOrNone(integrates) ? defaultGitIntegrate : Sequence.cast(integrates, GitIntegrateChanges.class, "integrates"), maybeChecker);
}
use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.
the class GitModule method githubApi.
@SuppressWarnings("unused")
@StarlarkMethod(name = GITHUB_API, doc = "Defines a feedback API endpoint for GitHub, that exposes relevant GitHub API" + " operations.", 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.", named = true) }, useStarlarkThread = true)
@UsesFlags(GitHubOptions.class)
public EndpointProvider<GitHubEndPoint> githubApi(String url, Object checkerObj, StarlarkThread thread) throws EvalException {
checkNotEmpty(url, "url");
String cleanedUrl = fixHttp(url, thread.getCallerLocation());
Checker checker = convertFromNoneable(checkerObj, null);
validateEndpointChecker(checker, GITHUB_API);
GitHubOptions gitHubOptions = options.get(GitHubOptions.class);
return EndpointProvider.wrap(new GitHubEndPoint(gitHubOptions.newGitHubApiSupplier(cleanedUrl, checker, GITHUB_COM), cleanedUrl, getGeneralConsole(), GITHUB_COM));
}
use of com.google.copybara.doc.annotations.UsesFlags in project copybara by google.
the class RemoteFileModule method gitHubTarball.
@SuppressWarnings("unused")
@StarlarkMethod(name = "github_archive", doc = "A tarball for a specific SHA1 on GitHub. Experimental.", documented = false, parameters = { @Param(name = "project", named = true, defaultValue = "[]", doc = "The GitHub project from which to load the file, e.g. google/copybara"), @Param(name = "revision", named = true, defaultValue = "[]", doc = "The revision to download from the project, typically a commit SHA1."), @Param(name = "type", named = true, defaultValue = "'TARBALL'", doc = "Archive type to download, options are 'TARBALL' or 'ZIP'.") })
@UsesFlags(RemoteFileOptions.class)
public GithubArchive gitHubTarball(String project, String revision, String type) throws EvalException {
GeneralOptions generalOptions = options.get(GeneralOptions.class);
RemoteFileOptions remoteFileOptions = options.get(RemoteFileOptions.class);
try {
return new GithubArchive(project, revision, Enums.getIfPresent(GithubArchive.Type.class, type).toJavaUtil().orElseThrow(() -> errorf("Unsupported archive type: '%s'. " + "Supported values: %s", type, Arrays.asList(GithubArchive.Type.values()))), remoteFileOptions.getTransport(), generalOptions.profiler(), generalOptions.console());
} catch (ValidationException e) {
throw Starlark.errorf("Error setting up remote http file: %s", e.getMessage());
}
}
Aggregations