Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style |
| 3 | # license that can be found in the LICENSE file or at |
| 4 | # https://developers.google.com/open-source/licenses/bsd |
| 5 | |
| 6 | """Protocol buffers for Monorail features.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | from __future__ import division |
| 10 | from __future__ import absolute_import |
| 11 | |
| 12 | from features import features_constants |
| 13 | from protorpc import messages |
| 14 | |
| 15 | |
| 16 | class Hotlist(messages.Message): |
| 17 | """This protocol buffer holds all the metadata associated with a hotlist.""" |
| 18 | # A numeric identifier for this hotlist. |
| 19 | hotlist_id = messages.IntegerField(1, required=True) |
| 20 | |
| 21 | # The short identifier for this hotlist. |
| 22 | name = messages.StringField(2, required=True) |
| 23 | |
| 24 | # A one-line summary (human-readable) of the hotlist. |
| 25 | summary = messages.StringField(3, default='') |
| 26 | |
| 27 | # A detailed description of the hotlist. |
| 28 | description = messages.StringField(4, default='') |
| 29 | |
| 30 | # Hotlists can be marked private to prevent unwanted users from seeing them. |
| 31 | is_private = messages.BooleanField(5, default=False) |
| 32 | |
| 33 | # Note that these lists are disjoint (a user ID will not appear twice). |
| 34 | owner_ids = messages.IntegerField(6, repeated=True) |
| 35 | editor_ids = messages.IntegerField(8, repeated=True) |
| 36 | follower_ids = messages.IntegerField(9, repeated=True) |
| 37 | |
| 38 | |
| 39 | class HotlistItem(messages.Message): |
| 40 | """Nested message for a hotlist to issue relation.""" |
| 41 | issue_id = messages.IntegerField(1, required=True) |
| 42 | rank = messages.IntegerField(2, required=True) |
| 43 | adder_id = messages.IntegerField(3) |
| 44 | date_added = messages.IntegerField(4) |
| 45 | note = messages.StringField(5, default='') |
| 46 | |
| 47 | items = messages.MessageField(HotlistItem, 10, repeated=True) |
| 48 | |
| 49 | # The default columns to show on hotlist issues page |
| 50 | default_col_spec = messages.StringField( |
| 51 | 11, default=features_constants.DEFAULT_COL_SPEC) |
| 52 | |
| 53 | def MakeHotlist(name, hotlist_item_fields=None, **kwargs): |
| 54 | """Returns a hotlist protocol buffer with the given attributes. |
| 55 | Args: |
| 56 | hotlist_item_fields: tuple of (iid, rank, user, date, note) |
| 57 | kwargs should only include the following: |
| 58 | hotlist_id, summary, description, is_private, owner_ids, editor_ids, |
| 59 | follower_ids, default_col_spec""" |
| 60 | hotlist = Hotlist(name=name, **kwargs) |
| 61 | |
| 62 | if hotlist_item_fields is not None: |
| 63 | for iid, rank, user, date, note in hotlist_item_fields: |
| 64 | hotlist.items.append(Hotlist.HotlistItem( |
| 65 | issue_id=iid, rank=rank, adder_id=user, date_added=date, note=note)) |
| 66 | |
| 67 | return hotlist |
| 68 | |
| 69 | |
| 70 | # For any issues that were added to hotlists before we started storing that |
| 71 | # timestamp, just use the launch date of the feature as a default. |
| 72 | ADDED_TS_FEATURE_LAUNCH_TS = 1484350000 # Jan 13, 2017 |
| 73 | |
| 74 | |
| 75 | def MakeHotlistItem( |
| 76 | issue_id, rank=None, adder_id=None, date_added=None, note=None): |
| 77 | item = Hotlist.HotlistItem( |
| 78 | issue_id=issue_id, |
| 79 | date_added=date_added or ADDED_TS_FEATURE_LAUNCH_TS) |
| 80 | if rank is not None: |
| 81 | item.rank = rank |
| 82 | if adder_id is not None: |
| 83 | item.adder_id = adder_id |
| 84 | if note is not None: |
| 85 | item.note = note |
| 86 | return item |