Search in sources :

Example 6 with Checker

use of com.google.copybara.checks.Checker 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 7 with Checker

use of com.google.copybara.checks.Checker 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 8 with Checker

use of com.google.copybara.checks.Checker 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 9 with Checker

use of com.google.copybara.checks.Checker in project copybara by google.

the class GerritApiTransportWithCheckerTest method setup.

@Before
public void setup() throws Exception {
    console = new TestingConsole();
    delegate = Mockito.mock(GerritApiTransport.class);
    checker = Mockito.mock(Checker.class);
    transport = new GerritApiTransportWithChecker(delegate, new ApiChecker(checker, console));
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Checker(com.google.copybara.checks.Checker) ApiChecker(com.google.copybara.checks.ApiChecker) ApiChecker(com.google.copybara.checks.ApiChecker) Before(org.junit.Before)

Aggregations

Checker (com.google.copybara.checks.Checker)9 UsesFlags (com.google.copybara.doc.annotations.UsesFlags)8 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)8 GeneralOptions (com.google.copybara.GeneralOptions)3 DocDefault (com.google.copybara.doc.annotations.DocDefault)2 WorkflowOptions (com.google.copybara.WorkflowOptions)1 ApiChecker (com.google.copybara.checks.ApiChecker)1 Example (com.google.copybara.doc.annotations.Example)1 ChangeIdPolicy (com.google.copybara.git.GerritDestination.ChangeIdPolicy)1 NotifyOption (com.google.copybara.git.GerritDestination.NotifyOption)1 DefaultWriteHook (com.google.copybara.git.GitDestination.WriterImpl.DefaultWriteHook)1 GitHubEventType (com.google.copybara.git.github.api.GitHubEventType)1 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)1 LinkedHashSet (java.util.LinkedHashSet)1 Before (org.junit.Before)1