Reputation: 4632
Is there a way (from the command line) to list the names of all files changed in a PR in Git/GitHub? This would be used to find what tests need to be run in a Travis CI build for that PR.
The CI build runs these commands before it calls our script:
git clone --depth=50 git://github.com/jekyll/jekyll.git jekyll/jekyll
cd jekyll/jekyll
git fetch origin +refs/pull/2615/merge
git checkout -qf FETCH_HEAD
Upvotes: 63
Views: 88100
Reputation: 3552
In general, you can list the files changed between any two commits with
git diff --name-only <ref1> <ref2>
How to list only the names of files that changed between two commits
The problem here seems to be determining the 'merge base'. If all branches originate with master, then you could do:
git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD master)
This will show you the changes between the point at which the FETCH_HEAD
was branched from master
to the current FETCH_HEAD
. I tested this locally, and the PR branches are cut from master
I believe it should work.
Upvotes: 64
Reputation: 1323145
The alternative to zoispag's answer (using the new GitHub CLI 2.14.5) and gh pr diff
:
gh pr diff --name-only
From PR 6074 and issue 6060.
But, as noted by Dean Radcliffe in the comments, this has a limit if the PR is too big - 20000 lines.
Upvotes: 1
Reputation: 71961
A total hacky, not 100% fool proof, but easy way to get this, for all files touched in a PR is to:
pbpaste | grep 'src/'
, for example, if you have a java project. This sends the text that's on the clipboard to grep.Upvotes: 1
Reputation: 141
There are some ways to find changed files but you have to experiment on what you compare. Two examples that I mainly use in GitHub Actions are:
git --no-pager diff --name-only --diff-filter=ACMRT ${{github.event.pull_request.base.sha}} ${{ github.event.pull_request.head.sha }}
and:
git --no-pager diff --name-only --diff-filter=ACMRT ${{github.event.pull_request.base.sha}} ${{github.sha}}
This results in a list such as:
.github/workflows/potato.yml
.tomato.yml
app/assets/javascripts/cucumber.js
Experiment with the SHA signatures according to your needs.
Upvotes: 0
Reputation: 665
Inspired by @AdamHickey, that answer was not working anymore. So, I created a working script.
let changes = document.getElementsByClassName("file-info");
let files = []
for(let i =0;i<changes.length;i++)
{
files.push(changes[i].getElementsByClassName("link-gray-dark")[0].title);
}
navigator.clipboard.writeText(JSON.stringify(files));
Disclaimer: This may stop working if someday the structure of html change.
Upvotes: 0
Reputation: 89
Chrome console...
Note: This will break if Github changes the tags/classes/IDs in the page.
const fileElems = document.querySelectorAll('#files div.js-diff-progressive-container div.file div.file-header div.file-info a.Link--primary');
const filePaths = [];
for (let a of fileElems) {
filePaths.push(a.title);
}
const filePathsStr = filePaths.join('\n');
console.log(filePathsStr);
copy(filePathsStr);
console.log('Copied to the clipboard as well 😁');
Upvotes: 8
Reputation: 21
According to @AdamHickey's 2019 answer, update the tag's class to 'Link--primary' as below
// the changes were only done on the **line** below
const fileElems = document.querySelectorAll('#files div.file-info a.Link--primary');
const filePaths = [];
for (let a of fileElems) {
filePaths.push(a.title);
}
const filePathsStr = filePaths.join('\n');
console.log(filePathsStr);
copy(filePathsStr);
console.log('Copied to the clipboard as well 😁');
Upvotes: 2
Reputation: 631
Using GitHub cli (gh) you can run:
gh pr view 2615 --json files --jq '.files.[].path'
I have made a gh alias
because I use it regularly:
gh alias set pr_files "pr view $1 --json files --jq '.files.[].path'"
and then I call it with gh pr_files 2615
or gh pr_files 2615 | cat
gh pr_files 2615 | cat
Upvotes: 47
Reputation: 318
For GitHub specifically, this can be accomplished using the REST API:
GET /repos/:owner/:repo/pulls/:pull_number/files
You can use one of the GitHub libraries for this purpose.
Upvotes: 13
Reputation: 1386
Here is the simple method:
6. Create access token in Azure DevOps and use it for authentication 7. Provide Code and Token Administration access to token
Upvotes: 2
Reputation: 90736
I couldn't find a way to see just the list of changed files in GitHub (i.e. without the diff and comments), but it can be done with this one-liner in the browser console:
Array.from(document.getElementsByClassName('js-details-target')).forEach((e) => {e.click();})
This will collapse all the diff blocks leaving only the filenames.
Upvotes: 1
Reputation: 27395
Google search sent me here though it is slightly different question.
This question [details] has command-line. However, I needed the list of files, its ok if I can see in GUI
Here a way to see list of files in GUI:
open the pull request
click on the [Files changed] tab
Conversation 0 Commits 3 [Files changed] 8
click on drop down after 'n files' in the below line of [Files changed]
Changes from all commits v ... [8 files v] ... +638 −266
(click on the v, drop down, after files in the above line)
Upvotes: 1