You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are use-cases where you want to analyse files changed by a commit:
you changed package.json but not yarn.lock
you pinned a package and didn't leave commit message body why you pinned.
modified source, but didn't add/update tests
and those per commit, not whole merge request.
therefore would want to have commit.modified_files, commit.JSONDiffForFile, commit.fileMatch methods:
constpackageDiff=awaitcommit.JSONDiffForFile("package.json")if(packageDiff.dependencies){constnewDependencies=packageDiff.dependencies.added;if(newDependencies.includes(blacklist)){fail(`${commit.sha}: Do not add ${blacklist} to our dependencies, see CVE #23`);}}constpackageJson=commit.fileMatch("package.json");constpackageLock=commit.fileMatch("yarn.lock");if(packageJson.modified&&!packageLock.modified){warn("${commit.sha}: This commit modified `package.json`, but not `yarn.lock`");}consttestChanges=commit.modified_files.filter(filepath=>filepath.match(/(test|cypress)/));if(testChanges.length<1){warn(`${commit.sha}: This commit does not have any changes in automated tests. Please consider adding some tests.`)}
The text was updated successfully, but these errors were encountered:
This is something that I'd also like to see.
I'd like to add a review comment on Github for each commit that is not linked to an issue, but for that I also need to provide a path to a file that has been changed in that commit (see: https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request). For this usecase it doesn't really matter which file I'm putting the comment on.
A review comment is a bit better in this case than danger's message because the PR can't be merged until all review comments are resolved.
I'd like to write a dangerfile like this:
import { danger } from "danger";
const ISSUE_REFERENCE = `https://github.com/${danger.github.thisPR.owner}/${danger.github.thisPR.repo}/issues/`;
danger.git.commits.forEach((commit) => {
if (!commit.message.includes(ISSUE_REFERENCE)) {
danger.github.api.pulls.createReviewComment({
owner: danger.github.thisPR.owner,
repo: danger.github.thisPR.repo,
pull_number: danger.github.thisPR.number,
commit_id: commit.sha,
body: "question: Do these changes belong to an issue?\n\nIf so, please add a reference to the issue in the commit messages.",
path: commit.modified_files[0], // <--- note this
side: "RIGHT",
subject_type: "file",
});
}
});
Describe the feature
Converting #1335 to a feature request
Expected behavior
There are use-cases where you want to analyse files changed by a commit:
and those per commit, not whole merge request.
therefore would want to have
commit.modified_files
,commit.JSONDiffForFile
,commit.fileMatch
methods:The text was updated successfully, but these errors were encountered: