Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/reference/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ base_rev
~~~~~~~~
The previous revision before ``head_rev`` got merged into. This can be a short revision string.

For a ``github-push`` of a branch and for ``github-pull-request``, the
:term:`Decision Task` replaces the reported base with the merge base of
``head_rev`` and the target branch, so ``files_changed`` covers only the
new commits. The target is ``base_ref`` for a pull request and the default
branch for a push. A push that only adds commits keeps its reported base,
and a force push to the default branch uses the merge base of its previous
and new tips. When no merge base can be found, the reported base is kept.

Set the ``GITHUB_TOKEN`` environment variable in the :term:`Decision Task`
to raise the rate limit of the GitHub API requests this makes.

head_rev
~~~~~~~~
The revision to check out, this can be a short revision string.
Expand Down
26 changes: 26 additions & 0 deletions src/taskgraph/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@ def taskgraph_decision(options, parameters=None):
)


def derive_base_rev(repo, parameters):
"""Return the base to use for a GitHub push or pull request, or ``None``
to keep ``parameters["base_rev"]`` as reported."""
tasks_for = parameters.get("tasks_for", "")
if tasks_for == "github-push":
# GitHub's event.before is not the base of a new or force pushed
# branch, see GitRepository.derive_base_rev.
return repo.derive_base_rev(
parameters["head_repository"],
parameters["head_rev"],
parameters["head_ref"],
parameters["base_rev"],
)
if tasks_for.startswith("github-pull-request"):
return repo.derive_pull_request_base_rev(
parameters["base_repository"],
parameters["head_rev"],
parameters.get("base_ref"),
)
return None


def get_decision_parameters(graph_config, options):
"""
Load parameters from the command-line options for 'taskgraph decision'.
Expand Down Expand Up @@ -188,6 +210,10 @@ def get_decision_parameters(graph_config, options):
except UnicodeDecodeError:
commit_message = ""

if base_rev := derive_base_rev(repo, parameters):
logger.info(f"Using {base_rev} as base_rev for {parameters['head_ref']}")
parameters["base_rev"] = base_rev

# Define default filter list, as most configurations shouldn't need
# custom filters.
parameters["files_changed"] = repo.get_changed_files(
Expand Down
Loading
Loading