From d1889edf9ebf60716e46c564f2de9686880689a8 Mon Sep 17 00:00:00 2001 From: Korrrba Date: Wed, 8 Nov 2023 14:33:57 +0100 Subject: [PATCH] feat: opt-in-out --- index.ts | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- opt.json | 11 ++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 opt.json diff --git a/index.ts b/index.ts index ada5429be..e267cc17c 100644 --- a/index.ts +++ b/index.ts @@ -5,13 +5,20 @@ import dotenv from 'dotenv'; import { Octokit } from 'octokit'; import _projects from './projects.json'; +import _opt from './opt.json'; interface Projects{ urls: string[]; category?: Record } +interface Opt{ + in: string[]; + out: string[]; +} + const projects = _projects as Projects; +const opt = _opt as Opt; // init env variables dotenv.config(); @@ -56,9 +63,22 @@ async function main() { DEVPOOL_REPO_NAME ); + // aggregate projects.urls and opt settings + let projectUrls = new Set(projects.urls); + for (let orgOrRepo in opt.in) { + const urls: string[] = await getRepoUrls(orgOrRepo); + urls.forEach(projectUrls.add, projectUrls); + } + for (let orgOrRepo in opt.out) { + const urls: string[] = await getRepoUrls(orgOrRepo); + urls.forEach(projectUrls.delete, projectUrls); + } + // aggregate all project issues const allProjectIssues: Issue[] = []; + console.log(projectUrls); + /* // for each project URL for (let projectUrl of projects.urls) { // get owner and repository names from project URL @@ -139,7 +159,7 @@ async function main() { // close missing issues await forceCloseMissingIssues(devpoolIssues, allProjectIssues); - + */ } catch (err) { console.log(err); } @@ -225,6 +245,46 @@ async function getAllIssues(ownerName: string, repoName: string) { return issues; } +/** + * Returns all org repositories urls or owner/repo url + * @param orgOrRepo org or repository name + * @returns array of repository urls + */ +async function getRepoUrls(orgOrRepo: string) { + const params = orgOrRepo.split("/"); + let repos: string[] = []; + + switch (params.length) { + case 1: // org + try { + const res = await octokit.paginate("GET /orgs/{org}/repos", { + org: orgOrRepo, + }); + repos = res.map((repo) => repo.html_url); + } catch (e: unknown) { + console.warn(`Getting org repositories failed: ${e}`); + } + break; + case 2: // owner/repo + try { + const res = await octokit.rest.repos.get({ + owner: params[0], + repo: params[1] + }); + if (res.status === 200) { + repos.push(res.data.html_url); + } else console.warn(`Getting owner/repo failed: ${res.status}`); + } catch (e: unknown) { + console.warn(`Getting owner/repo failed: ${e}`); + } + break; + default: + console.warn(`Neither org or nor repo GitHub provided: ${orgOrRepo}.`); + } + + return repos; +} + /** * Returns array of labels for a devpool issue * @param issue issue object diff --git a/opt.json b/opt.json new file mode 100644 index 000000000..1de2326d7 --- /dev/null +++ b/opt.json @@ -0,0 +1,11 @@ +{ + "out": [ + "ubiquity/devpool-directory", + "ubiquity/.github" + ], + "in": [ + "alpha-labs-global/blockalizer", + "uniswap/interface", + "korrrba" + ] +}