Skip to content

Commit

Permalink
feat(tekton): more fork property support
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Gleeson <brian.gleeson@ie.ibm.com>
  • Loading branch information
briangleeson committed Oct 1, 2024
1 parent b23e2bc commit dbe2210
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ibm_continuous_delivery/cd_tekton_pipeline_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,7 @@ def create_tekton_pipeline_trigger(
events: List[str] = None,
filter: str = None,
favorite: bool = None,
enable_events_from_forks: bool = None,
**kwargs,
) -> DetailedResponse:
"""
Expand Down Expand Up @@ -1567,6 +1568,9 @@ def create_tekton_pipeline_trigger(
Stores the CEL (Common Expression Language) expression value which is used
for event filtering against the Git webhook payloads.
:param bool favorite: (optional) Mark the trigger as a favorite.
:param bool enable_events_from_forks: (optional) Only used for SCM
triggers. When enabled, pull request events from forks of the selected
repository will trigger a pipeline run.
:param dict headers: A `dict` containing the request headers
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
:rtype: DetailedResponse with `dict` result representing a `Trigger` object
Expand Down Expand Up @@ -1609,6 +1613,7 @@ def create_tekton_pipeline_trigger(
"events": events,
"filter": filter,
"favorite": favorite,
"enable_events_from_forks": enable_events_from_forks,
}
data = {k: v for (k, v) in data.items() if v is not None}
data = json.dumps(data)
Expand Down Expand Up @@ -4678,6 +4683,9 @@ class TriggerPatch:
CEL (Common Expression Language) expression value which is used for event
filtering against the Git webhook payloads.
:attr bool favorite: (optional) Mark the trigger as a favorite.
:attr bool enable_events_from_forks: (optional) Only used for SCM triggers. When
enabled, pull request events from forks of the selected repository will trigger
a pipeline run.
"""

def __init__(
Expand All @@ -4697,6 +4705,7 @@ def __init__(
events: List[str] = None,
filter: str = None,
favorite: bool = None,
enable_events_from_forks: bool = None,
) -> None:
"""
Initialize a TriggerPatch object.
Expand Down Expand Up @@ -4741,6 +4750,9 @@ def __init__(
Stores the CEL (Common Expression Language) expression value which is used
for event filtering against the Git webhook payloads.
:param bool favorite: (optional) Mark the trigger as a favorite.
:param bool enable_events_from_forks: (optional) Only used for SCM
triggers. When enabled, pull request events from forks of the selected
repository will trigger a pipeline run.
"""
self.type = type
self.name = name
Expand All @@ -4756,6 +4768,7 @@ def __init__(
self.events = events
self.filter = filter
self.favorite = favorite
self.enable_events_from_forks = enable_events_from_forks

@classmethod
def from_dict(cls, _dict: Dict) -> "TriggerPatch":
Expand Down Expand Up @@ -4789,6 +4802,8 @@ def from_dict(cls, _dict: Dict) -> "TriggerPatch":
args["filter"] = _dict.get("filter")
if "favorite" in _dict:
args["favorite"] = _dict.get("favorite")
if "enable_events_from_forks" in _dict:
args["enable_events_from_forks"] = _dict.get("enable_events_from_forks")
return cls(**args)

@classmethod
Expand Down Expand Up @@ -4836,6 +4851,8 @@ def to_dict(self) -> Dict:
_dict["filter"] = self.filter
if hasattr(self, "favorite") and self.favorite is not None:
_dict["favorite"] = self.favorite
if hasattr(self, "enable_events_from_forks") and self.enable_events_from_forks is not None:
_dict["enable_events_from_forks"] = self.enable_events_from_forks
return _dict

def _to_dict(self):
Expand Down
6 changes: 6 additions & 0 deletions test/unit/test_cd_tekton_pipeline_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2879,6 +2879,7 @@ def test_create_tekton_pipeline_trigger_all_params(self):
events = ["push"]
filter = "testString"
favorite = False
enable_events_from_forks = False

# Invoke method
response = _service.create_tekton_pipeline_trigger(
Expand All @@ -2897,6 +2898,7 @@ def test_create_tekton_pipeline_trigger_all_params(self):
events=events,
filter=filter,
favorite=favorite,
enable_events_from_forks=enable_events_from_forks,
headers={},
)

Expand All @@ -2919,6 +2921,7 @@ def test_create_tekton_pipeline_trigger_all_params(self):
assert req_body["events"] == ["push"]
assert req_body["filter"] == "testString"
assert req_body["favorite"] == False
assert req_body["enable_events_from_forks"] == False

def test_create_tekton_pipeline_trigger_all_params_with_retries(self):
# Enable retries and run test_create_tekton_pipeline_trigger_all_params.
Expand Down Expand Up @@ -2984,6 +2987,7 @@ def test_create_tekton_pipeline_trigger_value_error(self):
events = ["push"]
filter = "testString"
favorite = False
enable_events_from_forks = False

# Pass in all but one required param and check for a ValueError
req_param_dict = {
Expand Down Expand Up @@ -3158,6 +3162,7 @@ def test_update_tekton_pipeline_trigger_all_params(self):
trigger_patch_model["events"] = ["push", "pull_request"]
trigger_patch_model["filter"] = "header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'"
trigger_patch_model["favorite"] = False
trigger_patch_model["enable_events_from_forks"] = False

# Set up parameter values
pipeline_id = "94619026-912b-4d92-8f51-6c74f0692d90"
Expand Down Expand Up @@ -5191,6 +5196,7 @@ def test_trigger_patch_serialization(self):
trigger_patch_model_json["events"] = ["push", "pull_request"]
trigger_patch_model_json["filter"] = "header['x-github-event'] == 'push' && body.ref == 'refs/heads/main'"
trigger_patch_model_json["favorite"] = False
trigger_patch_model_json["enable_events_from_forks"] = False

# Construct a model instance of TriggerPatch by calling from_dict on the json representation
trigger_patch_model = TriggerPatch.from_dict(trigger_patch_model_json)
Expand Down

0 comments on commit dbe2210

Please sign in to comment.