|
| 1 | +// install these: |
| 2 | +// yarn add @octokit/core |
| 3 | +// yarn add dotenv |
| 4 | + |
| 5 | +// run with node setup_github_repos.mjs |
| 6 | + |
| 7 | +import fs from 'node:fs' |
| 8 | +import { Octokit } from '@octokit/core' |
| 9 | +import dotenv from 'dotenv' |
| 10 | + |
| 11 | + |
| 12 | +import { getsubmodules } from '../getsubmodules.js' |
| 13 | + |
| 14 | +// Load environment variables from .env file |
| 15 | +// dotenv.config({ path: `${localRepoPath}/tools/setup_github_repos/.env` }) |
| 16 | +dotenv.config({ path: `tools/.env` }) |
| 17 | + |
| 18 | + |
| 19 | +async function repoSetHomepage(octokit, name, homepage) { |
| 20 | + const result = await octokit.request('PATCH /repos/{owner}/{repo}', { |
| 21 | + owner: 'Make-Your-School', |
| 22 | + repo: name, |
| 23 | + name: name, |
| 24 | + homepage: homepage, |
| 25 | + // description: 'This is your first repository', |
| 26 | + // private: true, |
| 27 | + // has_issues: true, |
| 28 | + // has_projects: true, |
| 29 | + // has_wiki: true, |
| 30 | + // topics not allowed. skipping for now. |
| 31 | + // topics: 'markdown arduino library mks make-your-school', |
| 32 | + headers: { |
| 33 | + 'X-GitHub-Api-Version': '2022-11-28', |
| 34 | + }, |
| 35 | + }) |
| 36 | + return result |
| 37 | +} |
| 38 | + |
| 39 | +async function testOctokitRequest(octokit) { |
| 40 | + try { |
| 41 | + const { data } = await octokit.request('/user') |
| 42 | + console.log('data', data) |
| 43 | + } catch (error) { |
| 44 | + console.error('Error making Octokit request:', error) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +export async function main() { |
| 49 | + // fixed configuration |
| 50 | + // Octokit.js |
| 51 | + // https://github.com/octokit/core.js#readme |
| 52 | + const octokit = new Octokit({ |
| 53 | + auth: process.env.GITHUB_PAC, |
| 54 | + }) |
| 55 | + |
| 56 | + await testOctokitRequest(octokit) |
| 57 | + console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') |
| 58 | + console.log('') |
| 59 | + console.log('') |
| 60 | + |
| 61 | + const submodules = getsubmodules() |
| 62 | + console.log(`found '${submodules.length}' submodules to process..`) |
| 63 | + for (const [submodule_name, submodule] of Object.entries(submodules)) { |
| 64 | + console.log('submodule_name', submodule_name) |
| 65 | + console.log('submodule', submodule) |
| 66 | + // const homepage = `https://make-your-school.github.io/mks-welcome/part/${repoData.repo_name.toLowerCase()}` |
| 67 | + // await repoSetHomepage(octokit, repoData.repo_name, homepage) |
| 68 | + } |
| 69 | + |
| 70 | + console.log('done.') |
| 71 | +} |
| 72 | + |
| 73 | +main() |
0 commit comments