From 4b8faad30bad787e3d5af4dc8bc5d5cd683c554e Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 11 Jan 2021 13:07:20 -0800 Subject: [PATCH] promote github fields to GA (#4373) (#362) Co-authored-by: upodroid Signed-off-by: Modular Magician Co-authored-by: upodroid --- plugins/modules/gcp_cloudbuild_trigger.py | 212 ++++++++++++++++++ .../modules/gcp_cloudbuild_trigger_info.py | 65 ++++++ 2 files changed, 277 insertions(+) diff --git a/plugins/modules/gcp_cloudbuild_trigger.py b/plugins/modules/gcp_cloudbuild_trigger.py index 34d333f..a99b770 100644 --- a/plugins/modules/gcp_cloudbuild_trigger.py +++ b/plugins/modules/gcp_cloudbuild_trigger.py @@ -162,6 +162,73 @@ options: SHA must be provided. required: false type: str + github: + description: + - Describes the configuration of a trigger that creates a build whenever a GitHub + event is received. + required: false + type: dict + suboptions: + owner: + description: + - 'Owner of the repository. For example: The owner for U(https://github.com/googlecloudplatform/cloud-builders) + is "googlecloudplatform".' + required: false + type: str + name: + description: + - 'Name of the repository. For example: The name for U(https://github.com/googlecloudplatform/cloud-builders) + is "cloud-builders".' + required: false + type: str + pull_request: + description: + - filter to match changes in pull requests. Specify only one of pullRequest + or push. + required: false + type: dict + suboptions: + branch: + description: + - Regex of branches to match. + required: true + type: str + comment_control: + description: + - Whether to block builds on a "/gcbrun" comment from a repository owner + or collaborator. + - 'Some valid choices include: "COMMENTS_DISABLED", "COMMENTS_ENABLED", + "COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY"' + required: false + type: str + invert_regex: + description: + - If true, branches that do NOT match the git_ref will trigger a build. + required: false + type: bool + push: + description: + - filter to match changes in refs, like branches or tags. Specify only one + of pullRequest or push. + required: false + type: dict + suboptions: + invert_regex: + description: + - When true, only trigger a build if the revision regex does NOT match + the git_ref regex. + required: false + type: bool + branch: + description: + - Regex of branches to match. Specify only one of branch or tag. + required: false + type: str + tag: + description: + - Regex of tags to match. Specify only one of branch or tag. + required: false + type: str build: description: - Contents of the build template. Either a filename or build template must be @@ -811,6 +878,71 @@ triggerTemplate: SHA must be provided. returned: success type: str +github: + description: + - Describes the configuration of a trigger that creates a build whenever a GitHub + event is received. + returned: success + type: complex + contains: + owner: + description: + - 'Owner of the repository. For example: The owner for U(https://github.com/googlecloudplatform/cloud-builders) + is "googlecloudplatform".' + returned: success + type: str + name: + description: + - 'Name of the repository. For example: The name for U(https://github.com/googlecloudplatform/cloud-builders) + is "cloud-builders".' + returned: success + type: str + pullRequest: + description: + - filter to match changes in pull requests. Specify only one of pullRequest + or push. + returned: success + type: complex + contains: + branch: + description: + - Regex of branches to match. + returned: success + type: str + commentControl: + description: + - Whether to block builds on a "/gcbrun" comment from a repository owner + or collaborator. + returned: success + type: str + invertRegex: + description: + - If true, branches that do NOT match the git_ref will trigger a build. + returned: success + type: bool + push: + description: + - filter to match changes in refs, like branches or tags. Specify only one of + pullRequest or push. + returned: success + type: complex + contains: + invertRegex: + description: + - When true, only trigger a build if the revision regex does NOT match the + git_ref regex. + returned: success + type: bool + branch: + description: + - Regex of branches to match. Specify only one of branch or tag. + returned: success + type: str + tag: + description: + - Regex of tags to match. Specify only one of branch or tag. + returned: success + type: str build: description: - Contents of the build template. Either a filename or build template must be provided. @@ -1308,6 +1440,17 @@ def main(): commit_sha=dict(type='str'), ), ), + github=dict( + type='dict', + options=dict( + owner=dict(type='str'), + name=dict(type='str'), + pull_request=dict( + type='dict', options=dict(branch=dict(required=True, type='str'), comment_control=dict(type='str'), invert_regex=dict(type='bool')) + ), + push=dict(type='dict', options=dict(invert_regex=dict(type='bool'), branch=dict(type='str'), tag=dict(type='str'))), + ), + ), build=dict( type='dict', options=dict( @@ -1446,6 +1589,7 @@ def resource_to_request(module): u'ignoredFiles': module.params.get('ignored_files'), u'includedFiles': module.params.get('included_files'), u'triggerTemplate': TriggerTriggertemplate(module.params.get('trigger_template', {}), module).to_request(), + u'github': TriggerGithub(module.params.get('github', {}), module).to_request(), u'build': TriggerBuild(module.params.get('build', {}), module).to_request(), } return_vals = {} @@ -1523,6 +1667,7 @@ def response_to_hash(module, response): u'ignoredFiles': response.get(u'ignoredFiles'), u'includedFiles': response.get(u'includedFiles'), u'triggerTemplate': TriggerTriggertemplate(response.get(u'triggerTemplate', {}), module).from_response(), + u'github': TriggerGithub(response.get(u'github', {}), module).from_response(), u'build': TriggerBuild(response.get(u'build', {}), module).from_response(), } @@ -1562,6 +1707,73 @@ class TriggerTriggertemplate(object): ) +class TriggerGithub(object): + def __init__(self, request, module): + self.module = module + if request: + self.request = request + else: + self.request = {} + + def to_request(self): + return remove_nones_from_dict( + { + u'owner': self.request.get('owner'), + u'name': self.request.get('name'), + u'pullRequest': TriggerPullrequest(self.request.get('pull_request', {}), self.module).to_request(), + u'push': TriggerPush(self.request.get('push', {}), self.module).to_request(), + } + ) + + def from_response(self): + return remove_nones_from_dict( + { + u'owner': self.request.get(u'owner'), + u'name': self.request.get(u'name'), + u'pullRequest': TriggerPullrequest(self.request.get(u'pullRequest', {}), self.module).from_response(), + u'push': TriggerPush(self.request.get(u'push', {}), self.module).from_response(), + } + ) + + +class TriggerPullrequest(object): + def __init__(self, request, module): + self.module = module + if request: + self.request = request + else: + self.request = {} + + def to_request(self): + return remove_nones_from_dict( + {u'branch': self.request.get('branch'), u'commentControl': self.request.get('comment_control'), u'invertRegex': self.request.get('invert_regex')} + ) + + def from_response(self): + return remove_nones_from_dict( + {u'branch': self.request.get(u'branch'), u'commentControl': self.request.get(u'commentControl'), u'invertRegex': self.request.get(u'invertRegex')} + ) + + +class TriggerPush(object): + def __init__(self, request, module): + self.module = module + if request: + self.request = request + else: + self.request = {} + + def to_request(self): + return remove_nones_from_dict( + {u'invertRegex': self.request.get('invert_regex'), u'branch': self.request.get('branch'), u'tag': self.request.get('tag')} + ) + + def from_response(self): + return remove_nones_from_dict( + {u'invertRegex': self.request.get(u'invertRegex'), u'branch': self.request.get(u'branch'), u'tag': self.request.get(u'tag')} + ) + + class TriggerBuild(object): def __init__(self, request, module): self.module = module diff --git a/plugins/modules/gcp_cloudbuild_trigger_info.py b/plugins/modules/gcp_cloudbuild_trigger_info.py index 64b2259..15b1c82 100644 --- a/plugins/modules/gcp_cloudbuild_trigger_info.py +++ b/plugins/modules/gcp_cloudbuild_trigger_info.py @@ -223,6 +223,71 @@ resources: SHA must be provided. returned: success type: str + github: + description: + - Describes the configuration of a trigger that creates a build whenever a GitHub + event is received. + returned: success + type: complex + contains: + owner: + description: + - 'Owner of the repository. For example: The owner for U(https://github.com/googlecloudplatform/cloud-builders) + is "googlecloudplatform".' + returned: success + type: str + name: + description: + - 'Name of the repository. For example: The name for U(https://github.com/googlecloudplatform/cloud-builders) + is "cloud-builders".' + returned: success + type: str + pullRequest: + description: + - filter to match changes in pull requests. Specify only one of pullRequest + or push. + returned: success + type: complex + contains: + branch: + description: + - Regex of branches to match. + returned: success + type: str + commentControl: + description: + - Whether to block builds on a "/gcbrun" comment from a repository owner + or collaborator. + returned: success + type: str + invertRegex: + description: + - If true, branches that do NOT match the git_ref will trigger a build. + returned: success + type: bool + push: + description: + - filter to match changes in refs, like branches or tags. Specify only one + of pullRequest or push. + returned: success + type: complex + contains: + invertRegex: + description: + - When true, only trigger a build if the revision regex does NOT match + the git_ref regex. + returned: success + type: bool + branch: + description: + - Regex of branches to match. Specify only one of branch or tag. + returned: success + type: str + tag: + description: + - Regex of tags to match. Specify only one of branch or tag. + returned: success + type: str build: description: - Contents of the build template. Either a filename or build template must be