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: Improve error logging for push events without a before sha (like tag pushes) #30

Merged
merged 3 commits into from
Mar 9, 2023

Conversation

sheck
Copy link
Member

@sheck sheck commented Feb 24, 2023

When a push event is sent for a tag, the before SHA is set to 0000000000000000000000000000000000000000 — which is not something we can run a diff against.

We were trying to pass it to rubocop, where it would silenty fail as rubocop fatal: bad object 0000000000000000000000000000000000000000

So let's just skip trying to run rubocop in those instances.


@sheck sheck marked this pull request as ready for review February 24, 2023 00:36
@sheck sheck requested a review from a team as a code owner February 24, 2023 00:36
@sheck sheck changed the title fix: Don't try to run for push events with no before sha (like tag pushes) fix: Don't try to run for push events without a before sha (like tag pushes) Feb 24, 2023
Copy link
Member

@danielma danielma 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 figuring this one out. It's a good change. My question is definitely not a blocker, but I would love your thoughts on whether it's worth trying to make this sha validation a little more resilient into the future?

action/action.rb Outdated
@@ -101,7 +101,13 @@ def report_offense?(offense, change_ranges:)
else
event.pull_request.base.sha
end
annotations = generate_annotations(compare_sha: previous_sha)
ActionUtils.debug "Using this as previous sha: #{previous_sha}"
annotations = if previous_sha == '0000000000000000000000000000000000000000'
Copy link
Member

Choose a reason for hiding this comment

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

This kind of exact check on a magic value feels risky to me. Like, what if the previous sha is nil or, an empty string, or any other value?

What would you think about opening up this condition, or maybe even reversing them?

Option 1 (something more open):

if previous_sha.chars.uniq == ["0"]

Option 2 (broader validation check)

if previous_sha.length == 40 && previous_sha.chars.uniq.many?
  generate_annotations(compare_sha: previous_sha)
else
  ActionUtils.debug "Skipping check run since we don't have a valid sha to compare #{previous_sha.inspect}"
  []
end

Copy link
Member

Choose a reason for hiding this comment

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

I was feeling a similar thing about the relative riskiness of this check.

I quickly started zooming out a bit to how this particular problem might show up in other places.

Do we want to silently return no annotations in this scenario or do we want to throw an error? This seems like an exceptional circumstance where use an error to indicate the issue (maybe even checking the presence of the sha with git cat-file -e {sha}?) seems reasonable.

That codifies the underlying issue, and then we can prevent the issue in our repo (and same for other folks using this action) by filtering out problematic pushes?

In general, does saying something went just fine when we didn't do any of the work feel potentially misleading?

(if this broader conversation needs to wait in order to get a quick fix out, I'm good with that too)

Copy link
Member Author

Choose a reason for hiding this comment

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

These are all great points. Here's what I'm thinking:

  1. Validations could be wider, I'll work on that
  2. It does feel weird that it would be listed the same as a successful check when this happens. I'll look into seeing what we can do here to change that.

@sheck sheck requested review from danielma and molawson March 7, 2023 23:15
@sheck sheck changed the title fix: Don't try to run for push events without a before sha (like tag pushes) fix: Improve error logging for push events without a before sha (like tag pushes) Mar 8, 2023
@sheck sheck merged commit a896077 into main Mar 9, 2023
@sheck sheck deleted the ns/fixtagpush branch March 9, 2023 15:56
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.

3 participants