Skip to content

Commit

Permalink
Make all the dev stuff toggled via config
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Jul 2, 2019
1 parent 47bf658 commit e62c958
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 43 deletions.
17 changes: 11 additions & 6 deletions cnames.js
@@ -1,6 +1,9 @@
// Load in custom caching
const {getCache, setCache} = require("./cache.js");

// Load in our config
const config = require("./config.json");

// Load in string formatting
require("./string.js");

Expand Down Expand Up @@ -34,8 +37,8 @@ const getCNAMEs = async () => {

// Get the raw GitHub API data
const req = await octokit.repos.getContents({
owner: "js-org",
repo: "js.org",
owner: config.repository_owner,
repo: config.repository_name,
path: "cnames_active.js"
});

Expand Down Expand Up @@ -100,10 +103,12 @@ const validateCNAMEs = async () => {
const tests = {};

// DEV: only test the first few
/*const slice = Object.keys(cnames).slice(10);
for (const key in slice) {
delete cnames[slice[key]];
}*/
if (config.dev_restrict_cname_count) {
const slice = Object.keys(cnames).slice(10);
for (const key in slice) {
delete cnames[slice[key]];
}
}

// Test each entry
let counter = 0;
Expand Down
8 changes: 8 additions & 0 deletions config.example.json
@@ -0,0 +1,8 @@
{
"github_token": "<personal access token for GitHub API>",
"repository_owner": "<target repo owner for cleanup>",
"repository_name": "<target repo name for cleanup>",
"automatic_contact": true,
"dev_restrict_cname_count": false,
"dev_fake_cnames": false
}
67 changes: 40 additions & 27 deletions index.js
@@ -1,3 +1,6 @@
// Load in our config
const config = require("./config.json");

// Load in CNAME operation
const {validateCNAMEs} = require("./cnames.js");

Expand All @@ -12,40 +15,50 @@ const createIssue = async () => {
const failed = await validateCNAMEs();

// DEV: custom test failed record
/*for (const cname in failed) {
if (!failed.hasOwnProperty(cname)) continue;
delete failed[cname];
if (config.dev_fake_cnames) {
// Clear out all the real cnames
for (const cname in failed) {
if (!failed.hasOwnProperty(cname)) continue;
delete failed[cname];
}
// Should be able to create automatic contact issue
failed["test"] = {
target: "js-org-cleanup.github.io/test-repo-2",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};
// Issues disabled on repo, automatic should fail
failed["test-other"] = {
target: "js-org-cleanup.github.io/test-repo-3",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};
// Repo doesn't exist, should fail on automatic contact
failed["test-gone"] = {
target: "js-org-cleanup.github.io",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};
// External domain, shouldn't try automatic contact
failed["custom"] = {
target: "custom-target.test.com",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};
}
failed["test"] = {
target: "js-org-cleanup.github.io/test-repo-2",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};
failed["test-other"] = {
target: "js-org-cleanup.github.io/test-repo-3",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};
failed["test-gone"] = {
target: "js-org-cleanup.github.io",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};
failed["custom"] = {
target: "custom-target.test.com",
http: "Failed with status code '404 Not Found'",
https: "Failed with status code '404 Not Found'",
failed: true
};*/

console.log(await createMainIssue(failed));
};

createIssue();

// TODO: as a secondary feature of the script, have just a file cleanup method
// TODO: will just parse all cnames, header/footer of the file, then generate perfectly formatted new file & pr

// TODO: parse issue to detect entries that were not ticked
// TODO: remove un-ticked entries from the cnames_active file
// TODO: create PR to update cnames_active file (ref issue)
24 changes: 14 additions & 10 deletions issues.js
Expand Up @@ -165,20 +165,24 @@ const createMainIssue = async failed => {
}

// Create new empty issue (change this for DEV)
const owner = "js-org";
const repo = "js.org";
const issue = await octokit.issues.create({
owner,
repo,
owner: config.repository_owner,
repo: config.repository_name,
title: "JS.ORG CLEANUP",
body: "Automatic initial cleanup contact in progress... this issue will be updated shortly."
});

// Attempt automatic contact
const {pending, contact} = await attemptTargetIssues(failed, issue.data.html_url);
let pending = failed;
let contact = {};
if (config.automatic_contact) {
// Attempt automatic contact
const res = await attemptTargetIssues(failed, issue.data.html_url);
pending = res.pending;
contact = res.contact;

// Log
console.log(chalk.cyanBright.bold("\nResuming createMainIssue process"));
// Log resume
console.log(chalk.cyanBright.bold("\nResuming createMainIssue process"));
}

// Convert them to MD list
const pendingList = entriesToList(pending);
Expand All @@ -198,8 +202,8 @@ const createMainIssue = async failed => {

// Edit the issue
await octokit.issues.update({
owner,
repo,
owner: config.repository_owner,
repo: config.repository_name,
issue_number: issue.data.number,
body
});
Expand Down

0 comments on commit e62c958

Please sign in to comment.