Skip to content

Commit

Permalink
feat: opt-in-out
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcoindev committed Nov 8, 2023
1 parent f8c35c5 commit d1889ed
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
62 changes: 61 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
}

interface Opt{
in: string[];
out: string[];
}

const projects = _projects as Projects;
const opt = _opt as Opt;

// init env variables
dotenv.config();
Expand Down Expand Up @@ -56,9 +63,22 @@ async function main() {
DEVPOOL_REPO_NAME
);

// aggregate projects.urls and opt settings
let projectUrls = new Set<string>(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
Expand Down Expand Up @@ -139,7 +159,7 @@ async function main() {
// close missing issues
await forceCloseMissingIssues(devpoolIssues, allProjectIssues);

*/
} catch (err) {
console.log(err);
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions opt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"out": [
"ubiquity/devpool-directory",
"ubiquity/.github"
],
"in": [
"alpha-labs-global/blockalizer",
"uniswap/interface",
"korrrba"
]
}

0 comments on commit d1889ed

Please sign in to comment.