-
Notifications
You must be signed in to change notification settings - Fork 21
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
[GH-47] [FIX] Agenda item number should get updated if the items of the agenda are deleted #90
Conversation
Codecov Report
@@ Coverage Diff @@
## master #90 +/- ##
==========================================
- Coverage 26.03% 24.56% -1.47%
==========================================
Files 7 7
Lines 315 403 +88
==========================================
+ Hits 82 99 +17
- Misses 216 287 +71
Partials 17 17
Continue to review full report at Codecov.
|
@sanjaydemansol LGTM |
@sanjaydemansol i forgot to add the review so i will check it again and will add the review. |
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.
LGTM, Its Working as Expected.
@sanjaydemansol @hanzei This PR is Tested From my side but i don't have pull review request for this PR, can someone send me that. |
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.
Great work @sanjaydemansol! I have some requests regarding error handling and writing unit tests
server/command.go
Outdated
} | ||
|
||
var ( | ||
messageRegexFormat = regexp.MustCompile(fmt.Sprintf(`(?m)^#### #%s(?P<date>.*) ([0-9]+)\) (?P<message>.*)?$`, prefix)) |
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.
I'm not verse enough in regex to gauge the stability of this. @hanzei @levb Can you take a look at this? This regex is meant to parse an agenda post's header.
@sanjaydemansol Can you please provide unit tests to assert that the code works under different circumstances?
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.
Note that MustCompile
will panic if the regex doesn't compile. Can we instead use Compile
and check for the error? Probably a good idea to make sure we're doing this elsewhere as well
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.
Added for my part, the other case is in the global scope.
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.
Thanks for implementing the changes @sanjaydemansol 👍 I have a few more comments
server/command.go
Outdated
return responsef("Error calculating list number") | ||
numQueueItems, itemErr := calculateQueueItemNumberAndUpdateOldItems(meeting, args, p, hashtag) | ||
if itemErr != nil { | ||
return responsef(err.Error()) |
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.
return responsef(err.Error()) | |
return responsef(itemErr.Error()) |
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 log this error as well?
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.
Sure, it is done.
server/command.go
Outdated
} | ||
|
||
var ( | ||
messageRegexFormat = regexp.MustCompile(fmt.Sprintf(`(?m)^#### #%s(?P<date>.*) ([0-9]+)\) (?P<message>.*)?$`, prefix)) |
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.
Note that MustCompile
will panic if the regex doesn't compile. Can we instead use Compile
and check for the error? Probably a good idea to make sure we're doing this elsewhere as well
server/meeting.go
Outdated
@@ -61,6 +65,45 @@ func (p *Plugin) SaveMeeting(meeting *Meeting) error { | |||
return nil | |||
} | |||
|
|||
func calculateQueueItemNumberAndUpdateOldItems(meeting *Meeting, args *model.CommandArgs, p *Plugin, hashtag string) (int, error) { | |||
searchResults, appErr := p.API.SearchPostsInTeamForUser(args.TeamId, args.UserId, model.SearchParameter{Terms: &hashtag}) |
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 want to scope this post search to the current channel as well, not just the current team
searchResults, appErr := p.API.SearchPostsInTeamForUser(args.TeamId, args.UserId, model.SearchParameter{Terms: &hashtag}) | |
c, appErr := p.API.GetChannel(args.ChannelId) | |
if appErr != nil {...} | |
terms := fmt.Sprintf("in:%s %s", c.Name, hashtag) | |
searchResults, appErr := p.API.SearchPostsInTeamForUser(args.TeamId, args.UserId, model.SearchParameter{Terms: &terms}) |
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.
Also I think this method should be defined on Plugin
instead of passing it in as a parameter
server/meeting.go
Outdated
counter++ | ||
if updateErr != nil { | ||
return 0, errors.Wrap(updateErr, "Error updating post") | ||
} |
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.
For readability, can we increment counter after the if block?
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.
done
server/meeting.go
Outdated
Id: post.Id, | ||
UserId: args.UserId, | ||
ChannelId: args.ChannelId, | ||
RootId: args.RootId, |
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.
I don't think we should change the post author or root id here
Id: post.Id, | |
UserId: args.UserId, | |
ChannelId: args.ChannelId, | |
RootId: args.RootId, | |
Id: post.Id, | |
UserId: post.UserId, | |
ChannelId: post.ChannelId, | |
RootId: post.RootId, |
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.
Yeah, right. Done.
return 0, errors.Wrap(updateErr, "Error updating post") | ||
} | ||
} | ||
return counter, nil |
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 add a newline before this for readability? We basically want to always add a newline after the end of a loop or if block
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.
done
p.API.LogDebug(err.Error()) | ||
return 0, errors.New(err.Error()) | ||
} | ||
_, updateErr := p.API.UpdatePost(&model.Post{ |
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.
Please add a newline after the if block above
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.
done
} | ||
return hashtagDateFormat, parsedMeetingMessage, nil | ||
} | ||
return hashtagDateFormat, ParsedMeetingMessage{}, errors.New("failed to parse meeting post's header") |
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.
Please add newlines here
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.
added
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.
LGTM, just a few non-blocking suggestions
server/command.go
Outdated
// ParsedMeetingMessage is meeting message after being parsed | ||
type ParsedMeetingMessage struct { | ||
date string | ||
number string // TODO we don't need it right now |
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.
For what feature will we remove this TODO comment?
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.
I can't recall, I removed the comment.
server/command.go
Outdated
@@ -132,6 +140,11 @@ func (p *Plugin) executeCommandQueue(args *model.CommandArgs) *model.CommandResp | |||
return responsef("Missing parameters for queue command") | |||
} | |||
|
|||
meeting, err := p.GetMeeting(args.ChannelId) | |||
if err != nil { | |||
p.API.LogError("failed to get meeting for channel", "err", err.Error(), "channel_id:", args.ChannelId) |
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.
p.API.LogError("failed to get meeting for channel", "err", err.Error(), "channel_id:", args.ChannelId) | |
p.API.LogError("failed to get meeting for channel", "err", err.Error(), "channel_id", args.ChannelId) |
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.
done
server/meeting.go
Outdated
terms := fmt.Sprintf("in:%s %s", c.Name, hashtag) | ||
searchResults, appErr := p.API.SearchPostsInTeamForUser(args.TeamId, args.UserId, model.SearchParameter{Terms: &terms}) | ||
if appErr != nil { | ||
return 0, errors.Wrap(appErr, "Error calculating list number") |
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.
return 0, errors.Wrap(appErr, "Error calculating list number") | |
return 0, errors.Wrap(appErr, "Error searching posts to find hashtags") |
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.
Done
server/meeting.go
Outdated
}) | ||
|
||
if updateErr != nil { | ||
return 0, errors.Wrap(updateErr, "Error updating post") | ||
} | ||
counter++ |
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.
Don't feel obligated to implement this suggestion, but the newlines are meant to separate different operations. Since this updateErr
is logically coupled with the "block" above, we don't need the newline between them. The block above actually not even a block, it's a function call with a struct. If it was an actual loop/if statement then it would make since to insert a newline after it.
Suggestion: We can remove the newline above this if statement. But we should always have a newline after if statements and loops. This is because after the block is finished, we are done both checking the value and processing its conditional logic. We then move on to something unrelated, thus the newline helps signal this intention.
}) | |
if updateErr != nil { | |
return 0, errors.Wrap(updateErr, "Error updating post") | |
} | |
counter++ | |
}) | |
if updateErr != nil { | |
return 0, errors.Wrap(updateErr, "Error updating post") | |
} | |
counter++ |
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.
@mickmister Thank you so much for highlighting that; I understood. Newlines are finally demystified for me.😊
@dipak-demansol This is ready for review |
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.
LGTM Tested it in the Chat and Thread Section.
Summary
Fixes #47
Now, Whenever we add new agenda item. Plugin searches for old messages for that hashtag.
If some item is missing(deleted), it fixes numbering for all items.
Testing
Ensure that the agenda plugin is installed and enabled.
Go to a channel header and edit the agenda settings to update the prefix and
Use command /agenda queue to queue at least 3 items as following:
/agenda queue item 1
/agenda queue item 2
/agenda queue item 3
Click on the agenda hashtag to open up the agenda list on the RHS.
On the RHS, click the post menu for item 1 (or the first item that was queued) and delete the agenda item.
Ensure that now there are only 2 items for that agenda hashtag: item 2 and item 3 on the RHS.
Add a new agenda item: /agenda queue new item.
Click on the hashtag to refresh the RHS.
Outcome: The RHS has 3 agenda items numbered 1), 2) and 3)
Ticket Link
#47