-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACR: Add Pull Request Event to Task Source Trigger #7526
Changes from all commits
1accdca
20866b9
6b87f94
bdfd98d
b0b3d46
94d0527
d2ddfb2
7ff22c2
1eb7626
4961413
a998801
d95e1ce
dbd7ced
e40a2a5
4cf68da
c7f2f56
e1def2d
1e1b43e
f1a3804
41432b6
7abc6f5
6005917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ def acr_task_create(cmd, # pylint: disable=too-many-locals | |
values=None, | ||
source_trigger_name='defaultSourceTriggerName', | ||
commit_trigger_enabled=True, | ||
pull_request_trigger_enabled=True, | ||
branch='master', | ||
no_push=False, | ||
no_cache=False, | ||
|
@@ -77,9 +78,9 @@ def acr_task_create(cmd, # pylint: disable=too-many-locals | |
base_image_trigger_enabled=True, | ||
base_image_trigger_type='Runtime', | ||
resource_group_name=None): | ||
if commit_trigger_enabled and not git_access_token: | ||
raise CLIError("Commit trigger needs to be disabled [--commit-trigger-enabled False] " | ||
"if no --git-access-token is provided.") | ||
if (commit_trigger_enabled or pull_request_trigger_enabled) and not git_access_token: | ||
raise CLIError("If source control trigger is enabled [--commit-trigger-enabled] or " | ||
"[--pull-request-trigger-enabled] --git-access-token must be provided.") | ||
|
||
if file.endswith(ALLOWED_TASK_FILE_TYPES): | ||
step = FileTaskStep( | ||
|
@@ -106,7 +107,13 @@ def acr_task_create(cmd, # pylint: disable=too-many-locals | |
source_control_type = SourceControlType.github.value | ||
|
||
source_triggers = None | ||
source_trigger_events = [] | ||
if commit_trigger_enabled: | ||
source_trigger_events.append(SourceTriggerEvent.commit.value) | ||
if pull_request_trigger_enabled: | ||
source_trigger_events.append(SourceTriggerEvent.pullrequest.value) | ||
# if source_trigger_events contains any event types we assume they are enabled | ||
if source_trigger_events: | ||
source_triggers = [ | ||
SourceTrigger( | ||
source_repository=SourceProperties( | ||
|
@@ -119,8 +126,8 @@ def acr_task_create(cmd, # pylint: disable=too-many-locals | |
scope='repo' | ||
) | ||
), | ||
source_trigger_events=[SourceTriggerEvent.commit.value], | ||
status=TriggerStatus.enabled.value if commit_trigger_enabled else TriggerStatus.disabled.value, | ||
source_trigger_events=source_trigger_events, | ||
status=TriggerStatus.enabled.value, | ||
name=source_trigger_name | ||
) | ||
] | ||
|
@@ -205,6 +212,7 @@ def acr_task_update(cmd, # pylint: disable=too-many-locals | |
timeout=None, | ||
context_path=None, | ||
commit_trigger_enabled=None, | ||
pull_request_trigger_enabled=None, | ||
git_access_token=None, | ||
branch=None, | ||
image_names=None, | ||
|
@@ -282,10 +290,10 @@ def acr_task_update(cmd, # pylint: disable=too-many-locals | |
if task.trigger: | ||
source_triggers = task.trigger.source_triggers | ||
base_image_trigger = task.trigger.base_image_trigger | ||
if commit_trigger_enabled or source_triggers is not None: | ||
status = None | ||
if commit_trigger_enabled is not None: | ||
status = TriggerStatus.enabled.value if commit_trigger_enabled else TriggerStatus.disabled.value | ||
if (commit_trigger_enabled or pull_request_trigger_enabled) or source_triggers: | ||
source_trigger_events = _get_trigger_event_list(source_triggers, | ||
commit_trigger_enabled, | ||
pull_request_trigger_enabled) | ||
source_trigger_update_params = [ | ||
SourceTriggerUpdateParameters( | ||
source_repository=SourceUpdateParameters( | ||
|
@@ -297,11 +305,12 @@ def acr_task_update(cmd, # pylint: disable=too-many-locals | |
token_type=DEFAULT_TOKEN_TYPE | ||
) | ||
), | ||
source_trigger_events=[SourceTriggerEvent.commit], | ||
status=status, | ||
name=source_triggers[0].name if source_triggers else "defaultBaseimageTriggerName" | ||
source_trigger_events=source_trigger_events, | ||
status=TriggerStatus.enabled.value if source_trigger_events else TriggerStatus.disabled.value, | ||
name=source_triggers[0].name if source_triggers else "defaultSourceTriggerName" | ||
) | ||
] | ||
|
||
if base_image_trigger_enabled or base_image_trigger is not None: | ||
status = None | ||
if base_image_trigger_enabled is not None: | ||
|
@@ -488,3 +497,27 @@ def _get_list_runs_message(base_message, task_name=None, image=None): | |
if image: | ||
base_message = "{} for image '{}'".format(base_message, image) | ||
return "{}.".format(base_message) | ||
|
||
|
||
def _get_trigger_event_list(source_triggers, | ||
commit_trigger_enabled=None, | ||
pull_request_trigger_enabled=None): | ||
source_trigger_events = set() | ||
# perform merge with server-side event list | ||
if source_triggers: | ||
source_trigger_events = set(source_triggers[0].source_trigger_events) | ||
if source_triggers[0].status == TriggerStatus.disabled.value: | ||
source_trigger_events.clear() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also relates to the above question. Is it possible that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an edge case in the RP that checks if
Therefore, a disabled trigger event list may be "empty" to the client it is not to the server (though the trigger is still disabled). This |
||
if commit_trigger_enabled is not None: | ||
if commit_trigger_enabled: | ||
source_trigger_events.add(SourceTriggerEvent.commit.value) | ||
else: | ||
if SourceTriggerEvent.commit.value in source_trigger_events: | ||
source_trigger_events.remove(SourceTriggerEvent.commit.value) | ||
if pull_request_trigger_enabled is not None: | ||
if pull_request_trigger_enabled: | ||
source_trigger_events.add(SourceTriggerEvent.pullrequest.value) | ||
else: | ||
if SourceTriggerEvent.pullrequest.value in source_trigger_events: | ||
source_trigger_events.remove(SourceTriggerEvent.pullrequest.value) | ||
return source_trigger_events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: _update_trigger_event_list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event list is not always updated. If a user calls task update for reasons other than changing the status of
commit-trigger-enabled
orpull-request-trigger-enabled
then the event list is not updated, but retrieved as is from server.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I was under the impression that this one can also be called by the create method.