-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlibrary_usage.py
More file actions
146 lines (117 loc) · 3.57 KB
/
library_usage.py
File metadata and controls
146 lines (117 loc) · 3.57 KB
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
143
144
145
146
"""Example of using pretty_release_notes as a library."""
from pathlib import Path
from pretty_release_notes import ProgressEvent, ProgressReporter, ReleaseNotesBuilder
class CustomProgressReporter(ProgressReporter):
"""Custom progress reporter that logs to console."""
def report(self, event: ProgressEvent) -> None:
print(f"[{event.type.upper()}] {event.message[:100]}")
# Example 1: Basic usage with minimal configuration
def basic_usage():
"""Generate release notes with minimal configuration."""
client = (
ReleaseNotesBuilder()
.with_github_token("ghp_xxxxx") # Replace with your token
.with_llm("sk-xxxxx") # Replace with your API key
.build()
)
notes = client.generate_release_notes(
owner="frappe",
repo="erpnext",
tag="v15.38.4",
)
print(notes)
# Example 2: Advanced usage with custom configuration
def advanced_usage():
"""Generate release notes with custom filters and progress reporting."""
client = (
ReleaseNotesBuilder()
.with_github_token("ghp_xxxxx") # Replace with your token
.with_llm(
"sk-xxxxx",
model="openai:gpt-4.1",
max_patch_size=15000,
reasoning_effort="medium",
)
.with_database("sqlite", enabled=True)
.with_filters(
exclude_types={"chore", "refactor", "ci", "style", "test"},
exclude_labels={"skip-release-notes"},
exclude_authors={"dependabot[bot]", "github-actions[bot]"},
)
.with_prompt_file(Path("custom_prompt.txt"))
.with_force_commits(False)
.with_progress_reporter(CustomProgressReporter())
.build()
)
notes = client.generate_release_notes(
owner="frappe",
repo="erpnext",
tag="v15.38.4",
)
print(notes)
# Optionally update GitHub release
# client.update_github_release("frappe", "erpnext", "v15.38.4", notes)
# Example 3: Direct configuration (without builder)
def direct_config_usage():
"""Generate release notes using direct configuration."""
from pretty_release_notes import (
DatabaseConfig,
FilterConfig,
GitHubConfig,
LLMConfig,
ReleaseNotesClient,
ReleaseNotesConfig,
)
config = ReleaseNotesConfig(
github=GitHubConfig(token="ghp_xxxxx"), # Replace with your token
llm=LLMConfig(
api_key="sk-xxxxx",
model="openai:gpt-4.1",
reasoning_effort="medium",
), # Replace with your key
database=DatabaseConfig(type="sqlite", enabled=True),
filters=FilterConfig(
exclude_change_types={"chore", "refactor"},
exclude_change_labels={"skip-release-notes"},
),
)
client = ReleaseNotesClient(config, progress_reporter=CustomProgressReporter())
notes = client.generate_release_notes(
owner="frappe",
repo="erpnext",
tag="v15.38.4",
)
print(notes)
# Example 4: Silent operation (no progress reporting)
def silent_usage():
"""Generate release notes without any progress output."""
client = (
ReleaseNotesBuilder()
.with_github_token("ghp_xxxxx") # Replace with your token
.with_llm("sk-xxxxx") # Replace with your API key
.build()
) # No progress reporter = NullProgressReporter used by default
return client.generate_release_notes(
owner="frappe",
repo="erpnext",
tag="v15.38.4",
)
if __name__ == "__main__":
print("Example 1: Basic Usage")
print("=" * 80)
# Uncomment to run:
# basic_usage()
print("\nExample 2: Advanced Usage with Custom Configuration")
print("=" * 80)
# Uncomment to run:
# advanced_usage()
print("\nExample 3: Direct Configuration")
print("=" * 80)
# Uncomment to run:
# direct_config_usage()
print("\nExample 4: Silent Operation")
print("=" * 80)
# Uncomment to run:
# result = silent_usage()
# print(result)
print("\nReplace 'ghp_xxxxx' and 'sk-xxxxx' with valid tokens to run these examples.")