use of com.google.copybara.transform.patch.PatchTransformation in project copybara by google.
the class GitHubPrOrigin method newReader.
@Override
public Reader<GitRevision> newReader(Glob originFiles, Authoring authoring) throws ValidationException {
return new ReaderImpl(url, originFiles, authoring, gitOptions, gitOriginOptions, generalOptions, /*includeBranchCommitLogs=*/
false, submoduleStrategy, firstParent, partialFetch, patchTransformation, describeVersion, /*configPath=*/
null, /*workflowName=*/
null) {
/**
* Disable rebase since this is controlled by useMerge field.
*/
@Override
protected void maybeRebase(GitRepository repo, GitRevision ref, Path workdir) throws RepoException, CannotResolveRevisionException {
}
@Override
public Optional<Baseline<GitRevision>> findBaseline(GitRevision startRevision, String label) throws RepoException, ValidationException {
if (!baselineFromBranch) {
return super.findBaseline(startRevision, label);
}
return findBaselinesWithoutLabel(startRevision, /*limit=*/
1).stream().map(e -> new Baseline<>(e.getSha1(), e)).findFirst();
}
@Override
public ImmutableList<GitRevision> findBaselinesWithoutLabel(GitRevision startRevision, int limit) throws RepoException, ValidationException {
String baseline = Iterables.getLast(startRevision.associatedLabels().get(GITHUB_BASE_BRANCH_SHA1), null);
checkNotNull(baseline, "%s label should be present in %s", GITHUB_BASE_BRANCH_SHA1, startRevision);
GitRevision baselineRev = getRepository().resolveReference(baseline);
// Don't skip the first change as it is already the baseline
BaselinesWithoutLabelVisitor<GitRevision> visitor = new BaselinesWithoutLabelVisitor<>(originFiles, limit, /*skipFirst=*/
false);
visitChanges(baselineRev, visitor);
return visitor.getResult();
}
@Override
public Endpoint getFeedbackEndPoint(Console console) throws ValidationException {
gitHubOptions.validateEndpointChecker(endpointChecker);
return new GitHubEndPoint(gitHubOptions.newGitHubApiSupplier(url, endpointChecker, ghHost), url, console, ghHost);
}
/**
* Deal with the case of useMerge. We have a new commit (the merge) and first-parent from that
* commit doesn't work for this case.
*/
@Override
public ChangesResponse<GitRevision> changes(@Nullable GitRevision fromRef, GitRevision toRef) throws RepoException, ValidationException {
checkCondition(toRef.associatedLabels().containsKey(GITHUB_PR_USE_MERGE), "Cannot determine whether 'use_merge' was set.");
if (toRef.associatedLabel(GITHUB_PR_USE_MERGE).contains("false")) {
return super.changes(fromRef, toRef);
}
GitLogEntry merge = Iterables.getOnlyElement(getRepository().log(toRef.getSha1()).withLimit(1).run());
// Fast-forward merge
if (merge.getParents().size() == 1) {
return super.changes(fromRef, toRef);
}
// HEAD of the Pull Request
GitRevision gitRevision = merge.getParents().get(1);
ChangesResponse<GitRevision> prChanges = super.changes(fromRef, gitRevision);
// origin_files
if (prChanges.isEmpty()) {
return prChanges;
}
try {
return ChangesResponse.forChanges(ImmutableList.<Change<GitRevision>>builder().addAll(prChanges.getChanges()).add(change(merge.getCommit())).build());
} catch (EmptyChangeException e) {
throw new RepoException("Error getting the merge commit information: " + merge, e);
}
}
};
}
use of com.google.copybara.transform.patch.PatchTransformation in project copybara by google.
the class GitModule method origin.
@SuppressWarnings("unused")
@StarlarkMethod(name = "origin", doc = "Defines a standard Git origin. For Git specific origins use: `github_origin` or " + "`gerrit_origin`.<br><br>All the origins in this module accept several string" + " formats as reference (When copybara is called in the form of `copybara config" + " workflow reference`):<br><ul><li>**Branch name:** For example" + " `master`</li><li>**An arbitrary reference:**" + " `refs/changes/20/50820/1`</li><li>**A SHA-1:** Note that it has to be reachable" + " from the default refspec</li><li>**A Git repository URL and reference:**" + " `http://github.com/foo master`</li><li>**A GitHub pull request URL:**" + " `https://github.com/some_project/pull/1784`</li></ul><br>So for example," + " Copybara can be invoked for a `git.origin` in the CLI as:<br>`copybara" + " copy.bara.sky my_workflow https://github.com/some_project/pull/1784`<br>This" + " will use the pull request as the origin URL and reference.", parameters = { @Param(name = "url", named = true, doc = "Indicates the URL of the git repository"), @Param(name = "ref", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, doc = "Represents the default reference that will be used for reading the revision " + "from the git repository. For example: 'master'"), @Param(name = "submodules", defaultValue = "'NO'", named = true, positional = false, doc = "Download submodules. Valid values: NO, YES, RECURSIVE."), @Param(name = "include_branch_commit_logs", defaultValue = "False", named = true, positional = false, doc = "Whether to include raw logs of branch commits in the migrated change message." + "WARNING: This field is deprecated in favor of 'first_parent' one." + " This setting *only* affects merge commits."), @Param(name = "first_parent", defaultValue = "True", named = true, positional = false, 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."), @Param(name = "partial_fetch", defaultValue = "False", named = true, positional = false, doc = "If true, partially fetch git repository by only fetching affected files."), @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 = "describe_version", allowedTypes = { @ParamType(type = Boolean.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = DESCRIBE_VERSION_FIELD_DOC), @Param(name = "version_selector", allowedTypes = { @ParamType(type = VersionSelector.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "Select a custom version (tag)to migrate" + " instead of 'ref'"), @Param(name = "primary_branch_migration", allowedTypes = { @ParamType(type = Boolean.class) }, defaultValue = "False", named = true, positional = false, doc = "When enabled, copybara will ignore the '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 'ref' param.\n" + "This is intended to help migrating to the new standard of using 'main' without " + "breaking users relying on the legacy default.") }, useStarlarkThread = true)
public GitOrigin origin(String url, Object ref, String submodules, Boolean includeBranchCommitLogs, Boolean firstParent, Boolean partialFetch, Object patch, Object describeVersion, Object versionSelector, Boolean primaryBranchMigration, StarlarkThread thread) throws EvalException {
checkNotEmpty(url, "url");
PatchTransformation patchTransformation = maybeGetPatchTransformation(patch);
if (versionSelector != Starlark.NONE) {
check(ref == Starlark.NONE, "Cannot use ref field and version_selector. Version selector will decide the ref" + " to migrate");
}
return GitOrigin.newGitOrigin(options, fixHttp(url, thread.getCallerLocation()), SkylarkUtil.convertOptionalString(ref), GitRepoType.GIT, stringToEnum("submodules", submodules, GitOrigin.SubmoduleStrategy.class), includeBranchCommitLogs, firstParent, partialFetch, primaryBranchMigration, patchTransformation, convertDescribeVersion(describeVersion), convertFromNoneable(versionSelector, null), mainConfigFile.path(), workflowName);
}
use of com.google.copybara.transform.patch.PatchTransformation 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);
}
use of com.google.copybara.transform.patch.PatchTransformation in project copybara by google.
the class GitModule method gerritOrigin.
@SuppressWarnings("unused")
@StarlarkMethod(name = "gerrit_origin", doc = "Defines a Git origin for Gerrit reviews.\n" + "\n" + "Implicit labels that can be used/exposed:\n" + "\n" + " - " + GerritChange.GERRIT_CHANGE_NUMBER_LABEL + ": The change number for the Gerrit review.\n" + " - " + GerritChange.GERRIT_CHANGE_ID_LABEL + ": The change id for the Gerrit review.\n" + " - " + GerritChange.GERRIT_CHANGE_DESCRIPTION_LABEL + ": The description of the Gerrit review.\n" + " - " + DEFAULT_INTEGRATE_LABEL + ": A label that when exposed, can be used to" + " integrate automatically in the reverse workflow.\n" + " - " + GerritChange.GERRIT_CHANGE_BRANCH + ": The destination branch for thechange\n" + " - " + GerritChange.GERRIT_CHANGE_TOPIC + ": The change topic\n" + " - " + GerritChange.GERRIT_COMPLETE_CHANGE_ID_LABEL + ": Complete Change-Id with project, branch and Change-Id\n" + " - " + GerritChange.GERRIT_OWNER_EMAIL_LABEL + ": Owner email\n" + " - GERRIT_REVIEWER_EMAIL: Multiple value field with the email of the reviewers\n" + " - GERRIT_CC_EMAIL: Multiple value field with the email of the people/groups in" + " cc\n", parameters = { @Param(name = "url", named = true, doc = "Indicates the URL of the git repository"), @Param(name = "ref", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, doc = "DEPRECATED. Use git.origin for submitted branches."), @Param(name = "submodules", defaultValue = "'NO'", named = true, doc = "Download submodules. Valid values: NO, YES, RECURSIVE."), @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 = "If true, partially fetch git repository by only fetching affected files.."), @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 = 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) }, defaultValue = "None", named = true, positional = false, doc = "Limit the import to" + " changes that are for this branch. By default imports everything."), @Param(name = "describe_version", allowedTypes = { @ParamType(type = Boolean.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = DESCRIBE_VERSION_FIELD_DOC), @Param(name = "ignore_gerrit_noop", defaultValue = "False", named = true, positional = false, doc = "Option to not migrate Gerrit changes that do not change origin_files"), @Param(name = "primary_branch_migration", allowedTypes = { @ParamType(type = Boolean.class) }, defaultValue = "False", named = true, positional = false, doc = "When enabled, copybara will ignore the '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 'ref' param.\n" + "This is intended to help migrating to the new standard of using 'main' without " + "breaking users relying on the legacy default.") }, useStarlarkThread = true)
public GitOrigin gerritOrigin(String url, Object ref, String submodules, Boolean firstParent, Boolean partialFetch, Object checkerObj, Object patch, Object branch, Object describeVersion, Boolean ignoreGerritNoop, Boolean primaryBranchMigration, StarlarkThread thread) throws EvalException {
checkNotEmpty(url, "url");
url = fixHttp(url, thread.getCallerLocation());
String refField = SkylarkUtil.convertOptionalString(ref);
PatchTransformation patchTransformation = maybeGetPatchTransformation(patch);
if (!Strings.isNullOrEmpty(refField)) {
getGeneralConsole().warn("'ref' field detected in configuration. git.gerrit_origin" + " is deprecating its usage for submitted changes. Use git.origin instead.");
return GitOrigin.newGitOrigin(options, url, refField, GitRepoType.GERRIT, stringToEnum("submodules", submodules, GitOrigin.SubmoduleStrategy.class), /*includeBranchCommitLogs=*/
false, firstParent, partialFetch, primaryBranchMigration, patchTransformation, convertDescribeVersion(describeVersion), /*versionSelector=*/
null, mainConfigFile.path(), workflowName);
}
return GerritOrigin.newGerritOrigin(options, url, stringToEnum("submodules", submodules, GitOrigin.SubmoduleStrategy.class), firstParent, partialFetch, convertFromNoneable(checkerObj, null), patchTransformation, convertFromNoneable(branch, null), convertDescribeVersion(describeVersion), ignoreGerritNoop, primaryBranchMigration);
}
use of com.google.copybara.transform.patch.PatchTransformation in project copybara by google.
the class GitModule method githubOrigin.
@SuppressWarnings("unused")
@StarlarkMethod(name = "github_origin", doc = "Defines a Git origin for a Github repository. This origin should be used for public" + " branches. Use " + GITHUB_PR_ORIGIN_NAME + " for importing Pull Requests.", parameters = { @Param(name = "url", named = true, doc = "Indicates the URL of the git repository"), @Param(name = "ref", allowedTypes = { @ParamType(type = String.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, doc = "Represents the default reference that will be used for reading the revision " + "from the git repository. For example: 'master'"), @Param(name = "submodules", defaultValue = "'NO'", named = true, doc = "Download submodules. Valid values: NO, YES, RECURSIVE."), @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 = "If true, partially fetch git repository by only fetching affected files."), @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 = "describe_version", allowedTypes = { @ParamType(type = Boolean.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = DESCRIBE_VERSION_FIELD_DOC), @Param(name = "version_selector", allowedTypes = { @ParamType(type = VersionSelector.class), @ParamType(type = NoneType.class) }, defaultValue = "None", named = true, positional = false, doc = "Select a custom version (tag)to migrate" + " instead of 'ref'"), @Param(name = "primary_branch_migration", allowedTypes = { @ParamType(type = Boolean.class) }, defaultValue = "False", named = true, positional = false, doc = "When enabled, copybara will ignore the '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 'ref' param.\n" + "This is intended to help migrating to the new standard of using 'main' without " + "breaking users relying on the legacy default.") }, useStarlarkThread = true)
public GitOrigin githubOrigin(String url, Object ref, String submodules, Boolean firstParent, Boolean partialFetch, Object patch, Object describeVersion, Object versionSelector, Boolean primaryBranchMigration, StarlarkThread thread) throws EvalException {
check(GITHUB_COM.isGitHubUrl(checkNotEmpty(url, "url")), "Invalid Github URL: %s", url);
if (versionSelector != Starlark.NONE) {
check(ref == Starlark.NONE, "Cannot use ref field and version_selector. Version selector will decide the ref" + " to migrate");
}
PatchTransformation patchTransformation = maybeGetPatchTransformation(patch);
// TODO(copybara-team): See if we want to support includeBranchCommitLogs for GitHub repos.
return GitOrigin.newGitOrigin(options, fixHttp(url, thread.getCallerLocation()), SkylarkUtil.convertOptionalString(ref), GitRepoType.GITHUB, stringToEnum("submodules", submodules, GitOrigin.SubmoduleStrategy.class), /*includeBranchCommitLogs=*/
false, firstParent, partialFetch, primaryBranchMigration, patchTransformation, convertDescribeVersion(describeVersion), convertFromNoneable(versionSelector, null), mainConfigFile.path(), workflowName);
}
Aggregations