Bug 1340668 - Fix repo scopes in action.json generation draft
authorBrian Stack <bstack@mozilla.com>
Fri, 17 Feb 2017 14:43:59 -0800
changeset 486453 426253f85084bbe7af432732c27729316d855fb9
parent 486451 d11c29c1db3a1bc96ad5792ebf8a89b2fbadcf85
child 546239 d52b16cfcb808d5812b770780abf0573323b30df
push id45977
push userbstack@mozilla.com
push dateFri, 17 Feb 2017 22:48:03 +0000
bugs1340668
milestone54.0a1
Bug 1340668 - Fix repo scopes in action.json generation MozReview-Commit-ID: CprCcIiqsbH
taskcluster/actions/registry.py
--- a/taskcluster/actions/registry.py
+++ b/taskcluster/actions/registry.py
@@ -1,11 +1,12 @@
 import json
 import os
 import inspect
+import re
 from types import FunctionType
 from collections import namedtuple
 from taskgraph.util.docker import docker_image
 from taskgraph.parameters import Parameters
 
 
 GECKO = os.path.realpath(os.path.join(__file__, '..', '..', '..'))
 
@@ -154,32 +155,39 @@ def register_callback_action(title, symb
         assert not mem['registered'], 'register_callback_action must be used as decorator'
         assert cb.__name__ not in callbacks, 'callback name {} is not unique'.format(cb.__name__)
         source_path = os.path.relpath(inspect.stack()[1][1], GECKO)
 
         @register_task_action(title, description, order, context, schema)
         def build_callback_action_task(parameters):
             if not available(parameters):
                 return None
+
+            match = re.match(r'https://(hg.mozilla.org)/(.*?)/?$', parameters['head_repository'])
+            if not match:
+                raise Exception('Unrecognized head_repository')
+            repo_scope = 'assume:repo:{}/{}:*'.format(
+                match.group(1), match.group(2))
+
             return {
                 'created': {'$fromNow': ''},
                 'deadline': {'$fromNow': '12 hours'},
                 'expires': {'$fromNow': '14 days'},
                 'metadata': {
                     'owner': 'mozilla-taskcluster-maintenance@mozilla.com',
                     'source': '{}raw-file/{}/{}'.format(
                         parameters['head_repository'], parameters['head_rev'], source_path,
                     ),
                     'name': 'Action: {}'.format(title),
                     'description': 'Task executing callback for action.\n\n---\n' + description,
                 },
                 'workerType': 'gecko-decision',
                 'provisionerId': 'aws-provisioner-v1',
                 'scopes': [
-                    'assume:repo:hg.mozilla.org/projects/{}:*'.format(parameters['project']),
+                    repo_scope,
                 ],
                 'tags': {
                     'createdForUser': parameters['owner'],
                     'kind': 'action-callback',
                 },
                 'routes': [
                     'tc-treeherder.v2.{}.{}.{}'.format(
                         parameters['project'], parameters['head_rev'], parameters['pushlog_id']),