From 17b177ce8dce92e2d1e3a0f9223eb24fac23476b Mon Sep 17 00:00:00 2001 From: Jake Bowhay Date: Mon, 12 May 2025 19:15:43 +0100 Subject: [PATCH 1/2] store data for when user stars the repo --- .gitignore | 4 ++++ devstats/__main__.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.gitignore b/.gitignore index c4c5b0e..455e00d 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,7 @@ cython_debug/ #.idea/ # MAC .DS_Store + +.python-version + +/devstats-data diff --git a/devstats/__main__.py b/devstats/__main__.py index 6154528..d0a36f8 100644 --- a/devstats/__main__.py +++ b/devstats/__main__.py @@ -1,10 +1,12 @@ import collections +import json import os import re import sys from glob import glob import click +import requests from .publish import publish, template from .query import GithubGrabber @@ -77,6 +79,30 @@ def query(repo_owner, repo_name, outdir): ftype = {"issues": "issues", "pullRequests": "PRs"} data.dump(f"{outdir}/{repo_name}_{ftype.get(qtype, qtype)}.json") + # get stars over time + url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/stargazers" + headers = { + "Accept": "application/vnd.github.v3.star+json", + "Authorization": f"Bearer {token}", + "X-GitHub-Api-Version": "2022-11-28", + } + + response = requests.get(url, headers=headers) + + if response.status_code == 200: + stargazers = response.json() + with open(f"{outdir}/{repo_name}_stars.json", "w") as outf: + simplified = [ + {"starred_at": user["starred_at"], "login": user["user"]["login"]} + for user in stargazers + ] + json.dump(simplified, outf) + else: + print( + "Request failed for collecting start with status code " + f"{response.status_code}" + ) + cli.add_command(template) cli.add_command(publish) From d6606d1db9fb7ca3d43e699866b35158afaf617e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 May 2025 19:12:18 +0000 Subject: [PATCH 2/2] =?UTF-8?q?'[pre-commit.ci=20=F0=9F=A4=96]=20Apply=20c?= =?UTF-8?q?ode=20format=20tools=20to=20PR'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3d5dcf5..e8acee0 100644 --- a/.gitignore +++ b/.gitignore @@ -169,4 +169,4 @@ cython_debug/ .history/ # devstats -devstats-data/ \ No newline at end of file +devstats-data/