Reputation: 567
We frequently use the Files Changed tab on a pull request to peer review the work we have done on a branch, unfortunately a major part of our development process is regenerating Flex services so when viewing the files changed 99% of the changes are irrelevant. This makes it very easy to miss important changes that should be reviewed.
We know the folder that these regenerated services live in, and we could commit all the regen changes in one commit if that would help.
Does anyone have any suggestions how we can improve this? Ideally we would exclude a folder from the pull request diff.
Upvotes: 40
Views: 20643
Reputation: 61
As it seems, you cannot remove files completely from the Pull Request diff. I wrote a little JS Script which you can add with TamperMonkey or similar tools to be applied to GitHub. It removes the files from the sidebar and the bigger file elements from the middle:
document.addEventListener('DOMContentLoaded', () => {
// Select all elements with role="treeitem" - Removes items from the sidebar
const treeItems = document.querySelectorAll('[data-tree-entry-type="file"]');
// Iterate over each treeitem element
treeItems.forEach(item => {
// Check if the treeitem's text contains the substring "freezed.dart"
if (item.textContent.includes('freezed.dart')) { // Change here file extensions you want to match.
item.parentElement.remove()
// Perform any desired actions with the matched treeitem element
}
});
// Function to check if an element has the data-file-path attribute containing a substring
function hasFilePathSubstring(element, substring) {
const filePath = element.getAttribute('data-file-path');
return filePath && filePath.includes(substring);
}
// Get all elements with the data-file-path attribute containing the substring "freezed.dart" - Removes from the bigger file diff view
const diffItems = Array.from(document.querySelectorAll('[data-file-path]')).filter(element =>
element.getAttribute('data-file-path') && element.getAttribute('data-file-path').includes('freezed.dart') // Change here file extensions you want to match.
).forEach(item => item.remove());
});
Upvotes: 1
Reputation: 411
Here's the URL to create a bookmarklet generated on https://caiorss.github.io/bookmarklet-maker/ from Vinicius Brasil's snippet above:
javascript:(function()%7Bconst%20fileElements%20%3D%20document.querySelectorAll(%22*%5Bdata-path*%3D'vendor'%5D%22)%0AfileElements.forEach(el%20%3D%3E%20el.parentElement.remove())%7D)()%3B
Upvotes: 0
Reputation: 10329
I know this is an old question, but wanted to share my solution anyways. As an iOS developer I can experience this problem as well when updating libraries fetched with Carthage. So, before I perform a review on a pull request I run the following script:
document.querySelectorAll("*[data-path*='Carthage']").forEach( el => {
const item = el.querySelectorAll("input[type=checkbox][name=viewed]:not(:checked)")[0]
if ( typeof item !== "undefined" ) {
setTimeout(function () {
item.click()
}, 1000)
}
})
Run it in you console (DevTools), on Safari on a Mac: CMD + Option + U. It'll find all the "Viewed" unchecked checkboxes for files having Carthage
in their path and "click" them. Thereafter, select the filter to not show files that are viewed.
Upvotes: 6
Reputation: 20630
Github supports this now with a .gitattributes
file.
Create a .gitattributes
file in the root of the repository.
Use the linguist-generated attribute to mark or unmark paths that you would like to be ignored for the repository's language statistics and hidden by default in diffs.
For example, to mark search/index.json as a generated file, add this line to .gitattributes
:
search/index.json linguist-generated=true
Upvotes: 34
Reputation: 6882
To exclude a certain folder, I've made a tricky script that you can execute via the DevTools.
const fileElements = document.querySelectorAll("*[data-path*='vendor']")
fileElements.forEach(el => el.parentElement.remove())
This will remove any file diffs that matches %vendor%
, in my case.
Upvotes: 9
Reputation: 1329072
While you cannot exclude files from a Pull Request, you can (since Dec. 2018) filter them.
See "Pull request file filter":
In the “Files changed” tab of a pull request you can now:
- filter by file type or
- hide all deleted files in order to stay focused on the diffs that you care about.
See the documentation "Filtering files in a pull request by file type"
You can see an animated version of that new feature in this tweet.
And don't forget you can already show only file names, with a collapse all/show all toggle, with Alt+Click on the arrow in the diff view.
Note: the filter does not support regexes for now. For that, you would still need a Chrome extension.
Upvotes: 3
Reputation: 758
Github now has a little more functionality to navigate a pull request.
You can filter and jump to specific files in a pull request. Pressing t
gives you access to this functionality anywhere in the pull request.
You can also, as you mentioned, keep the files you don't want to review in a separate commit. Then you can take advantage of the commit filter feature, which lets you view the changes from just one commit rather than the entire pull request. Pressing c
brings up this selector, and p
and n
allow you to move to the previous and next commit, respectively.
?
brings up the list of keyboard shortcuts.
Source: https://github.com/blog/2123-more-code-review-tools
Upvotes: 4
Reputation: 7484
Currently GitHub does not support a way to exclude files or folders from the pull request.
If I had this problem while sending pull requests and it was something that was causing pain to my development team I can only think of the following:
The goal would be to exclude the folders and files from the difference but at the same time you don't want to merge the changes of the services before the whole pull request is ready. This solution is not ideal but you could:
A
B
B
to A
and you'll only see what you are interested on.A few things I don't like with this suggestion:
Maybe someone has a better flow for this, but I had the same issue with distribution files which I pushed upstream and I dealt with it by just passing them completely. However I imagine your use case is much trickier than mine.
Hope this helps or it gives other users something to start on.
Upvotes: 1