-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.py
More file actions
43 lines (37 loc) · 1.24 KB
/
github.py
File metadata and controls
43 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Author: Robert Wojciechowski <robertwoj@microsoft.com>
# License: MIT
import subprocess
import datetime
import json
from enum import Enum
from typing import List
from pr import PR
from repo_type import RepoType
def determine_user():
return subprocess.check_output(["gh", "api", "user", "--jq", ".login"]).decode().strip()
def list_prs(month_start, month_end) -> List[PR]:
search_range = f"created:{month_start}..{month_end}"
try:
user = determine_user()
result = subprocess.check_output([
"gh", "pr", "list",
"--author", user,
"--search", search_range,
"--state", "all",
"--json", "number,title,createdAt,closedAt,updatedAt"
]).decode()
array = json.loads(result)
result = []
for item in array:
number = item["number"]
pr = PR(
repo_type=RepoType.GITHUB,
title=item["title"],
created_at=item["createdAt"].split("T")[0],
url=f"https://github.com/Azure/azure-osconfig/pull/{number}",
)
result.append(pr)
return result
except subprocess.CalledProcessError as e:
print(f"Error fetching PRs: {e}")
return []