From 19f30a6d98d1cb2df9e21757fb66273ef752bc96 Mon Sep 17 00:00:00 2001 From: Sanjay Date: Fri, 17 Sep 2021 08:17:58 +0530 Subject: [PATCH 1/5] Re-queue an item for next meeting --- server/command.go | 100 ++++++++++++++++++++++++++++++++---- server/meeting.go | 17 ++++-- server/meeting_test.go | 2 +- server/utils.go | 19 +++++++ webapp/src/actions/index.js | 28 +++++++++- webapp/src/index.js | 6 ++- 6 files changed, 153 insertions(+), 19 deletions(-) diff --git a/server/command.go b/server/command.go index f53bb1a..043f76c 100644 --- a/server/command.go +++ b/server/command.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "regexp" "strings" "time" @@ -49,6 +50,9 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo case "queue": return p.executeCommandQueue(args), nil + case "requeue": + return p.executeCommandReQueue(args), nil + case "setting": return p.executeCommandSetting(args), nil @@ -69,7 +73,7 @@ func (p *Plugin) executeCommandList(args *model.CommandArgs) *model.CommandRespo weekday = int(parsedWeekday) } - hashtag, err := p.GenerateHashtag(args.ChannelId, nextWeek, weekday) + hashtag, err := p.GenerateHashtag(args.ChannelId, nextWeek, weekday, false, time.Now().Weekday()) if err != nil { return responsef("Error calculating hashtags") } @@ -147,25 +151,21 @@ func (p *Plugin) executeCommandQueue(args *model.CommandArgs) *model.CommandResp message = strings.Join(split[3:], " ") } - hashtag, error := p.GenerateHashtag(args.ChannelId, nextWeek, weekday) + hashtag, error := p.GenerateHashtag(args.ChannelId, nextWeek, weekday, false, time.Now().Weekday()) if error != nil { return responsef("Error calculating hashtags. Check the meeting settings for this channel.") } - searchResults, appErr := p.API.SearchPostsInTeamForUser(args.TeamId, args.UserId, model.SearchParameter{Terms: &hashtag}) - - if appErr != nil { - return responsef("Error calculating list number") + itemErr, numQueueItems := calculateQueItemNumber(args, p, hashtag) + if itemErr != nil { + return itemErr } - postList := *searchResults.PostList - numQueueItems := len(postList.Posts) - - _, appErr = p.API.CreatePost(&model.Post{ + _, appErr := p.API.CreatePost(&model.Post{ UserId: args.UserId, ChannelId: args.ChannelId, RootId: args.RootId, - Message: fmt.Sprintf("#### %v %v) %v", hashtag, numQueueItems+1, message), + Message: fmt.Sprintf("#### %v %v) %v", hashtag, numQueueItems, message), }) if appErr != nil { return responsef("Error creating post: %s", appErr.Message) @@ -174,6 +174,84 @@ func (p *Plugin) executeCommandQueue(args *model.CommandArgs) *model.CommandResp return &model.CommandResponse{} } +func calculateQueItemNumber(args *model.CommandArgs, p *Plugin, hashtag string) (*model.CommandResponse, int) { + searchResults, appErr := p.API.SearchPostsInTeamForUser(args.TeamId, args.UserId, model.SearchParameter{Terms: &hashtag}) + if appErr != nil { + return responsef("Error calculating list number"), 0 + } + postList := *searchResults.PostList + numQueueItems := len(postList.Posts) + return nil, numQueueItems + 1 +} + +func (p *Plugin) executeCommandReQueue(args *model.CommandArgs) *model.CommandResponse { + split := strings.Fields(args.Command) + + if len(split) <= 2 { + return responsef("Missing parameters for requeue command") + } + + meeting, err := p.GetMeeting(args.ChannelId) + if err != nil { + return responsef("Can't find the meeting") + } + + oldPostID := split[2] + postToBeReQueued, _ := p.API.GetPost(oldPostID) + var ( + prefix string + hashtagDateFormat string + ) + if matchGroups := meetingDateFormatRegex.FindStringSubmatch(meeting.HashtagFormat); len(matchGroups) == 4 { + prefix = matchGroups[1] + hashtagDateFormat = strings.TrimSpace(matchGroups[2]) + } + + var ( + messageRegexFormat = regexp.MustCompile(fmt.Sprintf(`(?m)^#### #%s(?P.*) [0-9]+\) (?P.*)?$`, prefix)) + ) + + if matchGroups := messageRegexFormat.FindStringSubmatch(postToBeReQueued.Message); len(matchGroups) == 3 { + originalPostDate := strings.ReplaceAll(strings.TrimSpace(matchGroups[1]), "_", " ") // reverse what we do to make it a valid hashtag + originalPostMessage := strings.TrimSpace(matchGroups[2]) + + today := time.Now() + local, _ := time.LoadLocation("Local") + formattedDate, _ := time.ParseInLocation(hashtagDateFormat, originalPostDate, local) + if formattedDate.Year() == 0 { + thisYear := today.Year() + formattedDate = formattedDate.AddDate(thisYear, 0, 0) + } + + if today.Year() <= formattedDate.Year() && today.YearDay() < formattedDate.YearDay() { + return responsef("Re-queing future items are not supported.") + } + + hashtag, err := p.GenerateHashtag(args.ChannelId, false, -1, true, formattedDate.Weekday()) + if err != nil { + return responsef("Error calculating hashtags. Check the meeting settings for this channel.") + } + + itemErr, numQueueItems := calculateQueItemNumber(args, p, hashtag) + if itemErr != nil { + return itemErr + } + + _, appErr := p.API.UpdatePost(&model.Post{ + Id: oldPostID, + UserId: args.UserId, + ChannelId: args.ChannelId, + RootId: args.RootId, + Message: fmt.Sprintf("#### %v %v) %v", hashtag, numQueueItems, originalPostMessage), + }) + if appErr != nil { + return responsef("Error creating post: %s", appErr.Message) + } + return responsef(fmt.Sprintf("Item has been Re-queued to %v", hashtag)) + } + return responsef("Make sure, message is in required format!") +} + func (p *Plugin) executeCommandHelp(args *model.CommandArgs) *model.CommandResponse { return responsef(helpCommandText) } diff --git a/server/meeting.go b/server/meeting.go index 7bfad8b..a3cca66 100644 --- a/server/meeting.go +++ b/server/meeting.go @@ -62,7 +62,7 @@ func (p *Plugin) SaveMeeting(meeting *Meeting) error { } // GenerateHashtag returns a meeting hashtag -func (p *Plugin) GenerateHashtag(channelID string, nextWeek bool, weekday int) (string, error) { +func (p *Plugin) GenerateHashtag(channelID string, nextWeek bool, weekday int, requeue bool, assignedDay time.Weekday) (string, error) { meeting, err := p.GetMeeting(channelID) if err != nil { return "", err @@ -75,9 +75,18 @@ func (p *Plugin) GenerateHashtag(channelID string, nextWeek bool, weekday int) ( return "", err } } else { - // Get date for the list of days of the week - if meetingDate, err = nextWeekdayDateInWeek(meeting.Schedule, nextWeek); err != nil { - return "", err + // user didn't provide any specific date, Get date for the list of days of the week + if !requeue { + if meetingDate, err = nextWeekdayDateInWeek(meeting.Schedule, nextWeek); err != nil { + return "", err + } + } else { + if len(meeting.Schedule) == 1 && meeting.Schedule[0] == assignedDay { // if this day is the only day selected in settings + nextWeek = true + } + if meetingDate, err = nextWeekdayDateInWeekSkippingDay(meeting.Schedule, nextWeek, assignedDay); err != nil { + return "", err + } } } diff --git a/server/meeting_test.go b/server/meeting_test.go index 4e24e25..6510e57 100644 --- a/server/meeting_test.go +++ b/server/meeting_test.go @@ -138,7 +138,7 @@ func TestPlugin_GenerateHashtag(t *testing.T) { jsonMeeting, err := json.Marshal(tt.args.meeting) tAssert.Nil(err) api.On("KVGet", tt.args.meeting.ChannelID).Return(jsonMeeting, nil) - got, err := mPlugin.GenerateHashtag(tt.args.meeting.ChannelID, tt.args.nextWeek, -1) + got, err := mPlugin.GenerateHashtag(tt.args.meeting.ChannelID, tt.args.nextWeek, -1, false, 1) if (err != nil) != tt.wantErr { t.Errorf("GenerateHashtag() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/server/utils.go b/server/utils.go index 799a076..3a1c3e3 100644 --- a/server/utils.go +++ b/server/utils.go @@ -72,6 +72,25 @@ func nextWeekdayDateInWeek(meetingDays []time.Weekday, nextWeek bool) (*time.Tim return nextWeekdayDate(meetingDay, nextWeek) } +func nextWeekdayDateInWeekSkippingDay(meetingDays []time.Weekday, nextWeek bool, dayToSkip time.Weekday) (*time.Time, error) { + if len(meetingDays) == 0 { + return nil, errors.New("missing weekdays to calculate date") + } + + todayWeekday := time.Now().Weekday() + + // Find which meeting weekday to calculate the date for + meetingDay := meetingDays[0] + for _, day := range meetingDays { + if todayWeekday <= day && day != dayToSkip { + meetingDay = day + break + } + } + + return nextWeekdayDate(meetingDay, nextWeek) +} + // nextWeekdayDate calculates the date of the next given weekday // from today's date. // If nextWeek is true, it will be based on the next calendar week. diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index fa540f7..3c5ca61 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -1,7 +1,8 @@ import {searchPostsWithParams} from 'mattermost-redux/actions/search'; - +import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; +import {Client4} from 'mattermost-redux/client'; import Client from '../client'; @@ -80,4 +81,27 @@ export function performSearch(terms) { return dispatch(searchPostsWithParams(teamId, {terms, is_or_search: false, include_deleted_channels: viewArchivedChannels, page: 0, per_page: 20}, true)); }; -} \ No newline at end of file +} + +export function requeueItem(itemId) { + return async (dispatch, getState) => { + const command = `/agenda requeue ${itemId}`; + await clientExecuteCommand(dispatch, getState, command); + return {data: true}; + }; +} + +export async function clientExecuteCommand(dispatch, getState, command) { + const currentChannel = getCurrentChannel(getState()); + const currentTeamId = getCurrentTeamId(getState()); + const args = { + channel_id: currentChannel?.id, + team_id: currentTeamId, + }; + + try { + return Client4.executeCommand(command, args); + } catch (error) { + return error; + } +} diff --git a/webapp/src/index.js b/webapp/src/index.js index 3a14357..cee038b 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -1,5 +1,5 @@ -import {updateSearchTerms, updateSearchResultsTerms, updateRhsState, performSearch, openMeetingSettingsModal} from './actions'; +import {updateSearchTerms, updateSearchResultsTerms, updateRhsState, performSearch, openMeetingSettingsModal, requeueItem} from './actions'; import reducer from './reducer'; @@ -19,6 +19,10 @@ export default class Plugin { (channelId) => { store.dispatch(openMeetingSettingsModal(channelId)); }); + + registry.registerPostDropdownMenuAction('Re-queue', (itemId) => { + store.dispatch(requeueItem(itemId)); + }); } } From 51a8315de533dfdb6372d1a64bed498badc163e3 Mon Sep 17 00:00:00 2001 From: Sanjay Date: Wed, 17 Nov 2021 22:58:39 +0530 Subject: [PATCH 2/5] - create test cases for nextWeekdayDateInWeekSkippingDay - updates based on feedback - bugfix for date allocation --- go.mod | 1 + go.sum | 2 ++ server/command.go | 31 ++++++++++++++++++--------- server/meeting.go | 5 +---- server/meeting_test.go | 5 ++++- server/utils_test.go | 42 +++++++++++++++++++++++++++++++++++++ webapp/src/actions/index.js | 9 ++++---- webapp/src/index.js | 4 ++-- 8 files changed, 78 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 6f3094d..2afe3d3 100644 --- a/go.mod +++ b/go.mod @@ -6,4 +6,5 @@ require ( github.com/mattermost/mattermost-server/v5 v5.3.2-0.20200723144633-ed34468996e6 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.6.1 + github.com/undefinedlabs/go-mpatch v1.0.6 ) diff --git a/go.sum b/go.sum index d16723d..2cc5657 100644 --- a/go.sum +++ b/go.sum @@ -541,6 +541,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/undefinedlabs/go-mpatch v1.0.6 h1:h8q5ORH/GaOE1Se1DMhrOyljXZEhRcROO7agMqWXCOY= +github.com/undefinedlabs/go-mpatch v1.0.6/go.mod h1:TyJZDQ/5AgyN7FSLiBJ8RO9u2c6wbtRvK827b6AVqY4= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w= diff --git a/server/command.go b/server/command.go index 043f76c..6c322e5 100644 --- a/server/command.go +++ b/server/command.go @@ -151,8 +151,8 @@ func (p *Plugin) executeCommandQueue(args *model.CommandArgs) *model.CommandResp message = strings.Join(split[3:], " ") } - hashtag, error := p.GenerateHashtag(args.ChannelId, nextWeek, weekday, false, time.Now().Weekday()) - if error != nil { + hashtag, err := p.GenerateHashtag(args.ChannelId, nextWeek, weekday, false, time.Now().Weekday()) + if err != nil { return responsef("Error calculating hashtags. Check the meeting settings for this channel.") } @@ -193,26 +193,31 @@ func (p *Plugin) executeCommandReQueue(args *model.CommandArgs) *model.CommandRe meeting, err := p.GetMeeting(args.ChannelId) if err != nil { - return responsef("Can't find the meeting") + return responsef("There was no meeting found for this channel.") } oldPostID := split[2] - postToBeReQueued, _ := p.API.GetPost(oldPostID) + postToBeReQueued, er := p.API.GetPost(oldPostID) + if er != nil { + return responsef("Error fetching post.") + } var ( prefix string hashtagDateFormat string ) - if matchGroups := meetingDateFormatRegex.FindStringSubmatch(meeting.HashtagFormat); len(matchGroups) == 4 { - prefix = matchGroups[1] - hashtagDateFormat = strings.TrimSpace(matchGroups[2]) + matchGroups := meetingDateFormatRegex.FindStringSubmatch(meeting.HashtagFormat) + if len(matchGroups) != 3 { + responsef("Error parsing hashtag format.") } + prefix = matchGroups[1] + hashtagDateFormat = strings.TrimSpace(matchGroups[2]) var ( messageRegexFormat = regexp.MustCompile(fmt.Sprintf(`(?m)^#### #%s(?P.*) [0-9]+\) (?P.*)?$`, prefix)) ) if matchGroups := messageRegexFormat.FindStringSubmatch(postToBeReQueued.Message); len(matchGroups) == 3 { - originalPostDate := strings.ReplaceAll(strings.TrimSpace(matchGroups[1]), "_", " ") // reverse what we do to make it a valid hashtag + originalPostDate := p.replaceUnderscoreWithSpace(strings.TrimSpace(matchGroups[1])) // reverse what we do to make it a valid hashtag originalPostMessage := strings.TrimSpace(matchGroups[2]) today := time.Now() @@ -224,11 +229,12 @@ func (p *Plugin) executeCommandReQueue(args *model.CommandArgs) *model.CommandRe } if today.Year() <= formattedDate.Year() && today.YearDay() < formattedDate.YearDay() { - return responsef("Re-queing future items are not supported.") + return responsef("Re-queuing future items is not supported.") } hashtag, err := p.GenerateHashtag(args.ChannelId, false, -1, true, formattedDate.Weekday()) if err != nil { + p.API.LogWarn("Error calculating hashtags. Check the meeting settings for this channel.", "error", err.Error()) return responsef("Error calculating hashtags. Check the meeting settings for this channel.") } @@ -245,11 +251,16 @@ func (p *Plugin) executeCommandReQueue(args *model.CommandArgs) *model.CommandRe Message: fmt.Sprintf("#### %v %v) %v", hashtag, numQueueItems, originalPostMessage), }) if appErr != nil { + p.API.LogWarn("Error creating post: %s", "error", appErr.Message) return responsef("Error creating post: %s", appErr.Message) } return responsef(fmt.Sprintf("Item has been Re-queued to %v", hashtag)) } - return responsef("Make sure, message is in required format!") + return responsef("Make sure, message is in required format.") +} + +func (p *Plugin) replaceUnderscoreWithSpace(hashtag string) string { + return strings.ReplaceAll(hashtag, "_", " ") } func (p *Plugin) executeCommandHelp(args *model.CommandArgs) *model.CommandResponse { diff --git a/server/meeting.go b/server/meeting.go index a3cca66..dc315c4 100644 --- a/server/meeting.go +++ b/server/meeting.go @@ -75,15 +75,12 @@ func (p *Plugin) GenerateHashtag(channelID string, nextWeek bool, weekday int, r return "", err } } else { - // user didn't provide any specific date, Get date for the list of days of the week + // user didn't specify any specific date/day in command, Get date for the list of days of the week if !requeue { if meetingDate, err = nextWeekdayDateInWeek(meeting.Schedule, nextWeek); err != nil { return "", err } } else { - if len(meeting.Schedule) == 1 && meeting.Schedule[0] == assignedDay { // if this day is the only day selected in settings - nextWeek = true - } if meetingDate, err = nextWeekdayDateInWeekSkippingDay(meeting.Schedule, nextWeek, assignedDay); err != nil { return "", err } diff --git a/server/meeting_test.go b/server/meeting_test.go index 6510e57..6f291e2 100644 --- a/server/meeting_test.go +++ b/server/meeting_test.go @@ -138,7 +138,10 @@ func TestPlugin_GenerateHashtag(t *testing.T) { jsonMeeting, err := json.Marshal(tt.args.meeting) tAssert.Nil(err) api.On("KVGet", tt.args.meeting.ChannelID).Return(jsonMeeting, nil) - got, err := mPlugin.GenerateHashtag(tt.args.meeting.ChannelID, tt.args.nextWeek, -1, false, 1) + weekday := -1 + requeue := false + assignedDay := time.Weekday(1) + got, err := mPlugin.GenerateHashtag(tt.args.meeting.ChannelID, tt.args.nextWeek, weekday, requeue, assignedDay) if (err != nil) != tt.wantErr { t.Errorf("GenerateHashtag() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/server/utils_test.go b/server/utils_test.go index 553dd6c..98f2f90 100644 --- a/server/utils_test.go +++ b/server/utils_test.go @@ -1,8 +1,11 @@ package main import ( + "reflect" "testing" "time" + + "github.com/undefinedlabs/go-mpatch" ) func Test_parseSchedule(t *testing.T) { @@ -41,3 +44,42 @@ func Test_parseSchedule(t *testing.T) { }) } } + +func Test_nextWeekdayDateInWeekSkippingDay(t *testing.T) { + var patch, err = mpatch.PatchMethod(time.Now, func() time.Time { + return time.Date(2021, 11, 15, 00, 00, 00, 0, time.UTC) + }) + if patch == nil || err != nil { + t.Errorf("error creating patch") + } + type args struct { + meetingDays []time.Weekday + nextWeek bool + dayToSkip time.Weekday + } + tests := []struct { + name string + args args + want time.Time + wantErr bool + }{ + + {name: "test skip tuesday in week, today", args: args{[]time.Weekday{1, 2, 3, 4, 5, 6, 7}, false, time.Weekday(2)}, want: time.Now().AddDate(0, 0, 0), wantErr: false}, + {name: "test skip tuesday in few days", args: args{[]time.Weekday{2, 3, 4, 5, 6, 7}, false, time.Weekday(2)}, want: time.Now().AddDate(0, 0, 2), wantErr: false}, + {name: "test skip monday with nextWeek true", args: args{[]time.Weekday{1, 2, 3, 4}, true, time.Weekday(1)}, want: time.Now().AddDate(0, 0, 8), wantErr: false}, + {name: "test only meeting day is skipped", args: args{[]time.Weekday{3}, false, time.Weekday(3)}, want: time.Now().AddDate(0, 0, 2), wantErr: false}, + {name: "test only meeting day is skipped with nextWeek true", args: args{[]time.Weekday{3}, true, time.Weekday(3)}, want: time.Now().AddDate(0, 0, 9), wantErr: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := nextWeekdayDateInWeekSkippingDay(tt.args.meetingDays, tt.args.nextWeek, tt.args.dayToSkip) + if (err != nil) != tt.wantErr { + t.Errorf("nextWeekdayDateInWeekSkippingDay() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, &tt.want) { + t.Errorf("nextWeekdayDateInWeekSkippingDay() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index 3c5ca61..8454750 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -83,17 +83,18 @@ export function performSearch(terms) { }; } -export function requeueItem(itemId) { +export function requeueItem(postId) { return async (dispatch, getState) => { - const command = `/agenda requeue ${itemId}`; + const command = `/agenda requeue ${postId}`; await clientExecuteCommand(dispatch, getState, command); return {data: true}; }; } export async function clientExecuteCommand(dispatch, getState, command) { - const currentChannel = getCurrentChannel(getState()); - const currentTeamId = getCurrentTeamId(getState()); + const state = getState(); + const currentChannel = getCurrentChannel(state); + const currentTeamId = getCurrentTeamId(state); const args = { channel_id: currentChannel?.id, team_id: currentTeamId, diff --git a/webapp/src/index.js b/webapp/src/index.js index cee038b..3020ca9 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -20,8 +20,8 @@ export default class Plugin { store.dispatch(openMeetingSettingsModal(channelId)); }); - registry.registerPostDropdownMenuAction('Re-queue', (itemId) => { - store.dispatch(requeueItem(itemId)); + registry.registerPostDropdownMenuAction('Re-queue', (postId) => { + store.dispatch(requeueItem(postId)); }); } } From 907377f90c911d1add6acc0691a59931f3b8f4bb Mon Sep 17 00:00:00 2001 From: sibasankarnayak <86650698+sibasankarnayak@users.noreply.github.com> Date: Wed, 27 Oct 2021 15:05:01 +0530 Subject: [PATCH 3/5] revert - [issue 92] Cross-plugin task: Enable the CircleCI "test" job in each plugin repo that has a webapp plugin (#93) Co-authored-by: maisnamrajusingh --- .circleci/config.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1695ab0..9e22b71 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,14 +23,22 @@ workflows: filters: tags: only: /^v.*/ + - plugin-ci/test: + filters: + tags: + only: /^v.*/ - plugin-ci/coverage: filters: tags: only: /^v.*/ + requires: + - plugin-ci/test - plugin-ci/build: filters: tags: only: /^v.*/ + requires: + - plugin-ci/test - plugin-ci/deploy-ci: filters: branches: @@ -40,6 +48,7 @@ workflows: - plugin-ci/lint - plugin-ci/coverage - plugin-ci/build + - plugin-ci/test - plugin-ci/deploy-release-github: filters: tags: @@ -51,3 +60,4 @@ workflows: - plugin-ci/lint - plugin-ci/coverage - plugin-ci/build + - plugin-ci/test From 9457541a516a46efab8b9247dd4822b8688ec3ef Mon Sep 17 00:00:00 2001 From: Sanjay Date: Fri, 11 Feb 2022 18:37:29 +0530 Subject: [PATCH 4/5] - feedback #89 --- server/command.go | 16 ++++++++++------ server/meeting.go | 6 +++++- webapp/src/actions/index.js | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/command.go b/server/command.go index 499b22b..f975afb 100644 --- a/server/command.go +++ b/server/command.go @@ -209,8 +209,9 @@ func (p *Plugin) executeCommandReQueue(args *model.CommandArgs) *model.CommandRe } oldPostID := split[2] - postToBeReQueued, er := p.API.GetPost(oldPostID) - if er != nil { + postToBeReQueued, appErr := p.API.GetPost(oldPostID) + if appErr != nil { + p.API.LogWarn("Error fetching post: %s", "error", appErr.Message) return responsef("Error fetching post.") } var ( @@ -225,8 +226,11 @@ func (p *Plugin) executeCommandReQueue(args *model.CommandArgs) *model.CommandRe hashtagDateFormat = strings.TrimSpace(matchGroups[2]) var ( - messageRegexFormat = regexp.MustCompile(fmt.Sprintf(`(?m)^#### #%s(?P.*) [0-9]+\) (?P.*)?$`, prefix)) + messageRegexFormat, er = regexp.Compile(fmt.Sprintf(`(?m)^#### #%s(?P.*) [0-9]+\) (?P.*)?$`, prefix)) ) + if er != nil { + return responsef(er.Error()) + } if matchGroups := messageRegexFormat.FindStringSubmatch(postToBeReQueued.Message); len(matchGroups) == 3 { originalPostDate := p.replaceUnderscoreWithSpace(strings.TrimSpace(matchGroups[1])) // reverse what we do to make it a valid hashtag @@ -250,9 +254,9 @@ func (p *Plugin) executeCommandReQueue(args *model.CommandArgs) *model.CommandRe return responsef("Error calculating hashtags. Check the meeting settings for this channel.") } - itemErr, numQueueItems := calculateQueItemNumber(args, p, hashtag) - if itemErr != nil { - return itemErr + commandResponse, numQueueItems := calculateQueItemNumber(args, p, hashtag) + if commandResponse != nil { + return commandResponse } _, appErr := p.API.UpdatePost(&model.Post{ diff --git a/server/meeting.go b/server/meeting.go index f9af614..ccd6648 100644 --- a/server/meeting.go +++ b/server/meeting.go @@ -13,7 +13,7 @@ import ( ) var ( - meetingDateFormatRegex = regexp.MustCompile(`(?m)^(?P.*)?(?:{{\s*(?P.*)\s*}})(?P.*)?$`) + meetingDateFormatRegex, appErr = regexp.Compile(`(?m)^(?P.*)?(?:{{\s*(?P.*)\s*}})(?P.*)?$`) ) // Meeting represents a meeting agenda @@ -140,6 +140,10 @@ func (p *Plugin) GenerateHashtag(channelID string, nextWeek bool, weekday int, r var hashtag string + if appErr != nil { + return "", appErr + } + if matchGroups := meetingDateFormatRegex.FindStringSubmatch(meeting.HashtagFormat); len(matchGroups) == 4 { var ( prefix string diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index 8454750..89f3f74 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -85,7 +85,7 @@ export function performSearch(terms) { export function requeueItem(postId) { return async (dispatch, getState) => { - const command = `/agenda requeue ${postId}`; + const command = `/agenda requeue post ${postId}`; await clientExecuteCommand(dispatch, getState, command); return {data: true}; }; From f4c0c33759cdcead12b29927f247fbadc5cfc863 Mon Sep 17 00:00:00 2001 From: Sanjay Date: Wed, 16 Feb 2022 11:57:26 +0530 Subject: [PATCH 5/5] - update regex Compile => linting fix --- server/meeting.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/meeting.go b/server/meeting.go index ccd6648..f9af614 100644 --- a/server/meeting.go +++ b/server/meeting.go @@ -13,7 +13,7 @@ import ( ) var ( - meetingDateFormatRegex, appErr = regexp.Compile(`(?m)^(?P.*)?(?:{{\s*(?P.*)\s*}})(?P.*)?$`) + meetingDateFormatRegex = regexp.MustCompile(`(?m)^(?P.*)?(?:{{\s*(?P.*)\s*}})(?P.*)?$`) ) // Meeting represents a meeting agenda @@ -140,10 +140,6 @@ func (p *Plugin) GenerateHashtag(channelID string, nextWeek bool, weekday int, r var hashtag string - if appErr != nil { - return "", appErr - } - if matchGroups := meetingDateFormatRegex.FindStringSubmatch(meeting.HashtagFormat); len(matchGroups) == 4 { var ( prefix string