Get Committers list from git & update contributors script
This commit is contained in:
parent
6136f866eb
commit
310089d847
|
@ -759,7 +759,8 @@ To make a new 3.4 release::
|
||||||
# polish changelog
|
# polish changelog
|
||||||
# - update the date
|
# - update the date
|
||||||
# - look for typos
|
# - look for typos
|
||||||
# - add list of contributors via `python3 scripts/get-contributions-stats.py develop $PREVIOUS_RELEASE`
|
# - add list of contributors via `python3 scripts/get-contributions-stats.py $NEXT_RELEASE`
|
||||||
|
git log $PREVIOUS_RELEASE.. --format="%aN" --reverse | sort | uniq -u # Get all commit authors since last release
|
||||||
nano CHANGELOG
|
nano CHANGELOG
|
||||||
|
|
||||||
# Set the `__version__` variable to $NEXT_RELEASE
|
# Set the `__version__` variable to $NEXT_RELEASE
|
||||||
|
|
|
@ -8,121 +8,100 @@ WEBLATE_URL = "https://translate.funkwhale.audio"
|
||||||
WEBLATE_COMPONENT_ID = "funkwhale/front"
|
WEBLATE_COMPONENT_ID = "funkwhale/front"
|
||||||
|
|
||||||
|
|
||||||
def get_commits(ref_name, since):
|
def get_issues(next_release):
|
||||||
url = GITLAB_URL + "/api/v4/projects/{}/repository/commits".format(
|
url = GITLAB_URL + "/api/v4/issues"
|
||||||
GITLAB_PROJECT_ID
|
# TODO assumes we have less than 100 issues per Milestone
|
||||||
|
response = requests.get(
|
||||||
|
url,
|
||||||
|
params={"per_page": 100, "milestone": next_release, "scope": "all"},
|
||||||
|
headers={"PRIVATE-TOKEN": os.environ["PRIVATE_TOKEN"]},
|
||||||
)
|
)
|
||||||
while url:
|
response.raise_for_status()
|
||||||
response = requests.get(
|
|
||||||
url, params={"since": since, "ref_name": ref_name, "per_page": 100}
|
|
||||||
)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
yield from response.json()
|
return response.json()
|
||||||
|
|
||||||
if "next" in response.links:
|
|
||||||
url = response.links["next"]["url"]
|
|
||||||
else:
|
|
||||||
url = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_commit_stats(commits):
|
def get_merge_requests(next_release):
|
||||||
stats = {"total": 0, "commiters": {}}
|
url = GITLAB_URL + "/api/v4/merge_requests"
|
||||||
for commit in commits:
|
# TODO assumes we have less than 100 issues per Milestone
|
||||||
if commit["message"].startswith("Merge branch "):
|
response = requests.get(
|
||||||
continue
|
url,
|
||||||
stats["total"] += 1
|
params={"per_page": 100, "milestone": next_release, "scope": "all"},
|
||||||
try:
|
headers={"PRIVATE-TOKEN": os.environ["PRIVATE_TOKEN"]},
|
||||||
stats["commiters"][commit["author_name"]] += 1
|
|
||||||
except KeyError:
|
|
||||||
stats["commiters"][commit["author_name"]] = 1
|
|
||||||
|
|
||||||
return stats
|
|
||||||
|
|
||||||
|
|
||||||
def get_tag_date(ref):
|
|
||||||
url = GITLAB_URL + "/api/v4/projects/{}/repository/tags/{}".format(
|
|
||||||
GITLAB_PROJECT_ID, ref
|
|
||||||
)
|
)
|
||||||
response = requests.get(url)
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
|
||||||
return data["commit"]["committed_date"]
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
def get_translations(since):
|
def get_participants(project_id, issue_iid, object_type="issues"):
|
||||||
url = WEBLATE_URL + "/api/components/{}/changes/".format(WEBLATE_COMPONENT_ID)
|
if object_type not in ["issues", "merge_requests"]:
|
||||||
while url:
|
raise ValueError("object_type needs to be `issues` or `merge_requests`")
|
||||||
response = requests.get(url)
|
url = GITLAB_URL + "/api/v4/projects/{}/{}/{}/participants".format(
|
||||||
response.raise_for_status()
|
project_id, object_type, issue_iid
|
||||||
if "next" in response.json():
|
)
|
||||||
url = response.json()["next"]
|
|
||||||
else:
|
|
||||||
url = None
|
|
||||||
for t in response.json()["results"]:
|
|
||||||
if t["timestamp"] < since:
|
|
||||||
url = None
|
|
||||||
break
|
|
||||||
|
|
||||||
yield t
|
response = requests.get(
|
||||||
|
url,
|
||||||
|
params={"per_page": 100},
|
||||||
def get_translations_stats(translations):
|
headers={"PRIVATE-TOKEN": os.environ["PRIVATE_TOKEN"]},
|
||||||
stats = {"total": 0, "translators": {}}
|
)
|
||||||
for translation in translations:
|
|
||||||
if not translation["author"]:
|
|
||||||
continue
|
|
||||||
print("translation", translation["action_name"])
|
|
||||||
continue
|
|
||||||
stats["total"] += 1
|
|
||||||
try:
|
|
||||||
stats["translators"][translation["author"]] += 1
|
|
||||||
except KeyError:
|
|
||||||
stats["translators"][translation["author"]] = 1
|
|
||||||
|
|
||||||
return stats
|
|
||||||
|
|
||||||
|
|
||||||
def get_group_usernames(group):
|
|
||||||
url = GITLAB_URL + "/api/v4/groups/{}/members".format(group)
|
|
||||||
response = requests.get(url, headers={"PRIVATE-TOKEN": os.environ["PRIVATE_TOKEN"]})
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
|
||||||
return [r["name"] for r in data]
|
participants = []
|
||||||
|
for participant in response.json():
|
||||||
|
participants.append(participant["name"])
|
||||||
|
|
||||||
|
return participants
|
||||||
|
|
||||||
|
|
||||||
|
def clear_list(inList):
|
||||||
|
outList = list(dict.fromkeys(inList))
|
||||||
|
try:
|
||||||
|
outList.remove("funkwhale-bot")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
outList.remove("weblate (bot)")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
outList.sort()
|
||||||
|
return outList
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if "PRIVATE_TOKEN" not in os.environ:
|
||||||
|
print("Please configure an Gitlab Access token in $PRIVATE_TOKEN")
|
||||||
|
return
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("ref_name")
|
parser.add_argument("next_tag")
|
||||||
parser.add_argument("last_tag")
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
since = get_tag_date(args.last_tag)
|
issues = get_issues(args.next_tag)
|
||||||
commits = get_commits(args.ref_name, since)
|
mrs = get_merge_requests(args.next_tag)
|
||||||
commits_stats = get_commit_stats(commits)
|
|
||||||
groups = [(588, "funkwhale/reviewers-python"), (589, "funkwhale/reviewers-front")]
|
print("\nContributors to our Issues:\n")
|
||||||
reviewers = []
|
issue_participants = []
|
||||||
for id, _ in groups:
|
|
||||||
reviewers += get_group_usernames(id)
|
for issue in issues:
|
||||||
print("\nReviewers:\n")
|
participants = get_participants(issue["project_id"], issue["iid"])
|
||||||
for reviewer in reviewers:
|
issue_participants.extend(participants)
|
||||||
print(reviewer)
|
|
||||||
commiter_names = commits_stats["commiters"].keys()
|
issue_participants = clear_list(issue_participants)
|
||||||
print("\nCommiters:\n")
|
for contributor in issue_participants:
|
||||||
for commiter in sorted(commits_stats["commiters"].keys(), key=lambda v: v.upper()):
|
print(contributor)
|
||||||
print(commiter)
|
|
||||||
translations = get_translations(since)
|
print("\nContributors to our Merge Requests:\n")
|
||||||
translations_stats = get_translations_stats(translations)
|
mr_participants = []
|
||||||
translators_ids = sorted(translations_stats["translators"].keys())
|
|
||||||
# There is no way to query user/author info via weblate API and we need the names…
|
for mr in mrs:
|
||||||
print(
|
participants = get_participants(mr["project_id"], mr["iid"], "merge_requests")
|
||||||
"\nExecute the following SQL query on the weblate server to get the translators names:"
|
mr_participants.extend(participants)
|
||||||
)
|
|
||||||
print("$ weblate dbshell")
|
mr_participants = clear_list(mr_participants)
|
||||||
print(
|
for contributor in mr_participants:
|
||||||
"SELECT full_name FROM weblate_auth_user WHERE id in ({});".format(
|
print(contributor)
|
||||||
", ".join([str(i) for i in translators_ids])
|
|
||||||
)
|
return
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue