try old device endpoint #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Temp Docflow API | |
| on: | |
| push: | |
| branches: ['temp-docflow-*'] | |
| permissions: | |
| contents: write | |
| jobs: | |
| device: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Start device flow via API commit | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| BRANCH: ${{ github.ref_name }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| python3 - <<'PY' | |
| import os, requests, json, time, base64, datetime | |
| repo=os.environ['REPO']; branch=os.environ['BRANCH']; gh=os.environ['GH_TOKEN'] | |
| H={'Authorization':'Bearer '+gh,'Accept':'application/vnd.github+json','X-GitHub-Api-Version':'2022-11-28'} | |
| def put(path, obj, msg): | |
| url=f'https://api.github.com/repos/{repo}/contents/{path}' | |
| old=requests.get(url,headers=H,params={'ref':branch}) | |
| payload={'message':msg,'content':base64.b64encode(json.dumps(obj,indent=2).encode()).decode(),'branch':branch} | |
| if old.status_code==200: payload['sha']=old.json()['sha'] | |
| rr=requests.put(url,headers=H,json=payload,timeout=30) | |
| print('PUT', path, rr.status_code, rr.text[:200]) | |
| try: | |
| cid='32555940559.apps.googleusercontent.com'; secret='ZmssLNjJy2998hD4CTg2ejr2' | |
| scope='https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/documents' | |
| r=requests.post('https://accounts.google.com/o/oauth2/device/code', data={'client_id':cid,'scope':scope}, timeout=30) | |
| d=r.json(); d['started_at']=datetime.datetime.utcnow().isoformat()+'Z'; d.pop('device_code',None) | |
| put('tmp_docflow/device.json', d, 'docflow device info') | |
| except Exception as e: | |
| put('tmp_docflow/error.json', {'error':repr(e)}, 'docflow error') | |
| raise | |
| PY |