-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.py
47 lines (36 loc) · 1.16 KB
/
github.py
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
43
44
45
46
47
import os
import requests
from dotenv import load_dotenv
from langchain_core.documents import Document
load_dotenv()
github_token = os.getenv("GITHUB_TOKEN")
def fetch_github(owner, repo, endpoint):
url = f"https://api.github.com/repos/{owner}/{repo}/{endpoint}"
headers = {"Authorization": f"Bearer {github_token}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
else:
print("Failed with status code:", response.status_code)
return []
print(data)
return data
def fetch_github_issues(owner, repo):
data = fetch_github(owner, repo, "issues")
return load_issues(data)
def load_issues(issues):
docs = []
for entry in issues:
metadata = {
"author": entry["user"]["login"],
"comments": entry["comments"],
"body": entry["body"],
"labels": entry["labels"],
"created_at": entry["created_at"],
}
data = entry["title"]
if entry["body"]:
data += entry["body"]
doc = Document(page_content=data, metadata=metadata)
docs.append(doc)
return docs