actions / dependency-review-action

A GitHub Action for detecting vulnerable dependencies and invalid licenses in your PRs
MIT License
558 stars 94 forks source link

Question: Is this action limited to revisions on the _default_ branch only? #743

Closed andreas-borglin closed 2 months ago

andreas-borglin commented 2 months ago

Hi there.

The README states: The action is supported by an [API endpoint](https://docs.github.com/rest/dependency-graph/dependency-review) that diffs the dependencies between any two revisions on your default branch..

This seems to indicate that the review only works if the two revisions (commits) are available on the default branch?

However, reading the API docs for the endpoint used, https://docs.github.com/en/rest/dependency-graph/dependency-review?apiVersion=2022-11-28#get-a-diff-of-the-dependencies-between-commits, there is no mention of this "restriction". It merely states Gets the diff of the dependency changes between two commits of a repository....

Testing the API as well with commits that are not on the default branch seems to work as expected, when the dependency submission API has been used to submit snapshots of those commits to that repo.

Is this then incorrect information in the README or does the action itself impose this restriction that the commits have to be on the default branch specifically?

Thanks in advance, Andreas

jonjanego commented 2 months ago

Hi @andreas-borglin - that's correct, this action only reviews diffs between commits to the default branch, because it also relies on data that's only in the dependency graph for the repo, which is only created for the default branch.

Thanks for using the action!

andreas-borglin commented 2 months ago

Hi again.

Sorry but this doesn't seem quite right to me. The dependency submission API allows for dependency information to be submitted for any git reference, and from that, the dependency review API can then be used to get a diff of the dependencies between any two submitted snapshots associated with any git refs in the repo. This is described in the GitHub docs and can be easily verified via the APIs. There is no dependency on the default branch for the APIs.

This action uses the latter API as per https://github.com/actions/dependency-review-action/blob/main/src/dependency-graph.ts#L28-L35.

Hence, if dependency snapshots have been submitted via the dependency submission API for any target branch, and for any source branch with a PR targeting the target branch, then this action does work as expected. We have tested this action fairly extensively now with non-default branches and it works as we'd expect.

But yes, if the dependency submission API is not used, then this would only work against the default branch as that is the only branch that is reported to the graph automatically via dependabot. However the README does not make this clear.

Thanks, Andreas