File size: 3,761 Bytes
b8f978e f30c6d8 3bbc731 f30c6d8 3bbc731 b8f978e e326eb8 b8f978e 2455fd8 f30c6d8 2455fd8 e326eb8 b8f978e 3bbc731 26e026f b8f978e f30c6d8 b8f978e 3bbc731 b8f978e f30c6d8 b8f978e 3bbc731 b8f978e 3bbc731 a9f33a2 f30c6d8 a9f33a2 f30c6d8 3bbc731 f30c6d8 cfa1326 b8f978e 3bbc731 cfa1326 f30c6d8 b8f978e cfa1326 b8f978e f30c6d8 b8f978e cfa1326 b8f978e cfa1326 b8f978e cfa1326 3bbc731 b8f978e eca9dc3 3bbc731 a9f33a2 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
from dataclasses import dataclass
import os
import gradio as gr
from graphql_calls import get_tag_commit_date, get_commits
from github import fetch_github_info
@dataclass
class Contributions:
additions: int
deletions: int
descriptions: list[str]
def get_release_notes(
tag: str,
branch: str,
contributor_treshhold: int,
ignore_dependabot: bool,
ignore_direct: bool,
):
try:
token = os.getenv("GITHUB_TOKEN")
repo = "huggingface/diffusers"
date = get_tag_commit_date(token, repo, tag)
commits = get_commits(token, repo, branch, date)
except ValueError as e:
return str(e)
result = ""
contributors = {}
for commit in commits[::-1]:
if "Hugging Face" not in commit.user.organizations:
if commit.user.name not in contributors:
contributors[commit.user.name] = Contributions(
additions=commit.additions,
deletions=commit.deletions,
descriptions=[commit.message],
)
else:
contributors[commit.user.name].additions += commit.additions
contributors[commit.user.name].deletions += commit.deletions
contributors[commit.user.name].descriptions += [commit.message]
if "(#" in commit.message:
if ignore_dependabot and commit.user.name == "dependabot[bot]":
continue
split = commit.message.split("(#")
message = split[0]
number = split[1].strip(")")
result += f"* {message} by @{commit.user.name} in #{number}\n"
elif not ignore_direct:
result += f"* {commit.message} by @{commit.user.name} (direct commit on {branch})\n"
significant_contributors = {
k: v
for k, v in contributors.items()
if (v.additions + v.deletions) > contributor_treshhold and k != "<NOT FOUND>"
}
if len(significant_contributors):
result += (
"\n## Significant community contributions\n"
"\nThe following contributors have made significant "
"changes to the library over the last release:\n\n"
)
for significant_contributor, contributions in significant_contributors.items():
result += f"* @{significant_contributor}\n"
for description in contributions.descriptions:
result += f" * {description}\n"
return result
article = """
Mostly copied from [lysandre/github-release](https://huggingface.co/spaces/lysandre/github-release) but suited for
Diffusers.
"""
github_info = fetch_github_info("https://github.com/huggingface/diffusers")
demo = gr.Interface(
title="Automatic release notes for 🤗 Diffusers",
article=article,
description="**See instructions below the form.**",
fn=get_release_notes,
inputs=[
gr.components.Textbox(
lines=1,
value=github_info["second_last_tag"] if github_info else None,
placeholder="The tag from which to get commit",
),
gr.components.Textbox(
lines=1,
placeholder="The linear branch on which the new version tag will be added",
value=github_info["latest_release_branch"] if github_info else None,
),
gr.components.Slider(
minimum=0,
maximum=2000,
value=500,
label="Threshold for significant contributors",
),
gr.components.Checkbox(label="Ignore dependabot commits"),
gr.components.Checkbox(label="Ignore direct commits"),
],
outputs="text",
allow_flagging="never"
)
if __name__ == "__main__":
demo.launch(show_error=True)
|