From a1eb642a587ed6d69220a383ff4d402196a9ebad Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 16 May 2020 12:47:11 -0400 Subject: [PATCH] Read directly from the git repository to get commits --- commits.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/commits.py b/commits.py index ced0ca5..01c69b9 100644 --- a/commits.py +++ b/commits.py @@ -3,6 +3,7 @@ import os import requests import json import os +import subprocess from datetime import datetime @@ -23,23 +24,25 @@ def grab(url): url = "https://git.crux.best/api/v1/repos/chemicalcrux/{0}/releases".format(sys.argv[1]) -tag = grab(url)[0]["tag_name"] +data = grab(url) -url = "https://git.crux.best/api/v1/repos/chemicalcrux/{0}/commits?sha={1}".format(sys.argv[1], tag) +if data: + spec = data[0]["tag_name"] + "..master" +else: + spec = "master" -data = grab(url)[1:] +output = subprocess.check_output(["git", "log", r"--pretty=format:%aI%x00%s%x00%b%x00", spec]).decode("utf-8").split("\x00") -results = [] -for commit in data: - result = {} - lines = commit["commit"]["message"].split("\n") - subject = lines[0] - body = "\n".join(lines[2:]) +data = [] - result["date"] = datetime.fromisoformat(commit["commit"]["author"]["date"]).strftime("%B %d") - result["subject"] = subject - result["body"] = body - results.append(result) +# last item is an empty string +for i in range(0, len(output)-1, 3): + entry = {} + entry["date"] = output[i].strip() + entry["date"] = datetime.fromisoformat(entry["date"]).strftime("%B %d") + entry["subject"] = output[i+1].strip() + entry["body"] = output[i+2].strip() + data.append(entry) with open(sys.argv[2], "w", encoding="utf-8") as file: - json.dump(results[::-1], file) + json.dump(data, file)