├── main.ml ├── .gitignore ├── dune ├── dune-project ├── release.sh ├── refresh.sh └── authorize.sh /main.ml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _opam/ 2 | _build/ 3 | .access-token 4 | .refresh-token 5 | -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (public_name minimal-release) 3 | (name main)) 4 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.17) 2 | 3 | (package 4 | (name minimal-release) 5 | (depends 6 | (ocaml (>= 5.2)))) 7 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | token=$(cat .access-token) 6 | 7 | echo Auth token is $token 8 | 9 | owner="Leonidas-from-XIV" 10 | repo="github-api-testing" 11 | ref="heads/main" 12 | 13 | url="https://api.github.com/repos/${owner}/${repo}/git/ref/${ref}" 14 | echo $url 15 | 16 | current_commit=$(curl -L \ 17 | -H "Accept: application/vnd.github+json" \ 18 | -H "Authorization: Bearer ${token}" \ 19 | -H "X-GitHub-Api-Version: 2022-11-28" \ 20 | "${url}") 21 | 22 | echo $current_commit | jq . 23 | -------------------------------------------------------------------------------- /refresh.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | client_id="Iv23lihr9zJsZwCzFOC2" 5 | grant_type="refresh_token" 6 | refresh_token=$(cat .refresh-token) 7 | 8 | access_token_response=$(curl -X POST https://github.com/login/oauth/access_token -d "client_id=${client_id}&grant_type=${grant_type}&refresh_token=${refresh_token}") 9 | echo $access_token_response 10 | 11 | access_token=$(echo $access_token_response | rg "access_token=([^&]+)" -or '$1') 12 | refresh_token=$(echo $access_token_response | rg "refresh_token=([^&]+)" -or '$1') 13 | 14 | echo "${access_token}" > .access-token 15 | echo "${refresh_token}" > .refresh-token 16 | -------------------------------------------------------------------------------- /authorize.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | client_id="Iv23lihr9zJsZwCzFOC2" 6 | device_code_response=$(curl -X POST https://github.com/login/device/code -d "client_id=${client_id}") 7 | echo $device_code_response 8 | 9 | function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } 10 | 11 | device_code=$(echo $device_code_response | rg "device_code=([-a-zA-Z0-9]+)" -or '$1') 12 | echo device code $device_code 13 | user_code=$(echo $device_code_response | rg "user_code=([-a-zA-Z0-9]*)" -or '$1') 14 | echo user code $user_code 15 | verification_uri=$(echo $device_code_response | rg "verification_uri=([^&]+)" -or '$1') 16 | verification_uri=$(urldecode $verification_uri) 17 | echo verification $verification_uri 18 | interval=$(echo $device_code_response | rg "interval=([0-9]+)" -or '$1') 19 | echo interval $interval 20 | 21 | echo "Enter \"${user_code}\" at the site that opens after you press enter" 22 | read 23 | xdg-open "${verification_uri}" 24 | 25 | echo "Press enter when done" 26 | read 27 | 28 | grant_type="urn:ietf:params:oauth:grant-type:device_code" 29 | access_token_response=$(curl -X POST https://github.com/login/oauth/access_token -d "client_id=${client_id}&device_code=${device_code}&grant_type=${grant_type}") 30 | echo $access_token_response 31 | access_token=$(echo $access_token_response | rg "access_token=([^&]+)" -or '$1') 32 | refresh_token=$(echo $access_token_response | rg "refresh_token=([^&]+)" -or '$1') 33 | 34 | echo "Access token is \"${access_token}\"" 35 | 36 | echo "${access_token}" > .access-token 37 | echo "${refresh_token}" > .refresh-token 38 | --------------------------------------------------------------------------------