Skip to content

Commit

Permalink
feat(bitrise): Add commit_message and pull_request_id to bitrise payl…
Browse files Browse the repository at this point in the history
…oads
  • Loading branch information
hneiva committed May 8, 2024
1 parent 433edb7 commit 75b7eee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/mozilla_taskgraph/worker_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion test/test_worker_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"],
Expand All @@ -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": {
Expand All @@ -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"],
Expand All @@ -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": {
Expand All @@ -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"],
Expand All @@ -131,13 +145,17 @@
"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": {
"global_params": {
"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"],
Expand Down

0 comments on commit 75b7eee

Please sign in to comment.