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

For slack triage notifications, use business hours left to notify hourly #735

Merged
merged 2 commits into from
Dec 27, 2023

Conversation

hubertdeng123
Copy link
Member

@hubertdeng123 hubertdeng123 commented Dec 22, 2023

It's a bit annoying when in the morning, a team gets surprised with a slack notification of an issue that is due in 24 minutes. This is because at the end of the day, we're not necessarily notifying teams of issues due the next morning since it is technically over 12 hours away.

Also cleans up some unneeded async/await declarations

Closes this: #719

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (c4d052f) 86.13% compared to head (6265d1b) 86.19%.
Report is 4 commits behind head on main.

Files Patch % Lines
src/brain/issueLabelHandler/followups.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #735      +/-   ##
==========================================
+ Coverage   86.13%   86.19%   +0.06%     
==========================================
  Files         116      116              
  Lines        3217     3231      +14     
  Branches      655      656       +1     
==========================================
+ Hits         2771     2785      +14     
  Misses        432      432              
  Partials       14       14              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

const triageBy = '2023-12-22T18:00:00.000Z';
const now = moment('2023-12-22T01:00:00.000Z');
expect(
getBusinessHoursLeft(
Copy link
Contributor

Choose a reason for hiding this comment

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

When a function signature is more than ~3 args, I think named parameters are the way to go. In particular, the last 3 arguments here are all the same type (strings), and as someone unfamiliar with the codebase, it's quite hard to figure out what corresponds to what just by reading the invocation.

What if we did:

// At definition-site:
interface BusinessHoursLeft {
  triageBy: string,
  now: moment.Moment,
  repo: string,
  org: string,
  productArea: string
}
function getBusinessHoursLeft({ triageBy, now, repo, org, productArea }: BusinessHoursLeft {
  ...
}

// At call-site:
getBusinessHoursLeft({
          triageBy,
          now,
          repo: 'test-ttt-simple',
          org: 'getsentry',
          productArea: 'Other'
        })

Now I know what's what, and can catch errors that the type system can't (ex, swapped string args) more easily when scanning.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason why I did not do this is because it seemed explicit enough what was going on where the function is being called:

const businessHoursLeft = getBusinessHoursLeft(
        triageBy,
        now,
        repo,
        org,
        productArea
      );

This ambiguity would only exist for testing. This is not a super widely used function, so I'd rather not declare an interface for it. I'll clear up what the strings are by giving them names before passing them in if that's helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but that relies on the call-site naming its variables properly. If you use an interface, this is required, rather than optional, enforcing more readable code. The language even encourages this practice if you use an interface (you can just type the var name without stuttering), so it feels like a best practice.

In any case, I trust your judgment, just a small nit as a rather unfamiliar reader of the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are other functions in the file that could use cleaning up too. Creating an issue to get those resolved in a later PR:
#737

)
).toEqual(1);
});
it('should correctly calculate business hours over multiple days', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a test for holidays as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

).toEqual(9);
});
it('should correctly account for weekends when calculating business hours', function () {
const triageBy = '2023-01-17T18:00:00.000Z';
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious what happens when we don't include milliseconds (or do include microseconds) in an ISO8601 timestamp. I know that Python's deserializer sometimes barfed on that, which caused trouble and test flakes in the past. Maybe JS's is smarter though.

Copy link
Member Author

Choose a reason for hiding this comment

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

this will be fine, since the moment library will parse the timestamp without milliseconds properly

src/brain/issueLabelHandler/followups.ts Show resolved Hide resolved
repo,
org
);
// Two cases to handle.
Copy link
Contributor

Choose a reason for hiding this comment

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

Great comment!

src/webhooks/pubsub/slackNotifications.ts Show resolved Hide resolved
@hubertdeng123 hubertdeng123 merged commit f9457ee into main Dec 27, 2023
8 checks passed
@hubertdeng123 hubertdeng123 deleted the hubertdeng123/act-fast-issues-use-business-hours branch December 27, 2023 20:02
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.

2 participants