danger-js
danger-js copied to clipboard
Feature: provider-agnostic API to fetch file contents of a different ref
Describe the bug
danger.github
is undefined.
Cannot read property 'pr' of undefined
TypeError: Cannot read property 'pr' of undefined
at dangerfile.js:5:62
To Reproduce
-
git clone https://github.com/edno/danger-github-undefined.git
-
cd danger-github-undefined
-
yarn install
(Yarn 2) -
git checkout new-branch
-
yarn danger local -b main
Expected behavior This should display
message(`:tada: The PR added ${additions} and removed ${deletions} lines.`)
Environment
software | version |
---|---|
danger.js | ^10.6.2 |
node | v12.18.3 |
yarn | 2.4.0 |
Operating System | MacOS 11.2.1 |
Those two DSL attributes rely on the GitHub API (on a GitHub repo), I'd be open to PRs which de-couple that on danger local
👍🏻
Those two DSL attributes rely on the GitHub API (on a GitHub repo), I'd be open to PRs which de-couple that on
danger local
👍🏻
Fair point! But in that case, how do you fetch a file content by ref while using local
?
I don't think there's an API for that today, I have generally only looked at the files which changed and not necessarily the contents - I think there could be a danger.local
API which feels like github
which wraps calls to git
to provide those sorts of functions?
git cat-file
would be a way to fetch file content locally.
Yep, good thinking, I'd accept a PR adding an API something like:
import {danger} from "danger"
// could maybe be always "HEAD", but could also be a branch reference, hard to say what it should be with --staging though
danger.local.head
// master, or whatever someone changed it to
danger.local.base
// New to .git - when in `local` use wrapped git call, otherwise use the available APIs
// Defaults to the head version
danger.git.getFileContents("file.md")
// So, you can get the other SHA refs
danger.git.getFileContents("file.md", danger.local.base)
Sure. I will look at it this week.