File size: 4,929 Bytes
b9b07ad
 
d80253f
 
 
 
b9b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d80253f
5c5d1c5
d80253f
b9b07ad
 
d80253f
8ee0a79
b9b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d80253f
b9b07ad
 
 
 
 
 
 
5c5d1c5
b9b07ad
 
 
 
 
 
 
 
d80253f
b9b07ad
 
 
 
d80253f
 
 
5c5d1c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddab483
5c5d1c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d80253f
 
4cd1e41
 
 
b9b07ad
d80253f
4cd1e41
 
 
b9b07ad
4cd1e41
 
b9b07ad
 
4cd1e41
b9b07ad
4cd1e41
b9b07ad
 
4cd1e41
b9b07ad
 
4cd1e41
 
d80253f
b9b07ad
5c5d1c5
 
 
 
 
 
d80253f
 
 
 
5c5d1c5
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from dataclasses import dataclass

import gradio as gr
from graphql_calls import get_tag_commit_date, get_commits


@dataclass
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[::-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_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(
    title='Automatic release notes 🤗',
    article=article,
    description="**See instructions below the form.**",
    fn=get_release_notes,
    inputs=[
        gr.components.Textbox(lines=1, placeholder="Your GitHub token"),
        gr.components.Textbox(
            lines=1, placeholder="Repository", value="huggingface/transformers"
        ),
        gr.components.Textbox(lines=1, 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="main",
        ),
        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",
    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],
    ],
)


if __name__ == "__main__":
    demo.launch(show_error=True)