Skip to content

Conversation

@neilpower
Copy link
Contributor

@neilpower neilpower commented Oct 31, 2022

Description / Purpose

Adding a calculation of the median age of a project and teams' flags into the Slack messages

Types of changes

What types of changes does your code ?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Todos

  • Tests
  • Documentaiton

Screenshots

Questions / Notes

Learning / Resources

Copy link

@steve-curran steve-curran left a comment

Choose a reason for hiding this comment

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

Looks good. Let me know when it's ready for full review.

I've never written kotlin but I have written scala once the appropriate tests have been added. This looks similar, though I'm sure some of the nuances are lost on me.

* Formats a message about the total flag count in the system based on the [teamFlags]
*/
private fun formatTotalCountMessage(totalFlagCount: Int): String {
private fun formatTotalCountMessage(teamFlags: List<FlagDetail>): String {

Choose a reason for hiding this comment

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

minor: If we follow the principle of least knowledge here and pass flagSize and medianAgeInDays as arguments, this function may be easier to test as we then do not need to mock/instantiate the teamFlags object to pass in.


private const val MILLISECONDS_IN_A_DAY = 1000 * 60 * 60 * 24
fun List<FlagDetail>.getMedianAgeInDays(): Long = this.sortedBy { it.creationDate }.let { flagDetails ->
if (flagDetails.size % 2 == 0) {

Choose a reason for hiding this comment

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

Excuse my lack of kotlin knowledge here.

Is it possible to extract flagDetails.size / 2 like statements to meaningful variables like medianFlag here to make this code easier to digest?

Can we utilize a guard clause to reduce the cognitive complexity of this block?

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