-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.py
54 lines (45 loc) · 1.34 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
48
49
50
51
52
53
54
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_GETHUB(owner, repo, endpoint):
url = f"https://api.github.com/repos/{owner}/{repo}/{endpoint}"
headers = {
"Authorization": f"token {github_token}",
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print(data)
return data[0]
else:
print(f"Error: {response.status_code}")
data = None
return data
def load_issues(issues):
docs = []
for entry in issues:
metadata = {
"author": entry["user"]["login"],
"comments": entry["comments"],
"body": entry["body"],
"created_at": entry["created_at"],
"labels": entry["labels"]
}
data = entry["title"]
if entry["body"]:
data += entry["body"]
doc = Document(page_content = data, metadata = metadata)
docs.append(doc)
return docs
def fetch_issues(owner, repo):
endpoint = "issues"
data = FETCH_GETHUB(owner, repo, endpoint)
docs = load_issues(data)
return docs
# owner = "techwithtim"
# repo = "Flask-Web-App-Tutorial"
# endpoint = "issues"
# data = FETCH_GETHUB(owner, repo, endpoint)