Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow excluding file paths to filter out commits #1875

Merged
merged 13 commits into from
Apr 10, 2023

Conversation

alex-enchi
Copy link
Contributor

@alex-enchi alex-enchi commented Mar 13, 2023

Idea is to exclude commits if all files in those commits are from specific paths.

In my case I have multiple packages in packages and . umbrella package. Some of packages are different and handled by different workflow and I need to exclude those from umbrella.

Tested only with config-file

Note: I think it is possible to break it with "package/foo":{"exclude-paths":["package/foo"]} but I did not test it yet.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #908🦕

@alex-enchi alex-enchi requested review from a team as code owners March 13, 2023 22:47
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Mar 13, 2023
@google-cla
Copy link

google-cla bot commented Mar 13, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Mar 13, 2023
@alex-enchi alex-enchi changed the title feature(monorepos): allow excluding file paths to filter out commits feat: allow excluding file paths to filter out commits Mar 14, 2023
Copy link
Contributor

@chingor13 chingor13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this!

I think you'll actually want to combine the exclude logic into the CommitSplit class (see the inline comment).

Comment on lines 50 to 52
!commit.files.every(file =>
excludePaths.some(path => file.indexOf(`${path}/`) === 0)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an edge case here that will be difficult to account for if you split the exclude from the include logic. The original CommitSplit class does not strip files out that don't match the path -- it's just used to determine if that commit touches that directory (it can touch multiple components).

This looks like it's checking if there's any file that does not match the exclude path pattern. Consider a commit that touches:

  • a/b/c
  • d/e/f
  • d/e/g

We have 2 components with paths a and d and d is configured to exclude d/e/*. This commit has a file (a/b/c) that does not match the exclude pattern, and will not be excluded. If I understand the feature correctly, this commit should be excluded (there's no commit under path d that does not include d/e/*).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, true there is such case.
Main reason for splitting this into two (aside of not adding additional logic tree to commit split) was the need to handle exclusion on . root scope
Thanks for catching up that usecase! Will update soon with changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent some time on adding the logic into commit split, but in the end decided to handle exclusion logic separately.
I have updated it to handle exclusion only based on relevant to project files.

Main reasoning of keeping it as "split" then "filter" is logic is a bit cleaner that way

  1. no special case to iterate over .
  2. commit split is not bloated with additional cases to handle and does only 1 thing, it splits commits per package

What do you think?
All my attempts to include that logic in commit-split itself did not look pretty, unfortunately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chingor13 i think now it covers all needed usecases. Could you take a look when you have time?

@chingor13 chingor13 merged commit a9bed82 into googleapis:main Apr 10, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature(monorepos): allow excluding file paths when create release PRs
2 participants