From a8919f9c01ec4ece1cef8a08f3d6df32d616ea95 Mon Sep 17 00:00:00 2001 From: Douglas <32344964+NotTheDr01ds@users.noreply.github.com> Date: Mon, 17 Feb 2025 12:59:52 -0500 Subject: [PATCH] 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. --- make_release/this_week_in_nu_weekly.nu | 105 ++++++++++++++++++------- 1 file changed, 75 insertions(+), 30 deletions(-) diff --git a/make_release/this_week_in_nu_weekly.nu b/make_release/this_week_in_nu_weekly.nu index 16119db..9ffed5a 100644 --- a/make_release/this_week_in_nu_weekly.nu +++ b/make_release/this_week_in_nu_weekly.nu @@ -3,35 +3,74 @@ # Repos to monitor def query-week-span [] { - let site_table = [ - [site repo]; - [Nushell nushell] - [Extension vscode-nushell-lang] - [Documentation nushell.github.io] - [Wasm demo] - [Nu_Scripts nu_scripts] - [RFCs rfcs] - [reedline reedline] - [Nana nana] - # ] [Jupyter jupyter] - ] + # Update the '7' below to however many days it has been since the last TWiN + let query_date = (seq date --days 21 -r | get 7) - let query_prefix = "https://api.github.com/search/issues?q=repo:nushell/" - let query_date = (seq date --days 7 -r | get 6) - let per_page = "100" - let page_num = "1" # need to implement iterating pages - let colon = "%3A" - let gt = "%3E" - let eq = "%3D" - let amp = "%26" - let query_suffix = $"+is($colon)pr+is($colon)merged+merged($colon)($gt)($eq)($query_date)&per_page=100&page=1" + # The heading mappings for each repository. This is only + # used to display the Heading for each reposting in TWiN. + # Repos without a mapping (that have activity) will simply + # default to the repo name. + let repo_headings = { + nushell: Nushell + nushell.github.io: Documentation + reedline: reedline + 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 { - let query_string = $"($query_prefix)($repo.repo)($query_suffix)" - let site_json = (http get -u $env.GITHUB_USERNAME -p $env.GITHUB_PASSWORD $query_string | get items | select html_url user.login title) + # If environment variables exists for GH username/pw, use + # them. If a token is available, it will take precedence, + # 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 }) { - 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) { 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 week_num = ((seq date -b '2019-08-23' -n 7 | length) - 1) -print $"# This week in Nushell #($week_num)(char nl)" +let has_token = (try { gh auth token }) != null +let has_username_pw = ($env | get -i GITHUB_USERNAME | is-not-empty) and ($env | get -i GITHUB_PASSWORD | is-not-empty) -if ($env | get -i GITHUB_USERNAME | is-empty) or ($env | get -i GITHUB_PASSWORD | is-empty) { - print 'Please set GITHUB_USERNAME and GITHUB_PASSWORD in $env to use this script' +if not ($has_token or $has_username_pw) { + 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 { + # 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 } +