diff --git a/src/mozilla_taskgraph/worker_types.py b/src/mozilla_taskgraph/worker_types.py index 3c6ba35..8084a05 100644 --- a/src/mozilla_taskgraph/worker_types.py +++ b/src/mozilla_taskgraph/worker_types.py @@ -80,24 +80,26 @@ def normref(ref, type="heads"): "branch_repo_owner": config.params["head_repository"], } - head_ref = normref(config.params["head_ref"]) - head_tag = normref(config.params["head_tag"], type="tags") - base_ref = normref(config.params["base_ref"]) - - if head_ref: + if head_ref := normref(config.params["head_ref"]): global_params["branch"] = head_ref - if head_tag: + if head_tag := normref(config.params["head_tag"], type="tags"): global_params["tag"] = head_tag + if commit_message := config.params.get("commit_message"): + global_params["commit_message"] = commit_message + + if pull_request_number := config.params.get("pull_request_number"): + global_params["pull_request_id"] = pull_request_number + if config.params["tasks_for"] == "github-pull-request": global_params["pull_request_author"] = config.params["owner"] - if base_ref: + if base_ref := normref(config.params["base_ref"]): global_params["branch_dest"] = base_ref - if config.params["base_repository"]: - global_params["branch_dest_repo_owner"] = config.params["base_repository"] + if base_repository := config.params["base_repository"]: + global_params["branch_dest_repo_owner"] = base_repository task_def["payload"] = {"global_params": global_params} if workflow_params: diff --git a/test/test_worker_types.py b/test/test_worker_types.py index 7fc3b1c..d7ce852 100644 --- a/test/test_worker_types.py +++ b/test/test_worker_types.py @@ -58,7 +58,11 @@ ), pytest.param( {"bitrise": {"app": "some-app", "workflows": ["bar"]}}, - {"tasks_for": "github-pull-request"}, + { + "tasks_for": "github-pull-request", + "commit_message": "This is a commit", + "pull_request_number": "123", + }, { "payload": { "global_params": { @@ -68,6 +72,8 @@ "branch_repo_owner": "http://example.com/head/repo", "commit_hash": "abcdef", "pull_request_author": "some-owner", + "commit_message": "This is a commit", + "pull_request_id": "123", }, }, "scopes": ["foo:bitrise:app:some-app", "foo:bitrise:workflow:bar"], @@ -83,6 +89,8 @@ "head_ref": "", "head_tag": "some-tag", "tasks_for": "github-pull-request", + "commit_message": "This is a commit", + "pull_request_number": "123", }, { "payload": { @@ -91,6 +99,8 @@ "commit_hash": "abcdef", "pull_request_author": "some-owner", "tag": "some-tag", + "commit_message": "This is a commit", + "pull_request_id": "123", } }, "scopes": ["foo:bitrise:app:some-app", "foo:bitrise:workflow:bar"], @@ -106,6 +116,8 @@ "head_ref": "refs/heads/bar", "head_tag": "refs/tags/some-tag", "tasks_for": "github-pull-request", + "commit_message": "This is a commit", + "pull_request_number": "123", }, { "payload": { @@ -116,6 +128,8 @@ "commit_hash": "abcdef", "pull_request_author": "some-owner", "tag": "some-tag", + "commit_message": "This is a commit", + "pull_request_id": "123", } }, "scopes": ["foo:bitrise:app:some-app", "foo:bitrise:workflow:bar"], @@ -131,6 +145,8 @@ "head_ref": "refs/tags/bar", "head_tag": "refs/heads/some-tag", "tasks_for": "github-pull-request", + "commit_message": "This is a commit", + "pull_request_number": "123", }, { "payload": { @@ -138,6 +154,8 @@ "branch_repo_owner": "http://example.com/head/repo", "commit_hash": "abcdef", "pull_request_author": "some-owner", + "commit_message": "This is a commit", + "pull_request_id": "123", } }, "scopes": ["foo:bitrise:app:some-app", "foo:bitrise:workflow:bar"],