Skip to content

Commit 9895dad

Browse files
authored
Update TWiN generation scripts (#1162)
Pretty much (another) complete rewrite of the TWiN generation script. This one requires `gh` exclusively and does not use the REST API directly. The big benefit in this rewrite is the automatic calculation of which PRs should be included. Each week, PRs from Friday through Thursday are included. The issue will usually, hopefully be generated on a Friday. However, previously the script could return duplicate PRs, especially when run later (like Saturday, or a few months later ...). Issue numbers can now be generated, so if a week is missed, you can: ```nushell source this_week_in_nu_weekly.nu generate-twin --issue-number 311 ``` The output is now a Nushell string, rather than a `print` result which could not be easily captured. --- This also included a new script `twin-tweaks.nu` which will pass a TWiN created via the above `generate-twin` command into DeepSeak (via OpenRouter.AI) and tweak the results to provide more natural wording to the PRs. For instance, a PR named: * Add foo Will become: * @userbar: - Added foo This requires a valid account with openrouter.ai, which does need a few $ in it to work against. However, the actual tweak script only takes ~ $0.03 per run.
1 parent a0f5105 commit 9895dad

File tree

2 files changed

+95
-66
lines changed

2 files changed

+95
-66
lines changed
Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# http get https://api.github.com/repos/nushell/nushell/pulls?q=is%3Apr+merged%3A%3E%3D2021-04-20+ | select html_url user.login title body
2-
# http get https://api.github.com/search/issues?q=repo:nushell/nushell+is:pr+is:merged+merged:%3E2021-05-08 | get items | select html_url user.login title body
3-
# Repos to monitor
1+
use std-rfc/str
42

5-
def query-week-span [] {
6-
# Update the '7' below to however many days it has been since the last TWiN
7-
let query_date = (seq date --days 21 -r | get 7)
3+
def generate-twin [
4+
--issue-number (-i): int
5+
] {
6+
let issue_number = $issue_number | default ((date now) - 2019-08-23 | $in / 7day | math floor)
7+
let end_date = 2019-08-23 + ($issue_number * 7day) - 1day
8+
let begin_date = ($end_date - 6day)
9+
let search_string = $"is:pr is:merged merged:($begin_date | format date '%Y-%m-%d')..($end_date | format date '%Y-%m-%d')"
810

911
# The heading mappings for each repository. This is only
1012
# used to display the Heading for each reposting in TWiN.
@@ -30,79 +32,66 @@ def query-week-span [] {
3032
nu_jupyter: Jupyter
3133
}
3234

33-
# If environment variables exists for GH username/pw, use
34-
# them. If a token is available, it will take precedence,
35-
# so passing an empty username/password isn't a problem.
36-
let gh_username = ($env.GITHUB_USERNAME? | default "")
37-
let gh_password = ($env.GITHUB_PASSWORD? | default "")
38-
let gh_token = $env.GH_AUTH_TOKEN? | default (try { gh auth token })
39-
let headers = match $gh_token {
40-
null => {}
41-
_ => { Authorization: $'Bearer ($gh_token)' }
42-
}
43-
4435
let repos = (
45-
http get -H $headers -u $gh_username -p $gh_password https://api.github.com/users/nushell/repos?sort=pushed
36+
gh repo list nushell --json name
37+
| from json
4638
| get name
4739
| where $it != 'nightly'
4840
| where $it != 'this_week_in_nu'
4941
| first 30
5042
)
5143

44+
mut twin_text = $"
45+
---
46+
title: 'This week in Nushell #($issue_number)'
47+
author: The Nu Authors
48+
author_site: https://nushell.sh
49+
author_image: https://www.nushell.sh/blog/images/nu_logo.png
50+
excerpt: \"PRs and activity for Nushell the week ending ($end_date | format date '%A, %Y-%m-%d')\"
51+
---
52+
53+
# This Week in Nushell #($issue_number)
54+
55+
Published (date now | format date '%A, %Y-%m-%d'), including PRs merged ($begin_date | format date '%A, %Y-%m-%d') through ($end_date | format date '%A, %Y-%m-%d').
56+
57+
" | str dedent
58+
59+
5260
for repo in $repos {
53-
let query_string = (
54-
$"https://api.github.com/search/issues"
55-
| url parse
56-
| merge {
57-
params: {
58-
q: $'repo:nushell/($repo) is:pr is:merged merged:>=($query_date)'
59-
page: 1
60-
per_page: 100
61-
}
62-
}
63-
| url join
64-
)
65-
let site_json = (
66-
http get -H $headers -u $gh_username -p $gh_password $query_string
67-
| get items
68-
| select html_url user.login title
61+
let prs = (
62+
gh pr list --search $search_string --repo $"nushell/($repo)" --json title,author,url,number
63+
| from json
64+
| select author.login title url number
65+
| rename author title url number
66+
| group-by author
67+
| transpose user prs
6968
)
7069

71-
if not ($site_json | all { |it| $it | is-empty }) {
72-
let heading_name = ($repo_headings | get -o $repo | default $repo)
73-
print $"(char nl)## ($heading_name)(char nl)"
74-
75-
for user in ($site_json | group-by "user.login" | transpose user prs) {
76-
let user_name = $user.user
77-
let pr_count = ($user.prs | length)
78-
79-
print -n $"- ($user_name) created "
80-
for pr in ($user.prs | enumerate) {
81-
if $pr_count == ($pr.index + 1) {
82-
print -n $"[($pr.item.title)](char lparen)($pr.item.html_url)(char rparen)"
83-
} else {
84-
print -n $"[($pr.item.title)](char lparen)($pr.item.html_url)(char rparen), and "
85-
}
86-
}
70+
if ($prs | is-not-empty) {
71+
$twin_text += $"
8772
88-
print ""
89-
}
90-
}
91-
}
92-
}
9373
94-
let has_token = (try { gh auth token }) != null
95-
let has_username_pw = ($env | get -o GITHUB_USERNAME | is-not-empty) and ($env | get -o GITHUB_PASSWORD | is-not-empty)
74+
## ($repo_headings | get -o $repo | default $repo)
9675
97-
if not ($has_token or $has_username_pw) {
98-
print "This script requires either a working GitHub client that returns `gh auth token` or"
99-
print "$env.GITHUB_USERNAME and $env.GITHUB_PASSWORD. Neither were found."
100-
} else {
101-
# 2019-08-23 was the release of 0.2.0, the first public release
76+
" | str dedent
10277

103-
let week_num = ((seq date -b '2019-08-23' -n 7 | length) - 1)
104-
print $"# This week in Nushell #($week_num)(char nl)"
78+
for user in $prs {
79+
$twin_text += $"
10580
106-
query-week-span
107-
}
81+
* @($user.user):
82+
83+
" | str dedent
84+
85+
for pr in $user.prs {
86+
$twin_text += $"
87+
- [($pr.title) \(#($pr.number)]\)\(($pr.url)\)
88+
89+
" | str dedent
90+
}
91+
}
92+
93+
}
94+
}
10895

96+
$twin_text
97+
}

make_release/twin-tweaks.nu

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def "twin format" [filename] {
2+
use std/clip
3+
use std-rfc/str
4+
5+
{
6+
Authorization: $'Bearer (kv get -u OPENROUTER_API_KEY)'
7+
}
8+
| kv set headers
9+
10+
$"
11+
Rewrite the following auto-generated changelog so it's more natural. For example, change things like 'rgwood created [Bump dependencies...' to 'rgwood [bumped dependencies...'. Keep the inline links. Make sure to keep ALL original URLs! When returning the text, do not include any explaination of the change or the surrounding backticks around the result:
12+
13+
```
14+
(open --raw $filename)
15+
```
16+
"
17+
| str unindent
18+
| kv set prompt
19+
20+
{
21+
role: 'user'
22+
content: (kv drop prompt)
23+
}
24+
| kv set message
25+
26+
{
27+
model: 'deepseek/deepseek-chat-v3-0324'
28+
messages: [ (kv drop message) ]
29+
}
30+
| kv set body
31+
32+
http post -ef -t application/json -H (kv drop headers) https://openrouter.ai/api/v1/chat/completions (kv drop body)
33+
| kv set rewrite
34+
35+
kv drop rewrite
36+
| get body.choices.0.message.content
37+
| kv set rewrite_body
38+
39+
kv drop rewrite_body
40+
}

0 commit comments

Comments
 (0)