| 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 | |
| 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) | |