|
1 | 1 | import os |
2 | | -import re |
3 | | -from datetime import date |
4 | 2 | from operator import itemgetter |
5 | 3 | from pathlib import Path |
6 | 4 |
|
7 | 5 | import requests |
8 | | -import strictyaml as yaml |
9 | 6 | from jinja2 import Template |
10 | 7 |
|
| 8 | +from pyvec_docs.board import BOARD_HISTORY |
| 9 | +from pyvec_docs.grants import get_lock_date, get_votes, remove_comments, to_date |
| 10 | + |
11 | 11 |
|
12 | 12 | GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") |
13 | 13 | GITHUB_API_HEADERS = { |
14 | 14 | "Accept": "application/vnd.github.squirrel-girl-preview", |
15 | 15 | "Authorization": f"token {GITHUB_TOKEN}", |
16 | 16 | } |
17 | 17 | GITHUB_API_URL = "https://api.github.com/repos/pyvec/money/issues" |
18 | | -REACTIONS_MAPPING = {"+1": "ano", "-1": "ne", "eyes": "zdržel(a) se"} |
19 | | -CONTENT_PATH = Path(__file__).parent.parent |
20 | | - |
21 | | -BOARD_HISTORY_SCHEMA = yaml.Seq( |
22 | | - yaml.Map( |
23 | | - { |
24 | | - "from": yaml.Datetime(), |
25 | | - "members": yaml.MapPattern(yaml.Str(), yaml.Str()), |
26 | | - } |
27 | | - ) |
28 | | -) |
29 | | -BOARD_HISTORY_PATH = Path(__file__).parent.parent / "board.yml" |
30 | | -BOARD_HISTORY = sorted( |
31 | | - yaml.load(BOARD_HISTORY_PATH.read_text(), BOARD_HISTORY_SCHEMA).data, |
32 | | - key=itemgetter("from"), |
33 | | - reverse=True, |
34 | | -) |
35 | | - |
36 | | - |
37 | | -def to_date(iso_datetime_string): |
38 | | - iso_date_string, _ = iso_datetime_string.split("T") |
39 | | - return date.fromisoformat(iso_date_string) |
40 | | - |
41 | | - |
42 | | -def remove_comments(html): |
43 | | - return re.sub(r"<!--[^<]+-->", "", html).strip() |
44 | | - |
45 | | - |
46 | | -def get_board_member_name(username, voted_at, board_history=None): |
47 | | - board_history = board_history or BOARD_HISTORY |
48 | | - for board in board_history: # sorted from the most recent |
49 | | - if voted_at > board["from"].date(): |
50 | | - return board["members"].get(username) |
51 | | - return None |
52 | | - |
53 | | - |
54 | | -def get_votes(reactions, voted_at, board_history=None): |
55 | | - for reaction in reactions: |
56 | | - username = reaction["user"]["login"] |
57 | | - name = get_board_member_name(username, voted_at, board_history) |
58 | | - if name: # else not reaction from a board member |
59 | | - text = REACTIONS_MAPPING.get(reaction["content"]) |
60 | | - if text: |
61 | | - yield {"name": name, "text": text} |
62 | | - |
63 | | - |
64 | | -def get_lock_date(events): |
65 | | - for event in reversed(events): |
66 | | - if event["event"] == "locked": |
67 | | - return to_date(event["created_at"]) |
| 18 | +CONTENT_PATH = Path(__file__).parent.parent.parent.parent |
68 | 19 |
|
69 | 20 |
|
70 | 21 | if __name__ == "__main__": |
@@ -103,7 +54,7 @@ def get_lock_date(events): |
103 | 54 |
|
104 | 55 | res = requests.get(issue["reactions"]["url"], headers=GITHUB_API_HEADERS) |
105 | 56 | res.raise_for_status() |
106 | | - votes = list(get_votes(res.json(), voted_at)) |
| 57 | + votes = list(get_votes(res.json(), voted_at, BOARD_HISTORY)) |
107 | 58 |
|
108 | 59 | grants.append( |
109 | 60 | { |
|
0 commit comments