OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 import webapp2 | 6 import webapp2 |
7 | 7 |
8 from dashboard.api import api_auth | 8 from dashboard.api import api_auth |
| 9 from dashboard.pinpoint.handlers import quest_generator |
9 from dashboard.pinpoint.models import change | 10 from dashboard.pinpoint.models import change |
10 from dashboard.pinpoint.models import job as job_module | 11 from dashboard.pinpoint.models import job as job_module |
11 from dashboard.pinpoint.models import quest_generator as quest_generator_module | |
12 | 12 |
13 | 13 |
14 _ERROR_BUG_ID = 'Bug ID must be an integer.' | 14 _ERROR_BUG_ID = 'Bug ID must be an integer.' |
15 | 15 |
16 | 16 |
17 class New(webapp2.RequestHandler): | 17 class New(webapp2.RequestHandler): |
18 """Handler that cooks up a fresh Pinpoint job.""" | 18 """Handler that cooks up a fresh Pinpoint job.""" |
19 | 19 |
20 def post(self): | 20 def post(self): |
21 try: | 21 try: |
(...skipping 18 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 change_2 = { | 42 change_2 = { |
43 'base_commit': { | 43 'base_commit': { |
44 'repository': self.request.get('end_repository'), | 44 'repository': self.request.get('end_repository'), |
45 'git_hash': self.request.get('end_git_hash') | 45 'git_hash': self.request.get('end_git_hash') |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 # Validate arguments and convert them to canonical internal representation. | 49 # Validate arguments and convert them to canonical internal representation. |
50 quest_generator = quest_generator_module.QuestGenerator(self.request) | 50 arguments, quests = quest_generator.GenerateQuests(self.request) |
51 bug_id = self._ValidateBugId(bug_id) | 51 bug_id = _ValidateBugId(bug_id) |
52 changes = self._ValidateChanges(change_1, change_2) | 52 changes = _ValidateChanges(change_1, change_2) |
53 | 53 |
54 # Create job. | 54 # Create job. |
55 job = job_module.Job.New( | 55 job = job_module.Job.New( |
56 arguments=quest_generator.AsDict(), | 56 arguments=arguments, |
57 quests=quest_generator.Quests(), | 57 quests=quests, |
58 auto_explore=auto_explore, | 58 auto_explore=auto_explore, |
59 bug_id=bug_id) | 59 bug_id=bug_id) |
60 | 60 |
61 # Add changes. | 61 # Add changes. |
62 for c in changes: | 62 for c in changes: |
63 job.AddChange(c) | 63 job.AddChange(c) |
64 | 64 |
65 # Put job into datastore. | 65 # Put job into datastore. |
66 job_id = job.put().urlsafe() | 66 job_id = job.put().urlsafe() |
67 | 67 |
68 # Start job. | 68 # Start job. |
69 job.Start() | 69 job.Start() |
70 job.put() | 70 job.put() |
71 | 71 |
72 # TODO: Figure out if these should be underscores or lowerCamelCase. | 72 # TODO: Figure out if these should be underscores or lowerCamelCase. |
73 # TODO: They should match the input arguments. | 73 # TODO: They should match the input arguments. |
74 self.response.out.write(json.dumps({ | 74 self.response.out.write(json.dumps({ |
75 'jobId': job_id, | 75 'jobId': job_id, |
76 'jobUrl': job.url | 76 'jobUrl': job.url |
77 })) | 77 })) |
78 | 78 |
79 def _ValidateBugId(self, bug_id): | |
80 if not bug_id: | |
81 return None | |
82 | 79 |
83 try: | 80 def _ValidateBugId(bug_id): |
84 return int(bug_id) | 81 if not bug_id: |
85 except ValueError: | 82 return None |
86 raise ValueError(_ERROR_BUG_ID) | |
87 | 83 |
88 def _ValidateChanges(self, change_1, change_2): | 84 try: |
89 return (change.Change.FromDict(change_1), change.Change.FromDict(change_2)) | 85 return int(bug_id) |
| 86 except ValueError: |
| 87 raise ValueError(_ERROR_BUG_ID) |
| 88 |
| 89 |
| 90 def _ValidateChanges(change_1, change_2): |
| 91 return (change.Change.FromDict(change_1), change.Change.FromDict(change_2)) |
OLD | NEW |