Is this an external contribution (send from a fork)?
List of all committed files (both added and modified).
Returns a list of all committed files that match the provided regex.
const testFiles = committedFilesGrep(/(\.test\.js|\.spec\.js)$/);
Has this pull request been flagged as "trivial"? It's considered trivial when the pull request title and all commit messages contain #trivial
or [trivial]
.
Is the provided file name included in the pull request?
if (inCommit('package.json')) {
...
}
Is the provided file name regex included in the pull request?
if (inCommitGrep(/.+\.log$/)) {
...
}
Return the contents of all the lines that have been added in the provided file.
const addedLinesString = await fileAddedLines('file.js');
Return the contents of all the lines that have been removed in the provided file.
const removedLinesString = await fileRemovedLines('file.js');
Do the file added lines match a regex?
const someLineMatch = await fileAddedLineMatch('file.js', /pattern/);
if (someLineMatch) {
...
}
Do the file removed lines match a regex?
const someLineMatch = await fileRemovedLineMatch('file.js', /pattern/);
if (someLineMatch) {
...
}
Return the line number of all the lines that have been added in the provided file.
const addedLinesArray = await fileAddedLineNumbers('file.js');
Return the line number of all the lines that have been removed in the provided file.
const removedLinesArray = await fileRemovedLineNumbers('file.js');
Return an object with the content of all the lines that have been added in the provided file. The keys in the object are the line numbers.
const addedLines = await structuredFileAddedLines('file.js');
Object.entries(addedLines).forEach(([lineNumber, content]) => {
...
});
Return an object with the content of all the lines that have been removed in the provided file. The keys in the object are the line numbers.
const removedLines = await structuredFileRemovedLines('file.js');
Object.entries(removedLines).forEach(([lineNumber, content]) => {
...
});
Return an array with the line numbers of all the added lines that match a regex.
const lineNumbers = await structuredFileAddedLineMatches('file.js', /pattern/);
lineNumbers.forEach(lineNumber => {
...
});
Return an array with the line numbers of all the removed lines that match a regex.
const lineNumbers = await structuredFileRemovedLineMatches('file.js', /pattern/);
lineNumbers.forEach(lineNumber => {
...
});
Get a link to a file in the target repository (the one where the pull request will be merged into).
Parameters:
filename
: The file to link to.text
: The text to use for the link. Defaults to the value offilename
.branch
: The branch to link to. Defaults tomaster
.
const link1 = linkToTargetRepo('foler/file.js');
const link2 = linkToTargetRepo('CHANGELOG.md', 'changelog');
Get a link to a file in the source repository (the one where the pull request is being send from).
Parameters:
filename
: The file to link to.text
: The text to use for the link. Defaults to the value offilename
.branch
: The branch to link to. Defaults tomaster
.
const link1 = linkToSourceRepo('foler/file.js');
const link2 = linkToSourceRepo('CHANGELOG.md', 'changelog');
Files added in the pull request (shorthand for danger.git.created_files
).
Files changed in the pull request (shorthand for danger.git.modified_files
).
List of commits included in the pull request (shorthand for danger.git.commits
).
Return the diff for a specific file (shorthand for danger.git.diffForFile
).
Title of the pull request (shorthand for danger.github.pr.title
).
Description of the pull request (shorthand for danger.github.pr.body
).
Username of the author of the pull request (shorthand for danger.github.pr.user.login
).
Branch name where the pull request will be merged into (shorthand for danger.github.pr.base.ref
).
Project ID where the pull request will be merged into (shorthand for danger.github.pr.base.repo.id
).
Project repository url where the pull request will be merged into (shorthand for danger.github.pr.base.repo.html_url
).
Branch name where the pull request is being send from (shorthand for danger.github.pr.head.ref
).
Project ID where the pull request is being send from (shorthand for danger.github.pr.head.repo.id
).
Project repository url where the pull request is being send from (shorthand for danger.github.pr.head.repo.html_url
).
Generate a link to a file in the repository (shorthand for danger.utils.href
).
Get an array with the owners of a file (defined in CODEOWNERS).
Parameters:
filename
: The file to get the owners.codeownersPath
: Path to the codeowners file. Defaults toCODEOWNERS
.
const owners = getFileOwners('foler/file.js');
const owners = getFileOwners('foler/file.js', '.github/CODEOWNERS');