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

Promote Github PR ID to int64 #2446

Merged
merged 4 commits into from
Feb 28, 2024
Merged

Promote Github PR ID to int64 #2446

merged 4 commits into from
Feb 28, 2024

Conversation

dmjb
Copy link
Contributor

@dmjb dmjb commented Feb 27, 2024

Summary

Fixes #2443

PR ID and line number are were previously downcasted to int32 in a number of places despite being mostly treated as an int64 type. While the likelihood of either of these values exceeding a 32-bit MAX_INT are minimal, this change makes them 64-bit to err on the side of caution.

EDIT: After discussion with the team, we have decided to leave the line numbers as int32. The rationale is that if the diffs ever get that large, we're going to have a whole bunch of other problems to deal with.

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

Fixes #2443

PR ID and line number are were previously downcasted to int32 in a
number of places despite being mostly treated as an int64 type. While
the likelihood of either of these values exceeding a 32-bit MAX_INT are
minimal, this change makes them 64-bit to err on the side of caution.
@dmjb dmjb requested a review from a team as a code owner February 27, 2024 16:31
@coveralls
Copy link

coveralls commented Feb 27, 2024

Coverage Status

coverage: 38.591% (-0.002%) from 38.593%
when pulling 9005d6d on pr-id-downcast
into a10ba30 on main.

eleftherias
eleftherias previously approved these changes Feb 27, 2024
Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

The code change looks good! For the commit message, our standard is to capitalise the subject line, so this one should be "Promote...". You can change the subject when merging.

@dmjb dmjb changed the title promote PR ID and line number to int64 [DO NOT MERGE] promote PR ID and line number to int64 Feb 27, 2024
evankanderson
evankanderson previously approved these changes Feb 27, 2024
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

I wouldn't expand the line_number counter, that seems overly optimistic.

@@ -253,7 +253,7 @@ message PrContents {
repeated Line patch_lines = 3;

message Line {
int32 line_number = 1;
int64 line_number = 1;
Copy link
Member

Choose a reason for hiding this comment

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

I'd leave this as an int32, because I'm terrified of needing more than 2B line numbers for a patch.

Copy link
Contributor

@teodor-yanev teodor-yanev Feb 27, 2024

Choose a reason for hiding this comment

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

Yeah, if there's a PR file exceeding 2^32 (well, 2147483647 considering the "-" in) number of lines, this counter is the last thing to worry about 😄

@@ -216,7 +216,7 @@ func ingestFileForFullDiff(filename, patch, patchUrl string) (*pb.PrContents_Fil
} else if strings.HasPrefix(line, "+") {
result = append(result, &pb.PrContents_File_Line{
Content: line[1:],
LineNumber: int32(currentLineNumber),
LineNumber: currentLineNumber,
Copy link
Member

Choose a reason for hiding this comment

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

We could just declare currentLineNumber as int32 here on line 206, particularly since we parse it as an int32 on line 212.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried this, but since strconv.ParseInt returns (int64, error) we can't just wrap the return value in int32().

@@ -735,7 +735,7 @@ func getPullRequestInfoFromPayload(

return &pb.PullRequest{
Url: prUrl,
Number: int32(prNumber),
Number: int64(prNumber),
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming we can't use JQReadFrom[int64] on line 721 because the underlying API understands that JSON numbers are floats?

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 think so. There is an issue which tracks this: #965

@dmjb dmjb changed the title [DO NOT MERGE] promote PR ID and line number to int64 [DO NOT MERGE] Promote PR ID and line number to int64 Feb 27, 2024
if diffs are this big, we have problems anyway
@dmjb dmjb dismissed stale reviews from evankanderson and eleftherias via 30dc9df February 27, 2024 17:40
@dmjb dmjb changed the title [DO NOT MERGE] Promote PR ID and line number to int64 Promote PR ID and line number to int64 Feb 27, 2024
@dmjb dmjb changed the title Promote PR ID and line number to int64 Promote Github PR ID to int64 Feb 27, 2024
@dmjb dmjb merged commit b87504e into main Feb 28, 2024
21 checks passed
@dmjb dmjb deleted the pr-id-downcast branch February 28, 2024 14:04
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.

Certain Github IDs are downcast to int32
6 participants