Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Move all JS files towards using flow
const changedFiles = danger.git.created_files.concat(danger.git.modified_files);
const unFlowedFiles = changedFiles.filter(path => !path.startsWith('test/') && path.endsWith('js'))
.filter(filepath => {
const content = fs.readFileSync(filepath);
return content.includes('@flow');
});
if (unFlowedFiles.length > 0) {
const flowLinks = [
' * [Main Site](https://flowtype.org)',
' * [Types](https://flowtype.org/docs/quick-reference.html#primitives)',
' * [What is Flow?](https://code.facebook.com/posts/1505962329687926/flow-a-new-static-type-checker-for-javascript/)', // eslint-disable-line
' * [Danger\'s flow glossary](https://github.com/danger/danger-js/blob/master/docs/js_glossary.md)',
];
markdown('--- \n\n If you are new to Flow, here are some resources: \n\n' + flowLinks.join('\n'));
warn(`These new JS files do not have Flow enabled: ${unFlowedFiles.join(', ')}`);
}
// Request a CHANGELOG entry, but allow a PR to say it doesn't neeed one
const hasChangelog = changedFiles.includes('changelog.md');
const declaredTrivial = danger.pr.title.indexOf('trivial') !== -1;
if (!hasChangelog && !declaredTrivial) {
fail('Please add a changelog entry noting your changes.');
}
// Politely ask for their name on the entry too
if (hasChangelog) {
const changelogDiff = danger.git.diffForFile('changelog.md');
const contributorName = danger.github.pr.user.login;
if (changelogDiff && changelogDiff.indexOf(contributorName) === -1) {
// Yes, this is a bit lossy, we run the linter twice now, but its still a short amount of time
// Perhaps we could indicate that tslint failed somehow the first time?
if (fs.existsSync("tslint-errors.json")) {
const tslintErrors = JSON.parse(fs.readFileSync("tslint-errors.json", "utf8")) as any[]
if (tslintErrors.length) {
const errors = tslintErrors.map(error => {
const format = error.ruleSeverity === "ERROR" ? ":no_entry_sign:" : ":warning:"
const linkToFile = danger.github.utils.fileLinks([error.name])
return `* ${format} ${linkToFile} - ${error.ruleName} -${error.failure}`
})
const tslintMarkdown = `
## TSLint Issues:
${errors.join("\n")}
`
markdown(tslintMarkdown)
}
}
// Show Jest fails in the PR
import jest from "danger-plugin-jest"
if (fs.existsSync("test-results.json")) {
jest({ testResultsJsonPath: "test-results.json" })
}
// Raise when native code changes are made, but the package.json does not
// have a bump for the native code version
//
const hasNativeCodeChanges = modified.find(p => p.includes("Pod/Classes") && p.includes(".h"))
const hasPackageJSONChanges = modified.find(p => p === "package.json")
if (hasNativeCodeChanges && !hasPackageJSONChanges && !acceptedNoNativeChanges) {
fail(
const commitRange = `${mergeBaseCommit}...${danger.github.pr.head.sha}`;
const comparison = await loadComparison(mergeBaseCommit, upstreamRef);
const results = Object.entries(comparison.bundles);
const anyResultsChanges = results.filter(createComparisonFilter(1, 1));
if (anyResultsChanges.length > 0) {
const importantChanges = results
.filter(createComparisonFilter(parsedSizeChangeThreshold, gzipSizeChangeThreshold))
.filter(isPackageComparison)
.map(generateEmphasizedChange);
// have to guard against empty strings
if (importantChanges.length > 0) {
markdown(importantChanges.join('\n'));
}
const detailsTable = generateMDTable(
[
{ label: 'bundle' },
{ label: 'Size Change', align: 'right' },
{ label: 'Size', align: 'right' },
{ label: 'Gzip Change', align: 'right' },
{ label: 'Gzip', align: 'right' },
],
results
.map(([bundleId, size]) => [computeBundleLabel(bundleId), size])
// orderBy(|parsedDiff| DESC, |gzipDiff| DESC, name ASC)
.sort(([labelA, statsA], [labelB, statsB]) => {
const compareParsedDiff =
Math.abs(statsB.parsed.absoluteDiff) - Math.abs(statsA.parsed.absoluteDiff);
// This process should always fail, so needs the `|| true` so it won't raise.
child_process.execSync(`npm run lint -- -- --format json --out tslint-errors.json || true`);
if (fs.existsSync("tslint-errors.json")) {
const tslintErrors = JSON.parse(fs.readFileSync("tslint-errors.json", "utf8")) as any[];
if (tslintErrors.length) {
const errors = tslintErrors.map(error => {
const format = error.ruleSeverity === "ERROR" ? ":no_entry_sign:" : ":warning:";
const linkToFile = danger.github.utils.fileLinks([error.name]);
return `* ${format} ${linkToFile} - ${error.ruleName} - ${error.failure}`;
});
const tslintMarkdown = `
## TSLint Issues:
${errors.join("\n")}
`;
markdown(tslintMarkdown);
}
}
let buildStatus = readLogFile('./logs/build-status')
if (buildStatus !== '0') {
// returning early here because if the build fails, there's nothing to analyze
fastlaneBuildLogTail(logFile, 'iOS Build Failed')
return
}
// tee the "fastlane" output to a log, and run the analysis script
// to report back the longest compilation units
let analysisFile = readFile('./logs/analysis')
if (!analysisFile.trim().length) {
return
}
markdown(
h.h2('iOS Report'),
h.details(
h.summary('Analysis of slow build times (>20s)'),
m.code({}, analysisFile),
),
)
}
const {danger, markdown, message, warn} = require('danger')
const http = require('http')
const url = require('url')
const yaml = require('js-yaml')
const fs = require('fs')
markdown("Hey there! Thanks for contributing a PR to osgameclones! 🎉")
let namesAdded = []
let namesChanged = []
let namesRemoved = []
const isGame = game => /^games\/\w+\.yaml$/.test(game)
let unknownLanguageDetected = false
const knownLanguages = [
'ActionScript',
'Ada',
'AngelScript',
'Assembly',
'Blitz BASIC',
'C',
'C#',
function listTouchedPackages(modifiedPackages: TinaPackage[]) {
if (!modifiedPackages.length) return
markdown(`### Modified Packages
The following packages were modified by this pull request:
* ${modifiedPackages
.map(({ packageJson }) => `\`${packageJson.name}\``)
.join('\n* ')}`)
}
function xcodeproj() {
let pbxprojChanged = danger.git.modified_files.find(filepath =>
filepath.endsWith('project.pbxproj'),
)
if (!pbxprojChanged) {
return
}
markdown(
'The Xcode project file changed. Maintainers, double-check the changes!',
)
}
allTables.push(`\n## ${name}`);
allTables.push(generateMDTable(mdHeaders, mdRows));
}
const summary = `
<details>
<summary>Details of bundled changes.</summary>
<p>Comparing: ${baseCommit}...${danger.github.pr.head.sha}</p>
${allTables.join('\n')}
</details>
`;
markdown(summary);
} else {
markdown('No significant bundle size changes to report.');
}
})();