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