nur-packages

My NUR packages
git clone git://git.sikmir.ru/nur-packages
Log | Files | Refs | README | LICENSE

update-commit-dates.sh (1243B)


      1 #!/usr/bin/env nix-shell
      2 #! nix-shell -i bash -p curl jq moreutils
      3 
      4 # heredoc variables
      5 typeset \
      6   commit_dates_filter='' \
      7   commit_dates_query='' \
      8 
      9 
     10 IFS='' read -r -d '' commit_dates_query <<'EOF' # vim:ft=jq
     11 def repoField($alias):
     12   "\($alias): repository(owner: \(.owner | @json), name: \(.repo | @json)) { " +
     13     "object(expression: \(.rev | @json)) { ...go } }";
     14 
     15 def build_query:
     16 "fragment go on GitObject { ... on Commit { committedDate } }
     17 
     18 query CommitDates {
     19   " + (map(.key as $alias | .value |
     20     select(has("owner") and has("repo")) |
     21       repoField($alias | gsub("-"; "_"))
     22   ) | join("\n  ")) + "
     23 }";
     24 
     25 { query: to_entries | build_query }
     26 EOF
     27 
     28 IFS='' read -r -d '' commit_dates_filter <<'EOF' # vim:ft=jq
     29 .data | with_entries(
     30   .key |= gsub("_"; "-") |
     31   .value |= { date: .object.committedDate }
     32 ) as $overrides | $sources[] * $overrides
     33 EOF
     34 
     35 set -o errexit -o errtrace -o nounset -o pipefail
     36 shopt -s inherit_errexit
     37 
     38 curl 'https://api.github.com/graphql' \
     39     -H "Authorization: bearer $GITHUB_TOKEN" \
     40     --data-binary "$(jq "${commit_dates_query}" nix/sources.json)" | \
     41   jq -S --indent 4 "${commit_dates_filter}" \
     42     --slurpfile sources nix/sources.json | \
     43   sponge nix/sources.json
     44 
     45 # vim:et:ft=sh:sw=2:tw=78