Skip to content

Commit

Permalink
save html in artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Mar 8, 2018
1 parent b43d767 commit 26ab57f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"max-params": ["error", {"max" : 3}],
"max-statements": ["error", {"max" : 17}, {"ignoreTopLevelFunctions": false}],
"max-len": ["error", {"code" : 120}],
"max-lines": ["error", {"max": 220, "skipComments": true, "skipBlankLines": true}],
"max-lines": ["error", {"max": 250, "skipComments": true, "skipBlankLines": true}],
"semi": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}]
}
Expand Down
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const parseLinkHeader = require('parse-link-header');
Expand All @@ -16,6 +18,7 @@ const GITHUB_TOKEN = TRENDING_POST_COMMENTS ? process.env.GITHUB_TOKEN_BOT : pro
if (!GITHUB_TOKEN) {
throw new Error('No GitHub token in env variables!');
}
const ARTIFACTS_PATH = process.env.CIRCLE_ARTIFACTS || '.artifacts';

const API_URL = 'https://api.github.com/repos/vitalets/github-trending-repos';
const GITHUB_URL_REG = /https:\/\/github.com\/[^)]+/ig;
Expand Down Expand Up @@ -211,14 +214,32 @@ function assertZeroTrendingRepos(domRepos, $, url) {
// When GitHub is re-calculating trending repos - it shows this message
const TRENDING_REPOS_DISSECTED_MSG = 'Trending repositories results are currently being dissected';
const isDissecting = $('.blankslate').text().indexOf(TRENDING_REPOS_DISSECTED_MSG) >= 0;
const isTimeouted = $.text().indexOf('This page is taking way too long to load') >= 0;
if (isDissecting) {
console.log(`Trending repos are being dissecting.`);
} else if (isTimeouted) {
console.log(`Page timeouted.`);
} else {
const filename = url.match(/trending\/(.+)$/)[1];
saveArtifact(`${filename}.html`, $.html());
throw new Error(`Can't retrieve trending repos from: ${url}`);
}
}
}

function saveArtifact(filename, content) {
try {
if (!fs.existsSync(ARTIFACTS_PATH)) {
fs.mkdirSync(ARTIFACTS_PATH);
}
const filepath = path.join(ARTIFACTS_PATH, filename);
console.log(`Saving artifact: ${filepath}`);
fs.writeFileSync(filepath, content, 'utf-8');
} catch (e) {
console.error(e);
}
}

function assertIssueIsLocked(issue) {
if (!issue.locked) {
throw new Error(`Unlocked issue: ${issue.html_url}`);
Expand Down

0 comments on commit 26ab57f

Please sign in to comment.