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

Fix failing scan-remote-repo command #241

Merged
merged 7 commits into from
Oct 27, 2021

Conversation

sushantmimani
Copy link
Contributor

To help us get this pull request reviewed and merged quickly, please be sure to include the following items:

  • Tests (if applicable)
  • Documentation (if applicable)
  • Changelog entry
  • A full explanation here in the PR description of the work done

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Tests
  • Other

Backward Compatibility

Is this change backward compatible with the most recently released version? Does it introduce changes which might change the user experience in any way? Does it alter the API in any way?

  • Yes (backward compatible)
  • No (breaking changes)

What's new?

The recent live-output & pygit2 changes broke existing remote repo scans because scanner.scan was being
called from the subcommand and the cloned directory was being deleted before the scan could actually happen.
The original process_issues callback has now been moved into util and is called from the sub-commands to
fix this issue. The main callback only handles exit status now.

sushantmimani and others added 2 commits October 26, 2021 14:49
The recent live-output & pygit2 changes broke existing remote repo scans because `scanner.scan` was being
called from the subcommand and the cloned directory was being deleted before the scan could actually happen.
The original process_issues callback has now been moved into util and is called from the sub-commands to
fix this issue. The main callback only handles exit status now.
@sushantmimani sushantmimani requested a review from a team as a code owner October 26, 2021 23:11
@sushantmimani sushantmimani requested review from rscottbailey, mxhenry-godaddy, rbailey-godaddy and tarkatronic and removed request for a team October 26, 2021 23:12
Copy link
Contributor

@tarkatronic tarkatronic left a comment

Choose a reason for hiding this comment

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

Just one small change.

Also, doesn't the scan-folder command need to be updated as well?

tartufo/cli.py Outdated
@@ -282,26 +280,9 @@ def main(ctx: click.Context, **kwargs: config.OptionTypes) -> None:
@click.pass_context
def process_issues(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is no longer doing any actual processing of issues, let's rename it to something more appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

I keep coming up with stupid-sounding redundant names. "return_exit_status" or "compute_return_code" or something oxymoronic that covers the 2 lines of code that's all that's left...

Copy link
Contributor

@rbailey-godaddy rbailey-godaddy left a comment

Choose a reason for hiding this comment

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

Just the one rename @tarkatronic already pointed out.

tartufo/cli.py Outdated
@@ -282,26 +280,9 @@ def main(ctx: click.Context, **kwargs: config.OptionTypes) -> None:
@click.pass_context
def process_issues(
Copy link
Contributor

Choose a reason for hiding this comment

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

I keep coming up with stupid-sounding redundant names. "return_exit_status" or "compute_return_code" or something oxymoronic that covers the 2 lines of code that's all that's left...

This addresses godaddy#243. We had two problems:

1. Diff was generated in backwards order; it is clear from:

https://pygit2.readthedocs.io/en/latest/recipes/git-show.html

that if "show diff" is implemented as:

```
>>> diff = repo.diff(commit.parents[0], commit)
```

then the previous commit must be the first argument (and in fact you can
see just above where prev_commit is precisely commit.parents[0]).

2. Commit metadata was retrieved for the previous commit

I verified running tartufo against itself that the reported commit hashes
and diffs now match what "git show" actually displays.

Unit test changes were restricted to swapping the order of the commits in
expected call signatures for repo.diff().

I resisted the temptation to collapse the special-case logic for the
lead commit into the earlier block that looks for it, in order to minimize
the size of this commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tartufo does not generate correct git content in issue descriptions
5 participants