Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Use DangerJS for commenting" (#1027)" #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/data-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install Dependencies
run: npm install

- name: Validate data.js
run: node ./scripts/data-validate.js
- name: Validate data.js using DangerJS
run: npx danger ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
57 changes: 57 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable import/no-extraneous-dependencies */
const { danger, fail, markdown, message, schedule } = require('danger');
const validate = require('./scripts/data-validate');

const DATA_FILE = 'src/data.js';

async function main() {
if (!danger.git.modified_files.includes(DATA_FILE)) {
message(`No changes in \`${DATA_FILE}\``);
return;
}

const diff = await danger.git.diffForFile(DATA_FILE);
// eslint-disable-next-line no-eval
const masterData = eval(diff.before);

const { data: changedData, errorMsgs, failedUrls } = await validate(
masterData
);

// If there are errors, will fail the action & add a comment detailing the issues
if (errorMsgs.length) {
fail(`There are ${errorMsgs.length} validation error(s)`);

markdown(
`### Validation Issues\n${errorMsgs.map(msg => `- ${msg}`).join('\n')}`
);
}

if (failedUrls.length) {
fail(`There are ${failedUrls.length} failing URL(s)`);

markdown(
`### Failing URLs\n${failedUrls
.map(({ url, error, statusCode }) => {
if (error)
return `- URL, ${url}, failed with error: ${error.message}`;
return `- URL, ${url}, failed with status code: ${statusCode}`;
})
.join('\n')}`
);
}

// If there are no errors, will leave an "all-clear" comment with relevant URLs (to ease a potential manual check)
if (!errorMsgs.length && !failedUrls.length && changedData.length) {
message('Automatic validation checks succeeded', { icon: '✅' });
// Comment with the URLs of users that have changed
// for easy access, way easier than taking a screenshot
markdown(
`### Changed URLs\n${changedData
.map(({ name, url }) => `- ${name}, ${url}`)
.join('\n')}`
);
}
}

schedule(main);
Loading