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

[GH-47] [FIX] Agenda item number should get updated if the items of the agenda are deleted #90

Merged
merged 5 commits into from
Dec 15, 2021

Conversation

sanjaydemansol
Copy link
Contributor

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


@codecov
Copy link

codecov bot commented Sep 17, 2021

Codecov Report

Merging #90 (c5abeee) into master (2f22484) will decrease coverage by 1.46%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
server/command.go 0.00% <0.00%> (ø)
server/meeting.go 40.00% <0.00%> (-23.05%) ⬇️
server/main.go 0.00% <0.00%> (ø)
server/manifest.go 100.00% <0.00%> (ø)
server/configuration.go 0.00% <0.00%> (ø)
server/utils.go 95.12% <0.00%> (+1.18%) ⬆️
server/plugin.go 25.74% <0.00%> (+3.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f22484...c5abeee. Read the comment docs.

@dipak-demansol
Copy link

@sanjaydemansol LGTM

@hanzei hanzei added the 2: Dev Review Requires review by a core committer label Sep 20, 2021
@dipak-demansol dipak-demansol added the QA Review Done PR has been approved by QA label Sep 27, 2021
@dipak-demansol
Copy link

@sanjaydemansol i forgot to add the review so i will check it again and will add the review.

Copy link

@dipak-demansol dipak-demansol left a 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.

@dipak-demansol
Copy link

@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.

@mickmister mickmister added this to the v0.3.0 milestone Oct 19, 2021
@mickmister mickmister self-requested a review October 19, 2021 05:31
Copy link
Contributor

@mickmister mickmister left a 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 Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
}

var (
messageRegexFormat = regexp.MustCompile(fmt.Sprintf(`(?m)^#### #%s(?P<date>.*) ([0-9]+)\) (?P<message>.*)?$`, prefix))
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

server/command.go Outdated Show resolved Hide resolved
server/command.go Outdated Show resolved Hide resolved
@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Nov 30, 2021
@sanjaydemansol sanjaydemansol removed the Awaiting Submitter Action Blocked on the author label Dec 1, 2021
@hanzei hanzei removed the QA Review Done PR has been approved by QA label Dec 1, 2021
Copy link
Contributor

@mickmister mickmister left a 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

return responsef("Error calculating list number")
numQueueItems, itemErr := calculateQueueItemNumberAndUpdateOldItems(meeting, args, p, hashtag)
if itemErr != nil {
return responsef(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return responsef(err.Error())
return responsef(itemErr.Error())

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, it is done.

}

var (
messageRegexFormat = regexp.MustCompile(fmt.Sprintf(`(?m)^#### #%s(?P<date>.*) ([0-9]+)\) (?P<message>.*)?$`, prefix))
Copy link
Contributor

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

@@ -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})
Copy link
Contributor

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

Suggested change
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})

Copy link
Contributor

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

Comment on lines 99 to 102
counter++
if updateErr != nil {
return 0, errors.Wrap(updateErr, "Error updating post")
}
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 93 to 96
Id: post.Id,
UserId: args.UserId,
ChannelId: args.ChannelId,
RootId: args.RootId,
Copy link
Contributor

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

Suggested change
Id: post.Id,
UserId: args.UserId,
ChannelId: args.ChannelId,
RootId: args.RootId,
Id: post.Id,
UserId: post.UserId,
ChannelId: post.ChannelId,
RootId: post.RootId,

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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{
Copy link
Contributor

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

Copy link
Contributor Author

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add newlines here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@hanzei hanzei added the 3: QA Review Requires review by a QA tester label Dec 7, 2021
Copy link
Contributor

@mickmister mickmister left a 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

// ParsedMeetingMessage is meeting message after being parsed
type ParsedMeetingMessage struct {
date string
number string // TODO we don't need it right now
Copy link
Contributor

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?

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 can't recall, I removed the comment.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return 0, errors.Wrap(appErr, "Error calculating list number")
return 0, errors.Wrap(appErr, "Error searching posts to find hashtags")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 104 to 109
})

if updateErr != nil {
return 0, errors.Wrap(updateErr, "Error updating post")
}
counter++
Copy link
Contributor

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.

Suggested change
})
if updateErr != nil {
return 0, errors.Wrap(updateErr, "Error updating post")
}
counter++
})
if updateErr != nil {
return 0, errors.Wrap(updateErr, "Error updating post")
}
counter++

Copy link
Contributor Author

@sanjaydemansol sanjaydemansol Dec 14, 2021

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.😊

@hanzei
Copy link
Contributor

hanzei commented Dec 14, 2021

@dipak-demansol This is ready for review

@hanzei hanzei removed the 2: Dev Review Requires review by a core committer label Dec 14, 2021
Copy link

@dipak-demansol dipak-demansol left a 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.

@hanzei hanzei added 4: Reviews Complete All reviewers have approved the pull request and removed 3: QA Review Requires review by a QA tester labels Dec 15, 2021
@hanzei hanzei merged commit bc0e65d into mattermost-community:master Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Agenda item number should get updated if the items of the agenda are deleted
5 participants