Spaces:
Running
Running
from dataclasses import dataclass | |
import gradio as gr | |
from graphql_calls import get_tag_commit_date, get_commits | |
class Contributions: | |
additions: int | |
deletions: int | |
descriptions: list[str] | |
def get_release_notes( | |
token: str, | |
repo: str, | |
tag: str, | |
branch: str, | |
contributor_treshold: int, | |
ignore_dependabot: bool, | |
ignore_direct: bool, | |
): | |
date = get_tag_commit_date(token, repo, tag) | |
commits = get_commits(token, repo, branch, date) | |
result = "" | |
contributors = {} | |
for commit in commits: | |
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_treshold 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 = """ | |
## How to use the interface? | |
⚠️ Most errors are due to: | |
- A wrong `tag` -> the tag must exist on the repository! | |
- A wrong `branch` -> The branch must exist on the repository! | |
- A wrong `token` -> Obtaining a token is detailed below. | |
### token | |
This is a personal access token generated by GitHub. You can obtain one with the following guide: | |
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token. | |
### Repository | |
The repository for which to create the release notes. Should be in the format `organization/repository`. | |
### Tag | |
The tag from which all commits were made. The app will fetch the date at which this tag was created, and will | |
return all commits of the branch defined below that have a timestamp following that date. | |
### Branch | |
The branch on which all commits lie. Usually `master` or `main`. | |
### Threshold | |
This threshold allows highlighting specific community contributors according to the size of their contributions. | |
It currently adds all their additions/deletions across all PRs included in this release. It is then compared | |
to the defined threshold: if above, that user will get a special note mentioning what they have worked on! | |
""" | |
demo = gr.Interface( | |
fn=get_release_notes, | |
inputs=[ | |
gr.inputs.Textbox(lines=1, placeholder="Your GitHub token"), | |
gr.inputs.Textbox( | |
lines=1, placeholder="Repository", default="huggingface/transformers" | |
), | |
gr.inputs.Textbox(lines=1, placeholder="The tag from which to get commit"), | |
gr.inputs.Textbox( | |
lines=1, | |
placeholder="The linear branch on which the new version tag will be added", | |
default="main", | |
), | |
gr.inputs.Slider( | |
minimum=0, | |
maximum=2000, | |
default=500, | |
label="Threshold for significant contributors", | |
), | |
gr.inputs.Checkbox(label="Ignore dependabot commits"), | |
gr.inputs.Checkbox(label="Ignore direct commits"), | |
], | |
outputs="text", | |
examples=[ | |
['ghp_XXX', 'huggingface/datasets', '2.1.0', 'master', 60, True, True], | |
['ghp_XXX', 'huggingface/accelerate', 'v0.7.1', 'main', 500, True, True], | |
['ghp_XXX', 'huggingface/transformers', 'v4.18.0', 'main', 500, True, True], | |
['ghp_XXX', 'gradio-app/gradio', 'v2.9.0', 'main', 500, True, True], | |
], | |
title='Automatic release notes 🤗', | |
article=article | |
) | |
if __name__ == "__main__": | |
demo.launch(show_error=True) | |