1# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""The database models for bug data."""
6
7import logging
8
9from google.appengine.ext import ndb
10
11
12BUG_STATUS_OPENED = 'opened'
13BUG_STATUS_CLOSED = 'closed'
14BUG_STATUS_RECOVERED = 'recovered'
15
16BISECT_STATUS_STARTED = 'started'
17BISECT_STATUS_COMPLETED = 'completed'
18BISECT_STATUS_FAILED = 'failed'
19
20
21class Bug(ndb.Model):
22  """Information about a bug created in issue tracker.
23
24  Keys for Bug entities will be in the form ndb.Key('Bug', <bug_id>).
25  """
26  status = ndb.StringProperty(
27      default=BUG_STATUS_OPENED,
28      choices=[
29          BUG_STATUS_OPENED,
30          BUG_STATUS_CLOSED,
31          BUG_STATUS_RECOVERED,
32      ],
33      indexed=True)
34
35  # Status of the latest bisect run for this bug
36  # (e.g., started, failed, completed).
37  latest_bisect_status = ndb.StringProperty(
38      default=None,
39      choices=[
40          BISECT_STATUS_STARTED,
41          BISECT_STATUS_COMPLETED,
42          BISECT_STATUS_FAILED,
43      ],
44      indexed=True)
45
46  # The time that the Bug entity was created.
47  timestamp = ndb.DateTimeProperty(indexed=True, auto_now_add=True)
48
49
50def SetBisectStatus(bug_id, status):
51  """Sets the bisect status for a Bug entity."""
52  if bug_id is None or bug_id < 0:
53    return
54  bug = ndb.Key('Bug', int(bug_id)).get()
55  if bug:
56    bug.latest_bisect_status = status
57    bug.put()
58  else:
59    logging.error('Bug %s does not exist.', bug_id)
60