CoolFace
Apppublic

LZ-SG/embedded-dev-tutorials

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
push_app.js57 linesDownload Raw Back to root
1const https = require('https');2const fs = require('fs');3 4const TOKEN = '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';5const REPO = 'SG06231219-boop/embedded-dev-tutorials';6const content = fs.readFileSync('app.py');7const b64 = content.toString('base64');8 9function ghReq(method, apiPath, body) {10  return new Promise((resolve, reject) => {11    const opts = {12      hostname: 'api.github.com',13      path: `/repos/${REPO}${apiPath}`,14      method,15      headers: {16        'Authorization': `token ${TOKEN}`,17        'Accept': 'application/vnd.github.v3+json',18        'User-Agent': 'push-script',19        'Content-Type': 'application/json'20      }21    };22    const req = https.request(opts, res => {23      let data = '';24      res.on('data', c => data += c);25      res.on('end', () => {26        try { resolve(JSON.parse(data)); }27        catch(e) { reject(new Error(`Parse error: ${data.slice(0,200)}`)); }28      });29    });30    req.on('error', reject);31    if (body) req.write(JSON.stringify(body));32    req.end();33  });34}35 36async function main() {37  console.log('Getting current SHA...');38  const info = await ghReq('GET', '/contents/app.py?ref=main', null);39  if (!info.sha) { console.error('No SHA found:', JSON.stringify(info).slice(0,300)); process.exit(1); }40  console.log('SHA:', info.sha.slice(0,7));41 42  console.log('Pushing app.py...');43  const result = await ghReq('PUT', '/contents/app.py', {44    message: 'chore: bump version to 1.5.0',45    content: b64,46    sha: info.sha,47    branch: 'main'48  });49  if (result.commit) {50    console.log('SUCCESS! Commit:', result.commit.sha.slice(0,7));51  } else {52    console.error('FAILED:', JSON.stringify(result).slice(0,500));53  }54}55 56main().catch(e => { console.error('Fatal:', e); process.exit(1); });57