mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Update TWiN script (#1047)
* Retrieves previous 7 days of contributions by default * Checks all repos under the `nushell` user - Reports against the most recent (up to 30, and we currently only have 26) with updates. * Uses the GitHub client to authenticate if available, with fallback to a token, then username/password * Cleans up a lot of the URL building using more recent Nushell commands.
This commit is contained in:
parent
c17dcc3855
commit
a8919f9c01
1 changed files with 75 additions and 30 deletions
|
@ -3,35 +3,74 @@
|
||||||
# Repos to monitor
|
# Repos to monitor
|
||||||
|
|
||||||
def query-week-span [] {
|
def query-week-span [] {
|
||||||
let site_table = [
|
# Update the '7' below to however many days it has been since the last TWiN
|
||||||
[site repo];
|
let query_date = (seq date --days 21 -r | get 7)
|
||||||
[Nushell nushell]
|
|
||||||
[Extension vscode-nushell-lang]
|
|
||||||
[Documentation nushell.github.io]
|
|
||||||
[Wasm demo]
|
|
||||||
[Nu_Scripts nu_scripts]
|
|
||||||
[RFCs rfcs]
|
|
||||||
[reedline reedline]
|
|
||||||
[Nana nana]
|
|
||||||
# ] [Jupyter jupyter]
|
|
||||||
]
|
|
||||||
|
|
||||||
let query_prefix = "https://api.github.com/search/issues?q=repo:nushell/"
|
# The heading mappings for each repository. This is only
|
||||||
let query_date = (seq date --days 7 -r | get 6)
|
# used to display the Heading for each reposting in TWiN.
|
||||||
let per_page = "100"
|
# Repos without a mapping (that have activity) will simply
|
||||||
let page_num = "1" # need to implement iterating pages
|
# default to the repo name.
|
||||||
let colon = "%3A"
|
let repo_headings = {
|
||||||
let gt = "%3E"
|
nushell: Nushell
|
||||||
let eq = "%3D"
|
nushell.github.io: Documentation
|
||||||
let amp = "%26"
|
reedline: reedline
|
||||||
let query_suffix = $"+is($colon)pr+is($colon)merged+merged($colon)($gt)($eq)($query_date)&per_page=100&page=1"
|
nu_scripts: Nu_Scripts
|
||||||
|
nupm: NUPM
|
||||||
|
demo: Wasm
|
||||||
|
nufmt: nufmt
|
||||||
|
awesome-nu: "Awesome Nu"
|
||||||
|
tree-sitter-nu: Tree-sitter
|
||||||
|
new-nu-parser: "New nu-parser"
|
||||||
|
rfcs: RFCs
|
||||||
|
nana: Nana
|
||||||
|
integrations: Integrations
|
||||||
|
vscode-nushell-lang: "VSCode Extension"
|
||||||
|
nu_plugin_template: "Plugin Template"
|
||||||
|
grammar: Grammar
|
||||||
|
nu_jupyter: Jupyter
|
||||||
|
}
|
||||||
|
|
||||||
for repo in $site_table {
|
# If environment variables exists for GH username/pw, use
|
||||||
let query_string = $"($query_prefix)($repo.repo)($query_suffix)"
|
# them. If a token is available, it will take precedence,
|
||||||
let site_json = (http get -u $env.GITHUB_USERNAME -p $env.GITHUB_PASSWORD $query_string | get items | select html_url user.login title)
|
# so passing an empty username/password isn't a problem.
|
||||||
|
let gh_username = ($env.GITHUB_USERNAME? | default "")
|
||||||
|
let gh_password = ($env.GITHUB_PASSWORD? | default "")
|
||||||
|
let gh_token = $env.GH_AUTH_TOKEN? | default (try { gh auth token })
|
||||||
|
let headers = match $gh_token {
|
||||||
|
null => {}
|
||||||
|
_ => { Authorization: $'Bearer ($gh_token)' }
|
||||||
|
}
|
||||||
|
|
||||||
|
let repos = (
|
||||||
|
http get -H $headers -u $gh_username -p $gh_password https://api.github.com/users/nushell/repos?sort=pushed
|
||||||
|
| get name
|
||||||
|
| where $it != 'nightly'
|
||||||
|
| where $it != 'this_week_in_nu'
|
||||||
|
| first 30
|
||||||
|
)
|
||||||
|
|
||||||
|
for repo in $repos {
|
||||||
|
let query_string = (
|
||||||
|
$"https://api.github.com/search/issues"
|
||||||
|
| url parse
|
||||||
|
| merge {
|
||||||
|
params: {
|
||||||
|
q: $'repo:nushell/($repo) is:pr is:merged merged:>=($query_date)'
|
||||||
|
page: 1
|
||||||
|
per_page: 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| url join
|
||||||
|
)
|
||||||
|
let site_json = (
|
||||||
|
http get -H $headers -u $gh_username -p $gh_password $query_string
|
||||||
|
| get items
|
||||||
|
| select html_url user.login title
|
||||||
|
)
|
||||||
|
|
||||||
if not ($site_json | all { |it| $it | is-empty }) {
|
if not ($site_json | all { |it| $it | is-empty }) {
|
||||||
print $"(char nl)## ($repo.site)(char nl)"
|
let heading_name = ($repo_headings | get -i $repo | default $repo)
|
||||||
|
print $"(char nl)## ($heading_name)(char nl)"
|
||||||
|
|
||||||
for user in ($site_json | group-by "user.login" | transpose user prs) {
|
for user in ($site_json | group-by "user.login" | transpose user prs) {
|
||||||
let user_name = $user.user
|
let user_name = $user.user
|
||||||
|
@ -52,12 +91,18 @@ def query-week-span [] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 2019-08-23 was the release of 0.2.0, the first public release
|
let has_token = (try { gh auth token }) != null
|
||||||
let week_num = ((seq date -b '2019-08-23' -n 7 | length) - 1)
|
let has_username_pw = ($env | get -i GITHUB_USERNAME | is-not-empty) and ($env | get -i GITHUB_PASSWORD | is-not-empty)
|
||||||
print $"# This week in Nushell #($week_num)(char nl)"
|
|
||||||
|
|
||||||
if ($env | get -i GITHUB_USERNAME | is-empty) or ($env | get -i GITHUB_PASSWORD | is-empty) {
|
if not ($has_token or $has_username_pw) {
|
||||||
print 'Please set GITHUB_USERNAME and GITHUB_PASSWORD in $env to use this script'
|
print "This script requires either a working GitHub client that returns `gh auth token` or"
|
||||||
|
print "$env.GITHUB_USERNAME and $env.GITHUB_PASSWORD. Neither were found."
|
||||||
} else {
|
} else {
|
||||||
|
# 2019-08-23 was the release of 0.2.0, the first public release
|
||||||
|
|
||||||
|
let week_num = ((seq date -b '2019-08-23' -n 7 | length) - 1)
|
||||||
|
print $"# This week in Nushell #($week_num)(char nl)"
|
||||||
|
|
||||||
query-week-span
|
query-week-span
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue