Skip to content
Merged
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
16 changes: 12 additions & 4 deletions src/taskgraph/util/cached_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ def add_optimization(
# Pull requests use a different target cache index route. This way we can
# be confident they won't be used by anything other than the pull request
# that created the cache in the first place.
if config.params["tasks_for"] == "github-pull-request" and config.graph_config[
"taskgraph"
].get("cache-pull-requests", True):
#
# Comments on a pull request run against the PR's head, so they use the
# same cache namespace as the PR itself.
tasks_for = config.params["tasks_for"]
if tasks_for in (
"github-pull-request",
"github-issue-comment",
) and config.graph_config["taskgraph"].get("cache-pull-requests", True):
subs["head_ref"] = config.params["head_ref"]
if subs["head_ref"].startswith("refs/heads/"):
subs["head_ref"] = subs["head_ref"][11:]
Expand All @@ -76,7 +81,10 @@ def add_optimization(
# ... and cache at the lowest level.
subs["level"] = config.params["level"]

if config.params["tasks_for"].startswith("github-pull-request"):
if (
tasks_for.startswith("github-pull-request")
or tasks_for == "github-issue-comment"
):
if config.graph_config["taskgraph"].get("cache-pull-requests", True):
taskdesc.setdefault("routes", []).append(
f"index.{TARGET_PR_CACHE_INDEX.format(**subs)}"
Expand Down
15 changes: 15 additions & 0 deletions test/test_util_cached_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def assert_pull_request_nocache(task):
}


def assert_issue_comment(task):
assert_pull_request(task)


@pytest.mark.parametrize(
"extra_params,extra_graph_config,digest,digest_data",
(
Expand Down Expand Up @@ -176,6 +180,17 @@ def assert_pull_request_nocache(task):
None,
id="pull_request_nocache",
),
pytest.param(
# extra_params
{"tasks_for": "github-issue-comment"},
# extra_graph_config
None,
# digest
"abc",
# digest_data
None,
id="issue_comment",
),
),
)
def test_add_optimization(
Expand Down
Loading