|
4 | 4 | import subprocess |
5 | 5 | import json |
6 | 6 | import sys |
7 | | -from datetime import datetime |
| 7 | +from datetime import datetime, timezone |
| 8 | + |
8 | 9 |
|
9 | 10 | def fetch_discussions(): |
10 | 11 | """Fetch discussions using gh CLI GraphQL.""" |
@@ -38,53 +39,62 @@ def fetch_discussions(): |
38 | 39 | } |
39 | 40 | } |
40 | 41 | """ |
41 | | - |
| 42 | + |
42 | 43 | try: |
43 | 44 | result = subprocess.run( |
44 | | - ['gh', 'api', 'graphql', '-f', f'query={query}'], |
| 45 | + ["gh", "api", "graphql", "-f", f"query={query}"], |
45 | 46 | capture_output=True, |
46 | 47 | text=True, |
47 | | - timeout=30 |
| 48 | + timeout=30, |
48 | 49 | ) |
49 | | - |
| 50 | + |
50 | 51 | if result.returncode == 0 and result.stdout: |
51 | 52 | data = json.loads(result.stdout) |
52 | | - return data.get('data', {}).get('repository', {}).get('discussions', {}).get('edges', []) |
| 53 | + return ( |
| 54 | + data.get("data", {}) |
| 55 | + .get("repository", {}) |
| 56 | + .get("discussions", {}) |
| 57 | + .get("edges", []) |
| 58 | + ) |
53 | 59 | return [] |
54 | 60 | except Exception as e: |
55 | 61 | print(f"Error fetching discussions: {e}", file=sys.stderr) |
56 | 62 | return [] |
57 | 63 |
|
| 64 | + |
58 | 65 | def main(): |
59 | 66 | """Generate DISCUSSIONS_TODAY.md from GitHub discussions.""" |
60 | 67 | discussions = fetch_discussions() |
61 | | - |
| 68 | + |
62 | 69 | if not discussions: |
63 | 70 | print("# Discussions Today\n\nNo recent discussions found.", file=sys.stdout) |
64 | 71 | return |
65 | | - |
| 72 | + |
66 | 73 | output = ["# Discussions Today\n\n"] |
67 | | - output.append(f"*Fetched at: {datetime.utcnow().isoformat()}*\n\n") |
68 | | - |
| 74 | + output.append(f"*Fetched at: {datetime.now(timezone.utc).isoformat()}*\n\n") |
| 75 | + |
69 | 76 | for edge in discussions: |
70 | | - node = edge.get('node', {}) |
| 77 | + node = edge.get("node", {}) |
71 | 78 | output.append(f"## {node.get('title', 'Untitled')}\n\n") |
72 | 79 | output.append(f"**Author**: {node.get('author', {}).get('login', 'unknown')}\n") |
73 | 80 | output.append(f"**URL**: {node.get('url', '#')}\n\n") |
74 | 81 | output.append(f"**Body**: {node.get('body', '')}\n\n") |
75 | | - |
| 82 | + |
76 | 83 | # Add comments |
77 | | - comments = node.get('comments', {}).get('edges', []) |
| 84 | + comments = node.get("comments", {}).get("edges", []) |
78 | 85 | if comments: |
79 | 86 | output.append("**Comments**:\n\n") |
80 | 87 | for comment_edge in comments: |
81 | | - comment = comment_edge.get('node', {}) |
82 | | - output.append(f"- **{comment.get('author', {}).get('login', 'unknown')}**: ") |
| 88 | + comment = comment_edge.get("node", {}) |
| 89 | + output.append( |
| 90 | + f"- **{comment.get('author', {}).get('login', 'unknown')}**: " |
| 91 | + ) |
83 | 92 | output.append(f"{comment.get('body', '')}\n\n") |
84 | | - |
| 93 | + |
85 | 94 | output.append("---\n\n") |
86 | | - |
87 | | - print(''.join(output), file=sys.stdout) |
88 | 95 |
|
89 | | -if __name__ == '__main__': |
| 96 | + print("".join(output), file=sys.stdout) |
| 97 | + |
| 98 | + |
| 99 | +if __name__ == "__main__": |
90 | 100 | main() |
0 commit comments