From e16906afc39cd2d6dac5eb660ca8f2035c6145c8 Mon Sep 17 00:00:00 2001 From: "Acid Chicken (硫酸鶏)" Date: Mon, 10 Dec 2018 23:22:52 +0900 Subject: Refactor /.autogen (#3551) * Create patreon.jq * Create check_pr.jq * Rename check_pr.jq to .autogen/check_pr.jq * Create next_url.jq * Update autogen.sh * Rename autogen.sh to update_readme_patreon.sh --- .autogen/autogen.sh | 87 --------------------------------------- .autogen/check_pr.jq | 3 ++ .autogen/next_url.jq | 2 + .autogen/patreon.jq | 39 ++++++++++++++++++ .autogen/update_readme_patreon.sh | 87 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 87 deletions(-) delete mode 100755 .autogen/autogen.sh create mode 100644 .autogen/check_pr.jq create mode 100644 .autogen/next_url.jq create mode 100644 .autogen/patreon.jq create mode 100755 .autogen/update_readme_patreon.sh diff --git a/.autogen/autogen.sh b/.autogen/autogen.sh deleted file mode 100755 index 30198f8048..0000000000 --- a/.autogen/autogen.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env bash -# __MISSKEY_BEARER_TOKEN= -# __MISSKEY_CAMPAIGN_ID= -# __MISSKEY_GITHUB_TOKEN= -# __MISSKEY_HEAD=acid-chicken:patch-autogen -# __MISSKEY_REPO=syuilo/misskey -# __MISSKEY_BRANCH=develop -test "$(curl -LSs -w '\n' -- "https://api.github.com/repos/$REPO/pulls?access_token=$__MISSKEY_GITHUB_TOKEN" | jq -r '.[].head.label' | grep $__MISSKEY_HEAD)" && exit 1 -cd "$(dirname $0)/.." && \ -touch null.cache && \ -rm *.cache && \ -git checkout $__MISSKEY_BRANCH && \ -git pull origin $__MISSKEY_BRANCH && \ -git pull upstream $__MISSKEY_BRANCH && \ -git stash && \ -git rebase -f upstream/$__MISSKEY_BRANCH && \ -git branch patch-autogen && \ -git checkout patch-autogen && \ -git reset --hard HEAD || \ -exit 1 -touch patreon.md.cache && \ -rm patreon.md.cache && \ -echo '' > patreon.md.cache && \ -url="https://www.patreon.com/api/oauth2/v2/campaigns/$__MISSKEY_CAMPAIGN_ID/members?include=currently_entitled_tiers,user&fields%5Btier%5D=title&fields%5Buser%5D=full_name,thumb_url,url,hide_pledges" -while : - do - touch patreon.raw.cache && \ - rm patreon.raw.cache && \ - curl -LSs -w '\n' -H "Authorization: Bearer $__MISSKEY_BEARER_TOKEN" -- $url > patreon.raw.cache && \ - touch patreon.cache && \ - rm patreon.cache && \ - cat patreon.raw.cache | \ - jq -r '(.data|map(select(.relationships.currently_entitled_tiers.data[]))|map(.relationships.user.data.id))as$data|.included|map(select(.id as$id|$data|contains([$id])))|map(.attributes|[.full_name,.thumb_url,.url]|@tsv)|.[]|@text' >> patreon.cache && \ - echo '' >> patreon.md.cache && \ - cat patreon.cache | \ - awk -F'\t' '{print $2,$1}' | \ - sed -e 's/ /\\" alt=\\"/' | \ - xargs -I% echo '' >> patreon.md.cache && \ - echo '' >> patreon.md.cache && \ - cat patreon.cache | \ - awk -F'\t' '{print $3,$1}' | \ - sed -e 's/ /\\">/' | \ - xargs -I% echo '
" >> patreon.md.cache && \ -touch README.md && \ -touch .autogen/README.md && \ -rm .autogen/README.md && \ -mv README.md .autogen/README.md && \ -cat .autogen/README.md | while IFS= read line; - do - if [[ -z "$ignore" ]] - then - if [[ "$line" = '' ]] - then - ignore='PATREON_INSIDE' - else - echo "$line" >> README.md - fi - else - if [[ "$LINE" = '' ]] - then - ignore= - cat patreon.md.cache >> README.md - fi - fi -done -cat patreon.md.cache -touch null.cache && \ -rm *.cache && \ -diff .autogen/README.md README.md > diff.cache -cat diff.cache && \ -test 4 -lt $(cat diff.cache | wc -l) && \ -git add README.md && \ -git commit -m 'Update README.md [AUTOGEN]' && \ -git push -f origin patch-autogen && \ -curl -LSs -w '\n' -X POST -d '{"title":"[AUTOMATED] Update README.md","body":"*This pull request was created by a tool.*","head":"'$__MISSKEY_HEAD'","base":"'$__MISSKEY_BRANCH'"}' -- "https://api.github.com/repos/$__MISSKEY_REPO/pulls?access_token=$__MISSKEY_GITHUB_TOKEN" -git stash -git checkout $__MISSKEY_BRANCH -git branch -D patch-autogen diff --git a/.autogen/check_pr.jq b/.autogen/check_pr.jq new file mode 100644 index 0000000000..0adb0b503d --- /dev/null +++ b/.autogen/check_pr.jq @@ -0,0 +1,3 @@ +.[] +.head +.label diff --git a/.autogen/next_url.jq b/.autogen/next_url.jq new file mode 100644 index 0000000000..b4c3b819a5 --- /dev/null +++ b/.autogen/next_url.jq @@ -0,0 +1,2 @@ +.links +.next diff --git a/.autogen/patreon.jq b/.autogen/patreon.jq new file mode 100644 index 0000000000..c761d587b8 --- /dev/null +++ b/.autogen/patreon.jq @@ -0,0 +1,39 @@ +( + .data | + map( + select( + .relationships + .currently_entitled_tiers + .data[] + ) + ) | + map( + .relationships + .user + .data + .id + ) +) as $data | +.included | +map( + select( + .id as $id | + $data | + contains( + [ + $id + ] + ) + ) +) | +map( + .attributes | + [ + .full_name, + .thumb_url, + .url + ] | + @tsv +) | +.[] | +@text diff --git a/.autogen/update_readme_patreon.sh b/.autogen/update_readme_patreon.sh new file mode 100755 index 0000000000..8f40a78991 --- /dev/null +++ b/.autogen/update_readme_patreon.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +# __MISSKEY_BEARER_TOKEN= +# __MISSKEY_CAMPAIGN_ID= +# __MISSKEY_GITHUB_TOKEN= +# __MISSKEY_HEAD=acid-chicken:patch-autogen +# __MISSKEY_REPO=syuilo/misskey +# __MISSKEY_BRANCH=develop +test "$(curl -LSs -w '\n' -- "https://api.github.com/repos/$REPO/pulls?access_token=$__MISSKEY_GITHUB_TOKEN" | jq -r -f check_pr.jq | grep $__MISSKEY_HEAD)" && exit 1 +cd "$(dirname $0)/.." && \ +touch null.cache && \ +rm *.cache && \ +git checkout $__MISSKEY_BRANCH && \ +git pull origin $__MISSKEY_BRANCH && \ +git pull upstream $__MISSKEY_BRANCH && \ +git stash && \ +git rebase -f upstream/$__MISSKEY_BRANCH && \ +git branch patch-autogen && \ +git checkout patch-autogen && \ +git reset --hard HEAD || \ +exit 1 +touch patreon.md.cache && \ +rm patreon.md.cache && \ +echo '' > patreon.md.cache && \ +url="https://www.patreon.com/api/oauth2/v2/campaigns/$__MISSKEY_CAMPAIGN_ID/members?include=currently_entitled_tiers,user&fields%5Btier%5D=title&fields%5Buser%5D=full_name,thumb_url,url,hide_pledges" +while : + do + touch patreon.raw.cache && \ + rm patreon.raw.cache && \ + curl -LSs -w '\n' -H "Authorization: Bearer $__MISSKEY_BEARER_TOKEN" -- $url > patreon.raw.cache && \ + touch patreon.cache && \ + rm patreon.cache && \ + cat patreon.raw.cache | \ + jq -r -f patreon.jq >> patreon.cache && \ + echo '' >> patreon.md.cache && \ + cat patreon.cache | \ + awk -F'\t' '{print $2,$1}' | \ + sed -e 's/ /\\" alt=\\"/' | \ + xargs -I% echo '' >> patreon.md.cache && \ + echo '' >> patreon.md.cache && \ + cat patreon.cache | \ + awk -F'\t' '{print $3,$1}' | \ + sed -e 's/ /\\">/' | \ + xargs -I% echo '
" >> patreon.md.cache && \ +touch README.md && \ +touch .autogen/README.md && \ +rm .autogen/README.md && \ +mv README.md .autogen/README.md && \ +cat .autogen/README.md | while IFS= read line; + do + if [[ -z "$ignore" ]] + then + if [[ "$line" = '' ]] + then + ignore='PATREON_INSIDE' + else + echo "$line" >> README.md + fi + else + if [[ "$LINE" = '' ]] + then + ignore= + cat patreon.md.cache >> README.md + fi + fi +done +cat patreon.md.cache +touch null.cache && \ +rm *.cache && \ +diff .autogen/README.md README.md > diff.cache +cat diff.cache && \ +test 4 -lt $(cat diff.cache | wc -l) && \ +git add README.md && \ +git commit -m 'Update README.md [AUTOGEN]' && \ +git push -f origin patch-autogen && \ +curl -LSs -w '\n' -X POST -d '{"title":"[AUTOMATED] Update README.md","body":"*This pull request was created by a tool.*","head":"'$__MISSKEY_HEAD'","base":"'$__MISSKEY_BRANCH'"}' -- "https://api.github.com/repos/$__MISSKEY_REPO/pulls?access_token=$__MISSKEY_GITHUB_TOKEN" +git stash +git checkout $__MISSKEY_BRANCH +git branch -D patch-autogen -- cgit v1.2.3-freya