1818import attr
1919import jsone
2020import jsonschema
21+
2122import taskcluster
2223
2324from . import scopes
@@ -35,13 +36,7 @@ def _is_task_in_context(context, task_tags):
3536 a given task, if that task's tags match one of the tag-sets given
3637 in the context property for the action.
3738 """
38- return any (
39- all (
40- tag in task_tags and task_tags [tag ] == tag_set [tag ]
41- for tag in tag_set .keys ()
42- )
43- for tag_set in context
44- )
39+ return any (all (tag in task_tags and task_tags [tag ] == tag_set [tag ] for tag in tag_set .keys ()) for tag_set in context )
4540
4641
4742def _filter_relevant_actions (actions_json , original_task ):
@@ -71,27 +66,22 @@ def _check_decision_task_scopes(decision_task_id, hook_group_id, hook_id):
7166 queue = taskcluster .Queue (taskcluster .optionsFromEnvironment (), session = SESSION )
7267 auth = taskcluster .Auth (taskcluster .optionsFromEnvironment (), session = SESSION )
7368 decision_task = queue .task (decision_task_id )
74- decision_task_scopes = auth .expandScopes ({"scopes" : decision_task ["scopes" ]})[
75- "scopes"
76- ]
69+ decision_task_scopes = auth .expandScopes ({"scopes" : decision_task ["scopes" ]})["scopes" ]
7770 in_tree_scope = f"in-tree:hook-action:{ hook_group_id } /{ hook_id } "
7871
7972 if not scopes .satisfies (have = decision_task_scopes , require = [in_tree_scope ]):
8073 raise RuntimeError (
8174 "Action is misconfigured: "
8275 f"decision task's scopes do not include { in_tree_scope } \n "
83- "Decision Task {decision_task_id} has scopes:\n "
84- + "\n " .join (f" - { scope } " for scope in decision_task_scopes )
76+ "Decision Task {decision_task_id} has scopes:\n " + "\n " .join (f" - { scope } " for scope in decision_task_scopes )
8577 )
8678
8779
8880def render_action (* , action_name , task_id , decision_task_id , action_input ):
8981 queue = taskcluster .Queue (taskcluster .optionsFromEnvironment (), session = SESSION )
9082
9183 logger .debug ("Fetching actions.json..." )
92- actions_url = queue .buildUrl (
93- "getLatestArtifact" , decision_task_id , "public/actions.json"
94- )
84+ actions_url = queue .buildUrl ("getLatestArtifact" , decision_task_id , "public/actions.json" )
9585 actions_response = SESSION .get (actions_url )
9686 actions_response .raise_for_status ()
9787 actions_json = actions_response .json ()
@@ -106,17 +96,12 @@ def render_action(*, action_name, task_id, decision_task_id, action_input):
10696 relevant_actions = _filter_relevant_actions (actions_json , task_definition )
10797
10898 if action_name not in relevant_actions :
109- raise LookupError (
110- f"{ action_name } action is not available for this task. "
111- f"Available: { sorted (relevant_actions .keys ())} "
112- )
99+ raise LookupError (f"{ action_name } action is not available for this task. Available: { sorted (relevant_actions .keys ())} " )
113100
114101 action = relevant_actions [action_name ]
115102
116103 if action ["kind" ] != "hook" :
117- raise NotImplementedError (
118- f"Unable to submit actions with '{ action ['kind' ]} ' kind."
119- )
104+ raise NotImplementedError (f"Unable to submit actions with '{ action ['kind' ]} ' kind." )
120105
121106 _check_decision_task_scopes (
122107 decision_task_id ,
@@ -163,9 +148,7 @@ def submit(self):
163148 session = SESSION ,
164149 )
165150 else :
166- hooks = taskcluster .Hooks (
167- taskcluster .optionsFromEnvironment (), session = SESSION
168- )
151+ hooks = taskcluster .Hooks (taskcluster .optionsFromEnvironment (), session = SESSION )
169152
170153 logger .info ("Triggering hook %s/%s" , self .hook_group_id , self .hook_id )
171154 result = hooks .triggerHook (self .hook_group_id , self .hook_id , self .hook_payload )
0 commit comments