dangerfile.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { DangerResults } from "danger";
  2. declare const results: DangerResults;
  3. declare const message: (message: string, results?: DangerResults) => void;
  4. declare const markdown: (message: string, results?: DangerResults) => void;
  5. // Import modules with danger rules
  6. // (Modules with checks are stored in ".github/dangerjs/<module_name>.ts". To import them, use path relative to "dangerfile.ts")
  7. import prCommitsTooManyCommits from "./prCommitsTooManyCommits";
  8. import prDescription from "./prDescription";
  9. import prTargetBranch from "./prTargetBranch";
  10. import prInfoContributor from "./prInfoContributor";
  11. import prCommitMessage from "./prCommitMessage";
  12. async function runDangerRules(): Promise<void> {
  13. // Message to contributor about review and merge process
  14. const prInfoContributorMessage: string = await prInfoContributor();
  15. markdown(prInfoContributorMessage);
  16. // Run danger checks
  17. prCommitsTooManyCommits();
  18. prDescription();
  19. prTargetBranch();
  20. prCommitMessage();
  21. // Add success log if no issues
  22. const dangerFails: number = results.fails.length;
  23. const dangerWarns: number = results.warnings.length;
  24. const dangerInfos: number = results.messages.length;
  25. if (!dangerFails && !dangerWarns && !dangerInfos) {
  26. return message("Good Job! All checks are passing!");
  27. }
  28. // Add retry link
  29. addRetryLink();
  30. }
  31. runDangerRules();
  32. function addRetryLink(): void {
  33. const serverUrl: string | undefined = process.env.GITHUB_SERVER_URL;
  34. const repoName: string | undefined = process.env.GITHUB_REPOSITORY;
  35. const runId: string | undefined = process.env.GITHUB_RUN_ID;
  36. const retryLinkUrl: string = `${serverUrl}/${repoName}/actions/runs/${runId}`;
  37. const retryLink: string = `<sub>:repeat: You can re-run automatic PR checks by retrying the <a href="${retryLinkUrl}">DangerJS action</a></sub>`;
  38. markdown(retryLink);
  39. }