Skip to content

Instantly share code, notes, and snippets.

@fricklerhandwerk
Created February 9, 2024 07:03
Show Gist options
  • Save fricklerhandwerk/723de760cd8a943d40c9a175d03a0d4f to your computer and use it in GitHub Desktop.
Save fricklerhandwerk/723de760cd8a943d40c9a175d03a0d4f to your computer and use it in GitHub Desktop.
Scripts to obtain raw data on Nix maintenance activities

Show all merged pull requests

gh pr list --state merged --search "NOT Backport merged:2023-04-01..2024-01-08" --json number,title --jq '.[] |  "- [#\( .number )](https://github.com/NixOS/nix/pull/\( .number )) \( .title )"' --limit 1000 | sort

Show merged pull requests by selected labels (categories will have overlap)

for label in bug tests documentation UX error-messages performance contributor-experience build-problem new-cli installer language process feature; do echo -e "\n## [$label](https://github.com/NixOS/nix/issues?q=is%3Amerged+label%3A$label+merged%3A2023-03-31..2024-01-08+)\n"; gh pr list --state merged --label "$label" --search "NOT Backport merged:2023-04-01..2024-01-08" --json number,title --jq '.[] |  "- [#\( .number )](https://github.com/NixOS/nix/pull/\( .number )) \( .title )"' --limit 500 | sort

Show closed issues

gh issue list --state closed --search "closed:2023-04-01..2024-01-08" --json number,title --jq '.[] | "- [#\( .number )](https://github.com/NixOS/nix/issues/\( .number )) \( .title )"' --limit 500 | sort

List authors of merged pull requests

gh pr list --state merged --search "merged:2023-04-01..2024-01-08" --json author --jq '.[] | .author.login' --limit 1000 | sort -u

List everyone involved in closed issues

#!/bin/bash

START_DATE="2023-04-01"
END_DATE="2024-01-08"

issues=$(gh issue list --state closed --search "closed:$START_DATE..$END_DATE" --json number,author --jq '.[] | {number: .number, author: .author.login}' --limit 1000)

get_commenters() {
    issue=$1
    echo "https://github.com/NixOS/nix/issues/$issue" >&2
    gh issue view $issue --json comments --jq '.comments[].user.login'
}

export -f get_commenters

{
    echo "$issues" | jq -r '.author'
    echo "$issues" | jq -r '.number' | xargs -I {} -P 10 -n 1 bash -c 'get_commenters "$@"' _ {}
} | grep -v '^$' | sort -u

List new and regular contributors

#!/bin/bash

export START_DATE="2023-04-01"
export END_DATE="2024-01-08"

contributors=$(gh pr list --state merged --search "merged:$START_DATE..$END_DATE" --json author --limit 1000 --jq '.[].author.login' | sort -u)

temp_new=$(mktemp)
temp_regular=$(mktemp)

cleanup() {
    rm -f "$temp_new" "$temp_regular"
}

trap cleanup EXIT

process_contributor() {
    contributor=$1
    first_pr_date=$(gh pr list --author "$contributor" --state merged --limit 1000 --json mergedAt --jq '.[].mergedAt' | sort | head -n 1 | cut -c 1-10)
    pr_count=$(gh pr list --author "$contributor" --state merged --search "merged:$START_DATE..$END_DATE" --limit 1000 --json number | jq 'length')

    echo "- @$contributor ($pr_count)" >&2

    if [[ "$first_pr_date" > "$START_DATE" ]]; then
        echo "- @$contributor ($pr_count)" >> "$temp_new"
    elif [[ "$pr_count" -gt 0 ]]; then
        echo "- @$contributor ($pr_count)" >> "$temp_regular"
    fi
}

export -f process_contributor
export temp_new
export temp_regular

echo "$contributors" | xargs -I {} -P 10 -n 1 bash -c 'process_contributor "$@"' _ {}

echo "# New Contributors"
cat "$temp_new" | sort -t '(' -k 2,2nr
echo
echo "# Regulars"
cat "$temp_regular" | sort -t '(' -k 2,2nr

Get list and count of issues and pull requests per assignee

#!/bin/bash

org_name="NixOS"
team_name="nix-team"
GH_TOKEN=$(gh auth token)

team_members=$(curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/orgs/$org_name/teams/$team_name/members" | jq -r '.[].login')

declare -A assignee_data

for assignee in $team_members; do
    issues=$(gh search issues --include-prs --repo=NixOS/nix --assignee=$assignee --state=open --limit=200 --json number,title)
    count=$(echo "$issues" | jq 'length')
    assignee_data["$assignee,$count"]=$(echo "$issues" | jq -r '.[] | "- [#\( .number )](https://github.com/NixOS/nix/issues/\( .number )) \( .title )"')
done

for key in $(printf "%s\n" "${!assignee_data[@]}" | sort -t, -k2 -nr); do
    IFS=',' read -r assignee count <<< "$key"
    echo "<details><summary><a href=\"https://github.com/NixOS/nix/issues?q=is%3Aopen+assignee%3A$assignee\">@$assignee: $count</a></summary>"
    echo
    echo "${assignee_data[$key]}"
    echo
    echo "</details>"
    echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment