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, 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 | |
| } | |
| 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 | |
| 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", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |