Skip to content

Commit 9dbf7bf

Browse files
authored
Merge pull request #89 from j-bowhay/stars_over_time
store data for when user stars the repo
2 parents 6aac187 + d6606d1 commit 9dbf7bf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

devstats/__main__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import collections
2+
import json
23
import os
34
import re
45
import sys
56
from glob import glob
67

78
import click
9+
import requests
810

911
from .publish import publish, template
1012
from .query import GithubGrabber
@@ -77,6 +79,30 @@ def query(repo_owner, repo_name, outdir):
7779
ftype = {"issues": "issues", "pullRequests": "PRs"}
7880
data.dump(f"{outdir}/{repo_name}_{ftype.get(qtype, qtype)}.json")
7981

82+
# get stars over time
83+
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/stargazers"
84+
headers = {
85+
"Accept": "application/vnd.github.v3.star+json",
86+
"Authorization": f"Bearer {token}",
87+
"X-GitHub-Api-Version": "2022-11-28",
88+
}
89+
90+
response = requests.get(url, headers=headers)
91+
92+
if response.status_code == 200:
93+
stargazers = response.json()
94+
with open(f"{outdir}/{repo_name}_stars.json", "w") as outf:
95+
simplified = [
96+
{"starred_at": user["starred_at"], "login": user["user"]["login"]}
97+
for user in stargazers
98+
]
99+
json.dump(simplified, outf)
100+
else:
101+
print(
102+
"Request failed for collecting start with status code "
103+
f"{response.status_code}"
104+
)
105+
80106

81107
cli.add_command(template)
82108
cli.add_command(publish)

0 commit comments

Comments
 (0)