-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d606ce2
commit a7573b0
Showing
8 changed files
with
50 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
import { danger, fail } from 'danger' | ||
import * as fs from 'fs' | ||
import { danger, fail } from 'danger'; | ||
import * as fs from 'fs'; | ||
|
||
const pr = danger.github.pr | ||
const modified = danger.git.modified_files | ||
const bodyAndTitle = (pr.body + pr.title).toLowerCase() | ||
const trivialPR = bodyAndTitle.includes('#trivial') | ||
const isForkedRepo = (): boolean => { | ||
const headRepoName = danger.github.pr.head.repo.full_name; | ||
const baseRepoName = danger.github.pr.base.repo.full_name; | ||
|
||
const typescriptOnly = (file: string) => file.includes('.ts') | ||
const filesOnly = (file: string) => fs.existsSync(file) && fs.lstatSync(file).isFile() | ||
if (headRepoName !== baseRepoName) { | ||
// This is shown inline in the output and also integrates with the GitHub | ||
// Action reporting UI and produces a warning | ||
console.log( | ||
"::warning::Running from a forked repo. Danger won't be able to post comments, you will most likely see a 403 error below..." | ||
); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
const pr = danger.github.pr; | ||
const modified = danger.git.modified_files; | ||
const bodyAndTitle = (pr.body + pr.title).toLowerCase(); | ||
const trivialPR = bodyAndTitle.includes('#trivial'); | ||
|
||
const typescriptOnly = (file: string) => file.includes('.ts'); | ||
const filesOnly = (file: string) => fs.existsSync(file) && fs.lstatSync(file).isFile(); | ||
|
||
// Custom subsets of known files | ||
const modifiedAppFiles = modified.filter(p => p.includes('src/')).filter(p => filesOnly(p) && typescriptOnly(p)) | ||
const modifiedAppFiles = modified | ||
.filter((p) => p.includes('src/')) | ||
.filter((p) => filesOnly(p) && typescriptOnly(p)); | ||
|
||
// Rules | ||
|
||
// When there are app-changes and it's not a PR marked as trivial, expect | ||
// there to be CHANGELOG changes. | ||
const changelogChanges = modified.includes('CHANGELOG.md') | ||
const changelogChanges = modified.includes('CHANGELOG.md'); | ||
if (modifiedAppFiles.length > 0 && !trivialPR && !changelogChanges) { | ||
fail( | ||
'**No CHANGELOG added.** If this is a small PR, or a bug-fix for an unreleased bug add `#trivial` to your PR message and re-run CI.' | ||
) | ||
const message = | ||
'**No CHANGELOG added.** If this is a small PR, or a bug-fix for an unreleased bug add `#trivial` to your PR message and re-run CI.'; | ||
if (isForkedRepo()) { | ||
console.log(`::error::${message}`); | ||
} | ||
fail(message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters