-
Notifications
You must be signed in to change notification settings - Fork 159
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
MM-17468: Accept a number of days instead of two date arguments in /incident test bulk-data
#549
Conversation
Hello @alankan886, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. Per the Mattermost Contribution Guide, we need to add you to the list of approved contributors for the Mattermost project. Please help complete the Mattermost contribution license agreement? This is a standard procedure for many open source projects. Please let us know if you have any questions. We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team. |
/check-cla |
/update-branch |
Thank you for your contribution, @alankan886 🎉 We will review it as soon as we can! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me from a code standpoint, thanks @alankan886 !
server/command/command.go
Outdated
if err != nil { | ||
r.postCommandResponse(fmt.Sprintf("The provided value for the last possible date, '%s', is not a valid date. It needs to be in the format 2020-01-31.", params[3])) | ||
r.warnUserAndLogErrorf("unable to parse in location on time.Now(): %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r.warnUserAndLogErrorf("unable to parse in location on time.Now(): %v", err) | |
r.warnUserAndLogErrorf("unable to parse in location on time.Now().AddDate: %v", err) |
Thank you for the comment @cpoile! The suggested change is made and pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @alankan886, it looks great! 🎉
I left some suggestions below.
server/command/command.go
Outdated
return | ||
} | ||
|
||
end, err := time.ParseInLocation("2006-01-02", params[3], time.Now().Location()) | ||
begin, err := time.ParseInLocation("2006-01-02", time.Now().AddDate(0, 0, -days).Format("2006-01-02"), time.Now().Location()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simplify this?
begin, err := time.ParseInLocation("2006-01-02", time.Now().AddDate(0, 0, -days).Format("2006-01-02"), time.Now().Location()) | |
begin := time.Now().AddDate(0, 0, -days) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, not sure if this matters, but they are slightly different where time.ParseInLocation()
would give 2021-05-12 00:00:00
(no specific time) and time.Now()
would give 2021-05-12 19:53:00.596493
(specific time). If you don't mind the differences, I'm happy to change them. Let me know if you have any thoughts on this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need a high specificity here, as the dates will be picked randomly in the range of dates. So I'd vote for making the code more readable using just time.Now()
.
server/command/command.go
Outdated
return | ||
} | ||
|
||
end, err := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Now().Location()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
end, err := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Now().Location()) | |
end := time.Now() |
server/command/command.go
Outdated
@@ -130,7 +130,7 @@ func getAutocompleteData(addTestCommands bool) *model.AutocompleteData { | |||
testCreate.AddTextArgument("Name of the incident", "Incident name", "") | |||
test.AddCommand(testCreate) | |||
|
|||
testData := model.NewAutocompleteData("bulk-data", "[ongoing] [ended] [begin] [end] [seed]", "Generate random test data in bulk") | |||
testData := model.NewAutocompleteData("bulk-data", "[ongoing] [ended] [days] [seed]", "Generate random test data in bulk") | |||
testData.AddTextArgument("An integer indicating how many ongoing incidents will be generated.", "Number of ongoing incidents", "") | |||
testData.AddTextArgument("An integer indicating how many ended incidents will be generated.", "Number of ended incidents", "") | |||
testData.AddTextArgument("Date in format 2020-01-31", "First possible creation date", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to update these descriptions. We need to modify this one as shown here and remove the next line
testData.AddTextArgument("Date in format 2020-01-31", "First possible creation date", "") | |
testData.AddTextArgument("An integer n. The incidents generated will have a start date between n days ago and today.", "Range of days for the incident start date", "") |
@justinegeffen may have a better wording for this.
@itao, I think it is ok getting rid of the old way of creating the test incidents and use instead just a number of days. What this means effectively is that it will be much easier to specify the number of days you want the incidents to go back (you just write that number), but also that it is now impossible to specify an end date, so the range will always be Is that ok? Or do we want to maintain the old way of generating this data? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! It makes the command one-clickable in a playbook which is helpful for the customer demo playbook. Nice!
/update-branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, @alankan886, thank you very much! Skipping QA as it is an internal, testing command.
Summary
This PR is for simplifying two date arguments in
/incident test bulk-data
into one number argument. Instead of/incident test bulk-data 10 3 2020-01-31 2020-11-22 2
, now it's/incident test bulk-data 10 3 342 2
. And the number of days is expected to be larger than 0.Ticket Link
Fixes mattermost/mattermost#17468