From 1b0340a9f626269529ec453eec0ee258ecfaae2c Mon Sep 17 00:00:00 2001 From: raghavaggarwal2308 Date: Fri, 18 Aug 2023 12:53:10 +0530 Subject: [PATCH 1/6] [MI-3405] Get proper data in sidebar buttons: 1. Get assigned PRs instead of the user's PRs. 2. Updated the name of sidebar buttons. 3. Updated API path. 4. Updated the name of API functions. 5. Updated the name of unreads to todos in the code. --- server/api.go | 29 +++++------ server/gitlab/api.go | 10 ++-- server/gitlab/gitlab.go | 6 +-- server/gitlab/mocks/mock_gitlab.go | 52 +++++++++---------- server/mocks/mock_gitlab.go | 52 +++++++++---------- server/plugin.go | 18 +++---- webapp/src/action_types/index.js | 2 +- webapp/src/actions/index.js | 6 +-- webapp/src/client/client.js | 8 +-- .../src/components/sidebar_buttons/index.js | 6 +-- .../sidebar_buttons/sidebar_buttons.jsx | 22 ++++---- webapp/src/components/sidebar_right/index.tsx | 16 +++--- webapp/src/constants/index.js | 2 +- webapp/src/reducers/index.js | 6 +-- webapp/src/selectors/index.js | 2 +- webapp/src/websocket/index.js | 6 +-- 16 files changed, 121 insertions(+), 122 deletions(-) diff --git a/server/api.go b/server/api.go index 1a342512f..af4258e66 100644 --- a/server/api.go +++ b/server/api.go @@ -56,10 +56,10 @@ func (p *Plugin) initializeAPI() { apiRouter.HandleFunc("/user", p.checkAuth(p.attachContext(p.getGitlabUser), ResponseTypeJSON)).Methods(http.MethodPost) apiRouter.HandleFunc("/todo", p.checkAuth(p.attachUserContext(p.postToDo), ResponseTypeJSON)).Methods(http.MethodPost) apiRouter.HandleFunc("/reviews", p.checkAuth(p.attachUserContext(p.getReviews), ResponseTypePlain)).Methods(http.MethodGet) - apiRouter.HandleFunc("/yourprs", p.checkAuth(p.attachUserContext(p.getYourPrs), ResponseTypePlain)).Methods(http.MethodGet) + apiRouter.HandleFunc("/yourassignedprs", p.checkAuth(p.attachUserContext(p.getYourAssignedPrs), ResponseTypePlain)).Methods(http.MethodGet) apiRouter.HandleFunc("/prdetails", p.checkAuth(p.attachUserContext(p.getPrDetails), ResponseTypePlain)).Methods(http.MethodPost) - apiRouter.HandleFunc("/yourassignments", p.checkAuth(p.attachUserContext(p.getYourAssignments), ResponseTypePlain)).Methods(http.MethodGet) - apiRouter.HandleFunc("/unreads", p.checkAuth(p.attachUserContext(p.getUnreads), ResponseTypePlain)).Methods(http.MethodGet) + apiRouter.HandleFunc("/yourassignedissues", p.checkAuth(p.attachUserContext(p.getYourAssignedIssues), ResponseTypePlain)).Methods(http.MethodGet) + apiRouter.HandleFunc("/todolist", p.checkAuth(p.attachUserContext(p.getToDoList), ResponseTypePlain)).Methods(http.MethodGet) apiRouter.HandleFunc("/settings", p.checkAuth(p.attachUserContext(p.updateSettings), ResponseTypePlain)).Methods(http.MethodPost) apiRouter.HandleFunc("/channel/{channel_id:[A-Za-z0-9]+}/subscriptions", p.checkAuth(p.attachUserContext(p.getChannelSubscriptions), ResponseTypeJSON)).Methods(http.MethodGet) @@ -530,10 +530,10 @@ func (p *Plugin) getConnected(c *Context, w http.ResponseWriter, r *http.Request p.writeAPIResponse(w, resp) } -func (p *Plugin) getUnreads(c *UserContext, w http.ResponseWriter, r *http.Request) { +func (p *Plugin) getToDoList(c *UserContext, w http.ResponseWriter, r *http.Request) { var result []*gitlabLib.Todo err := p.useGitlabClient(c.GitlabInfo, func(info *gitlab.UserInfo, token *oauth2.Token) error { - resp, err := p.GitlabClient.GetUnreads(c.Ctx, info, token) + resp, err := p.GitlabClient.GetToDoList(c.Ctx, info, token) if err != nil { return err } @@ -542,8 +542,8 @@ func (p *Plugin) getUnreads(c *UserContext, w http.ResponseWriter, r *http.Reque }) if err != nil { - c.Log.WithError(err).Warnf("Unable to list unreads in GitLab API") - p.writeAPIError(w, &APIErrorResponse{ID: "", Message: "Unable to list unreads in GitLab API.", StatusCode: http.StatusInternalServerError}) + c.Log.WithError(err).Warnf("Unable to list todos in GitLab API") + p.writeAPIError(w, &APIErrorResponse{ID: "", Message: "Unable to list todos in GitLab API.", StatusCode: http.StatusInternalServerError}) return } @@ -570,24 +570,23 @@ func (p *Plugin) getReviews(c *UserContext, w http.ResponseWriter, r *http.Reque p.writeAPIResponse(w, result) } -func (p *Plugin) getYourPrs(c *UserContext, w http.ResponseWriter, r *http.Request) { - var result []*gitlab.MergeRequest +func (p *Plugin) getYourAssignedPrs(c *UserContext, w http.ResponseWriter, r *http.Request) { + var assignedPRs []*gitlab.MergeRequest err := p.useGitlabClient(c.GitlabInfo, func(info *gitlab.UserInfo, token *oauth2.Token) error { - resp, err := p.GitlabClient.GetYourPrs(c.Ctx, info, token) + resp, err := p.GitlabClient.GetYourAssignedPrs(c.Ctx, info, token) if err != nil { return err } - result = resp + assignedPRs = resp return nil }) - if err != nil { c.Log.WithError(err).Warnf("Can't list merge-request where author in GitLab API") p.writeAPIError(w, &APIErrorResponse{ID: "", Message: "Unable to list merge-request in GitLab API.", StatusCode: http.StatusInternalServerError}) return } - p.writeAPIResponse(w, result) + p.writeAPIResponse(w, assignedPRs) } func (p *Plugin) getPrDetails(c *UserContext, w http.ResponseWriter, r *http.Request) { @@ -615,10 +614,10 @@ func (p *Plugin) getPrDetails(c *UserContext, w http.ResponseWriter, r *http.Req p.writeAPIResponse(w, result) } -func (p *Plugin) getYourAssignments(c *UserContext, w http.ResponseWriter, r *http.Request) { +func (p *Plugin) getYourAssignedIssues(c *UserContext, w http.ResponseWriter, r *http.Request) { var result []*gitlab.Issue err := p.useGitlabClient(c.GitlabInfo, func(info *gitlab.UserInfo, token *oauth2.Token) error { - resp, err := p.GitlabClient.GetYourAssignments(c.Ctx, info, token) + resp, err := p.GitlabClient.GetYourAssignedIssues(c.Ctx, info, token) if err != nil { return err } diff --git a/server/gitlab/api.go b/server/gitlab/api.go index e0fe1b27c..f481bf37c 100644 --- a/server/gitlab/api.go +++ b/server/gitlab/api.go @@ -353,7 +353,7 @@ func (g *gitlab) GetReviews(ctx context.Context, user *UserInfo, token *oauth2.T return mergeRequests, err } -func (g *gitlab) GetYourPrs(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*MergeRequest, error) { +func (g *gitlab) GetYourAssignedPrs(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*MergeRequest, error) { client, err := g.GitlabConnect(*token) if err != nil { return nil, err @@ -366,7 +366,7 @@ func (g *gitlab) GetYourPrs(ctx context.Context, user *UserInfo, token *oauth2.T if g.gitlabGroup == "" { opt := &internGitlab.ListMergeRequestsOptions{ - AuthorID: &user.GitlabUserID, + AssigneeID: internGitlab.AssigneeID(user.GitlabUserID), State: &opened, Scope: &scope, ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage}, @@ -386,7 +386,7 @@ func (g *gitlab) GetYourPrs(ctx context.Context, user *UserInfo, token *oauth2.T } } else { opt := &internGitlab.ListGroupMergeRequestsOptions{ - AuthorID: &user.GitlabUserID, + AssigneeID: internGitlab.AssigneeID(user.GitlabUserID), State: &opened, Scope: &scope, ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage}, @@ -518,7 +518,7 @@ func (g *gitlab) fetchYourPrDetails(c context.Context, log logger.Logger, client return nil } -func (g *gitlab) GetYourAssignments(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*Issue, error) { +func (g *gitlab) GetYourAssignedIssues(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*Issue, error) { client, err := g.GitlabConnect(*token) if err != nil { return nil, err @@ -588,7 +588,7 @@ func (g *gitlab) GetYourAssignments(ctx context.Context, user *UserInfo, token * return result, nil } -func (g *gitlab) GetUnreads(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*internGitlab.Todo, error) { +func (g *gitlab) GetToDoList(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*internGitlab.Todo, error) { client, err := g.GitlabConnect(*token) if err != nil { return nil, err diff --git a/server/gitlab/gitlab.go b/server/gitlab/gitlab.go index 8e5907518..7127a4b32 100644 --- a/server/gitlab/gitlab.go +++ b/server/gitlab/gitlab.go @@ -29,9 +29,9 @@ type Gitlab interface { GetProject(ctx context.Context, user *UserInfo, token *oauth2.Token, owner, repo string) (*internGitlab.Project, error) GetYourPrDetails(ctx context.Context, log logger.Logger, user *UserInfo, token *oauth2.Token, prList []*PRDetails) ([]*PRDetails, error) GetReviews(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*MergeRequest, error) - GetYourPrs(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*MergeRequest, error) - GetYourAssignments(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*Issue, error) - GetUnreads(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*internGitlab.Todo, error) + GetYourAssignedPrs(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*MergeRequest, error) + GetYourAssignedIssues(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*Issue, error) + GetToDoList(ctx context.Context, user *UserInfo, token *oauth2.Token) ([]*internGitlab.Todo, error) GetProjectHooks(ctx context.Context, user *UserInfo, token *oauth2.Token, owner string, repo string) ([]*WebhookInfo, error) GetGroupHooks(ctx context.Context, user *UserInfo, token *oauth2.Token, owner string) ([]*WebhookInfo, error) NewProjectHook(ctx context.Context, user *UserInfo, token *oauth2.Token, projectID interface{}, projectHookOptions *AddWebhookOptions) (*WebhookInfo, error) diff --git a/server/gitlab/mocks/mock_gitlab.go b/server/gitlab/mocks/mock_gitlab.go index c7deb75b4..83266505a 100644 --- a/server/gitlab/mocks/mock_gitlab.go +++ b/server/gitlab/mocks/mock_gitlab.go @@ -113,19 +113,19 @@ func (mr *MockGitlabMockRecorder) GetReviews(arg0, arg1, arg2 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReviews", reflect.TypeOf((*MockGitlab)(nil).GetReviews), arg0, arg1, arg2) } -// GetUnreads mocks base method. -func (m *MockGitlab) GetUnreads(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab0.Todo, error) { +// GetToDoList mocks base method. +func (m *MockGitlab) GetToDoList(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab0.Todo, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetUnreads", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetToDoList", arg0, arg1, arg2) ret0, _ := ret[0].([]*gitlab0.Todo) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetUnreads indicates an expected call of GetUnreads. -func (mr *MockGitlabMockRecorder) GetUnreads(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetToDoList indicates an expected call of GetToDoList. +func (mr *MockGitlabMockRecorder) GetToDoList(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUnreads", reflect.TypeOf((*MockGitlab)(nil).GetUnreads), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetToDoList", reflect.TypeOf((*MockGitlab)(nil).GetToDoList), arg0, arg1, arg2) } // GetUserDetails mocks base method. @@ -143,49 +143,49 @@ func (mr *MockGitlabMockRecorder) GetUserDetails(arg0, arg1, arg2 interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserDetails", reflect.TypeOf((*MockGitlab)(nil).GetUserDetails), arg0, arg1, arg2) } -// GetYourAssignments mocks base method. -func (m *MockGitlab) GetYourAssignments(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.Issue, error) { +// GetYourAssignedIssues mocks base method. +func (m *MockGitlab) GetYourAssignedIssues(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.Issue, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetYourAssignments", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetYourAssignedIssues", arg0, arg1, arg2) ret0, _ := ret[0].([]*gitlab.Issue) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetYourAssignments indicates an expected call of GetYourAssignments. -func (mr *MockGitlabMockRecorder) GetYourAssignments(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetYourAssignedIssues indicates an expected call of GetYourAssignedIssues. +func (mr *MockGitlabMockRecorder) GetYourAssignedIssues(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourAssignments", reflect.TypeOf((*MockGitlab)(nil).GetYourAssignments), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourAssignedIssues", reflect.TypeOf((*MockGitlab)(nil).GetYourAssignedIssues), arg0, arg1, arg2) } -// GetYourPrDetails mocks base method. -func (m *MockGitlab) GetYourPrDetails(arg0 context.Context, arg1 logger.Logger, arg2 *gitlab.UserInfo, arg3 *oauth2.Token, arg4 []*gitlab.PRDetails) ([]*gitlab.PRDetails, error) { +// GetYourAssignedPrs mocks base method. +func (m *MockGitlab) GetYourAssignedPrs(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.MergeRequest, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetYourPrDetails", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].([]*gitlab.PRDetails) + ret := m.ctrl.Call(m, "GetYourAssignedPrs", arg0, arg1, arg2) + ret0, _ := ret[0].([]*gitlab.MergeRequest) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetYourPrDetails indicates an expected call of GetYourPrDetails. -func (mr *MockGitlabMockRecorder) GetYourPrDetails(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +// GetYourAssignedPrs indicates an expected call of GetYourAssignedPrs. +func (mr *MockGitlabMockRecorder) GetYourAssignedPrs(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourPrDetails", reflect.TypeOf((*MockGitlab)(nil).GetYourPrDetails), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourAssignedPrs", reflect.TypeOf((*MockGitlab)(nil).GetYourAssignedPrs), arg0, arg1, arg2) } -// GetYourPrs mocks base method. -func (m *MockGitlab) GetYourPrs(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.MergeRequest, error) { +// GetYourPrDetails mocks base method. +func (m *MockGitlab) GetYourPrDetails(arg0 context.Context, arg1 logger.Logger, arg2 *gitlab.UserInfo, arg3 *oauth2.Token, arg4 []*gitlab.PRDetails) ([]*gitlab.PRDetails, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetYourPrs", arg0, arg1, arg2) - ret0, _ := ret[0].([]*gitlab.MergeRequest) + ret := m.ctrl.Call(m, "GetYourPrDetails", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].([]*gitlab.PRDetails) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetYourPrs indicates an expected call of GetYourPrs. -func (mr *MockGitlabMockRecorder) GetYourPrs(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetYourPrDetails indicates an expected call of GetYourPrDetails. +func (mr *MockGitlabMockRecorder) GetYourPrDetails(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourPrs", reflect.TypeOf((*MockGitlab)(nil).GetYourPrs), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourPrDetails", reflect.TypeOf((*MockGitlab)(nil).GetYourPrDetails), arg0, arg1, arg2, arg3, arg4) } // GitlabConnect mocks base method. diff --git a/server/mocks/mock_gitlab.go b/server/mocks/mock_gitlab.go index c7deb75b4..83266505a 100644 --- a/server/mocks/mock_gitlab.go +++ b/server/mocks/mock_gitlab.go @@ -113,19 +113,19 @@ func (mr *MockGitlabMockRecorder) GetReviews(arg0, arg1, arg2 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetReviews", reflect.TypeOf((*MockGitlab)(nil).GetReviews), arg0, arg1, arg2) } -// GetUnreads mocks base method. -func (m *MockGitlab) GetUnreads(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab0.Todo, error) { +// GetToDoList mocks base method. +func (m *MockGitlab) GetToDoList(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab0.Todo, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetUnreads", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetToDoList", arg0, arg1, arg2) ret0, _ := ret[0].([]*gitlab0.Todo) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetUnreads indicates an expected call of GetUnreads. -func (mr *MockGitlabMockRecorder) GetUnreads(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetToDoList indicates an expected call of GetToDoList. +func (mr *MockGitlabMockRecorder) GetToDoList(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUnreads", reflect.TypeOf((*MockGitlab)(nil).GetUnreads), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetToDoList", reflect.TypeOf((*MockGitlab)(nil).GetToDoList), arg0, arg1, arg2) } // GetUserDetails mocks base method. @@ -143,49 +143,49 @@ func (mr *MockGitlabMockRecorder) GetUserDetails(arg0, arg1, arg2 interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserDetails", reflect.TypeOf((*MockGitlab)(nil).GetUserDetails), arg0, arg1, arg2) } -// GetYourAssignments mocks base method. -func (m *MockGitlab) GetYourAssignments(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.Issue, error) { +// GetYourAssignedIssues mocks base method. +func (m *MockGitlab) GetYourAssignedIssues(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.Issue, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetYourAssignments", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "GetYourAssignedIssues", arg0, arg1, arg2) ret0, _ := ret[0].([]*gitlab.Issue) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetYourAssignments indicates an expected call of GetYourAssignments. -func (mr *MockGitlabMockRecorder) GetYourAssignments(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetYourAssignedIssues indicates an expected call of GetYourAssignedIssues. +func (mr *MockGitlabMockRecorder) GetYourAssignedIssues(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourAssignments", reflect.TypeOf((*MockGitlab)(nil).GetYourAssignments), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourAssignedIssues", reflect.TypeOf((*MockGitlab)(nil).GetYourAssignedIssues), arg0, arg1, arg2) } -// GetYourPrDetails mocks base method. -func (m *MockGitlab) GetYourPrDetails(arg0 context.Context, arg1 logger.Logger, arg2 *gitlab.UserInfo, arg3 *oauth2.Token, arg4 []*gitlab.PRDetails) ([]*gitlab.PRDetails, error) { +// GetYourAssignedPrs mocks base method. +func (m *MockGitlab) GetYourAssignedPrs(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.MergeRequest, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetYourPrDetails", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].([]*gitlab.PRDetails) + ret := m.ctrl.Call(m, "GetYourAssignedPrs", arg0, arg1, arg2) + ret0, _ := ret[0].([]*gitlab.MergeRequest) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetYourPrDetails indicates an expected call of GetYourPrDetails. -func (mr *MockGitlabMockRecorder) GetYourPrDetails(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +// GetYourAssignedPrs indicates an expected call of GetYourAssignedPrs. +func (mr *MockGitlabMockRecorder) GetYourAssignedPrs(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourPrDetails", reflect.TypeOf((*MockGitlab)(nil).GetYourPrDetails), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourAssignedPrs", reflect.TypeOf((*MockGitlab)(nil).GetYourAssignedPrs), arg0, arg1, arg2) } -// GetYourPrs mocks base method. -func (m *MockGitlab) GetYourPrs(arg0 context.Context, arg1 *gitlab.UserInfo, arg2 *oauth2.Token) ([]*gitlab.MergeRequest, error) { +// GetYourPrDetails mocks base method. +func (m *MockGitlab) GetYourPrDetails(arg0 context.Context, arg1 logger.Logger, arg2 *gitlab.UserInfo, arg3 *oauth2.Token, arg4 []*gitlab.PRDetails) ([]*gitlab.PRDetails, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetYourPrs", arg0, arg1, arg2) - ret0, _ := ret[0].([]*gitlab.MergeRequest) + ret := m.ctrl.Call(m, "GetYourPrDetails", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].([]*gitlab.PRDetails) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetYourPrs indicates an expected call of GetYourPrs. -func (mr *MockGitlabMockRecorder) GetYourPrs(arg0, arg1, arg2 interface{}) *gomock.Call { +// GetYourPrDetails indicates an expected call of GetYourPrDetails. +func (mr *MockGitlabMockRecorder) GetYourPrDetails(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourPrs", reflect.TypeOf((*MockGitlab)(nil).GetYourPrs), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetYourPrDetails", reflect.TypeOf((*MockGitlab)(nil).GetYourPrDetails), arg0, arg1, arg2, arg3, arg4) } // GitlabConnect mocks base method. diff --git a/server/plugin.go b/server/plugin.go index 3642cf8bd..62428a189 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -575,13 +575,13 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri notificationText := "" g.Go(func() error { - var unreads []*gitlabLib.Todo + var todos []*gitlabLib.Todo err := p.useGitlabClient(user, func(info *gitlab.UserInfo, token *oauth2.Token) error { - resp, err := p.GitlabClient.GetUnreads(ctx, info, token) + resp, err := p.GitlabClient.GetToDoList(ctx, info, token) if err != nil { return err } - unreads = resp + todos = resp return nil }) if err != nil { @@ -591,7 +591,7 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri notificationCount := 0 notificationContent := "" - for _, n := range unreads { + for _, n := range todos { if n == nil { continue } @@ -649,7 +649,7 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri g.Go(func() error { var yourAssignments []*gitlab.Issue err := p.useGitlabClient(user, func(info *gitlab.UserInfo, token *oauth2.Token) error { - resp, err := p.GitlabClient.GetYourAssignments(ctx, info, token) + resp, err := p.GitlabClient.GetYourAssignedIssues(ctx, info, token) if err != nil { return err } @@ -679,7 +679,7 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri g.Go(func() error { var mergeRequests []*gitlab.MergeRequest err := p.useGitlabClient(user, func(info *gitlab.UserInfo, token *oauth2.Token) error { - resp, err := p.GitlabClient.GetYourPrs(ctx, info, token) + resp, err := p.GitlabClient.GetYourAssignedPrs(ctx, info, token) if err != nil { return err } @@ -709,16 +709,16 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri return false, "", err } - text := "##### Unread Messages\n" + text := "##### To-Do list\n" text += notificationText text += "##### Review Requests\n" text += reviewText - text += "##### Assignments\n" + text += "##### Issues\n" text += assignmentText - text += "##### Your Open Merge Requests\n" + text += "##### Merge Requests Assigned\n" text += mergeRequestText return hasTodo, text, nil diff --git a/webapp/src/action_types/index.js b/webapp/src/action_types/index.js index f67cbcf23..cdd18449f 100644 --- a/webapp/src/action_types/index.js +++ b/webapp/src/action_types/index.js @@ -7,7 +7,7 @@ export default { RECEIVED_REVIEW_DETAILS: `${id}_received_review_details`, RECEIVED_YOUR_ASSIGNMENTS: `${id}_received_your_assignments`, RECEIVED_MENTIONS: `${id}_received_mentions`, - RECEIVED_UNREADS: `${id}_received_unreads`, + RECEIVED_TODOS: `${id}_received_todos`, RECEIVED_CONNECTED: `${id}_received_connected`, RECEIVED_GITLAB_USER: `${id}_received_gitlab_user`, RECEIVED_SHOW_RHS_ACTION: `${id}_received_rhs_action`, diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index 779e27df9..e0b81c98d 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -188,11 +188,11 @@ export function getMentions() { }; } -export function getUnreads() { +export function getTodos() { return async (dispatch, getState) => { let data; try { - data = await Client.getUnreads(); + data = await Client.getTodos(); } catch (error) { return {error}; } @@ -206,7 +206,7 @@ export function getUnreads() { } dispatch({ - type: ActionTypes.RECEIVED_UNREADS, + type: ActionTypes.RECEIVED_TODOS, data, }); diff --git a/webapp/src/client/client.js b/webapp/src/client/client.js index c8cd1696e..2286d9470 100644 --- a/webapp/src/client/client.js +++ b/webapp/src/client/client.js @@ -15,7 +15,7 @@ export default class Client { }; getYourPrs = async () => { - return this.doGet(`${this.url}/yourprs`); + return this.doGet(`${this.url}/yourassignedprs`); }; getPrsDetails = async (prList) => { @@ -23,15 +23,15 @@ export default class Client { } getYourAssignments = async () => { - return this.doGet(`${this.url}/yourassignments`); + return this.doGet(`${this.url}/yourassignedissues`); }; getMentions = async () => { return this.doGet(`${this.url}/mentions`); }; - getUnreads = async () => { - return this.doGet(`${this.url}/unreads`); + getTodos = async () => { + return this.doGet(`${this.url}/todolist`); }; getGitlabUser = async (userID) => { diff --git a/webapp/src/components/sidebar_buttons/index.js b/webapp/src/components/sidebar_buttons/index.js index ea40180c9..70ba3da5e 100644 --- a/webapp/src/components/sidebar_buttons/index.js +++ b/webapp/src/components/sidebar_buttons/index.js @@ -3,7 +3,7 @@ import {bindActionCreators} from 'redux'; import { getReviews, - getUnreads, + getTodos, getYourPrs, getYourAssignments, updateRHSState, @@ -23,7 +23,7 @@ function mapStateToProps(state) { reviews: state[`plugins-${id}`].reviews, yourPrs: state[`plugins-${id}`].yourPrs, yourAssignments: state[`plugins-${id}`].yourAssignments, - unreads: state[`plugins-${id}`].unreads, + todos: state[`plugins-${id}`].todos, gitlabURL: state[`plugins-${id}`].gitlabURL, org: state[`plugins-${id}`].organization, pluginServerRoute: getPluginServerRoute(state), @@ -36,7 +36,7 @@ function mapDispatchToProps(dispatch) { actions: bindActionCreators( { getReviews, - getUnreads, + getTodos, getYourPrs, getYourAssignments, updateRHSState, diff --git a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx index c057b5225..0b394e923 100644 --- a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx +++ b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx @@ -14,7 +14,7 @@ export default class SidebarButtons extends React.PureComponent { clientId: PropTypes.string, gitlabURL: PropTypes.string, reviews: PropTypes.arrayOf(PropTypes.object), - unreads: PropTypes.arrayOf(PropTypes.object), + todos: PropTypes.arrayOf(PropTypes.object), yourPrs: PropTypes.arrayOf(PropTypes.object), yourAssignments: PropTypes.arrayOf(PropTypes.object), isTeamSidebar: PropTypes.bool, @@ -22,7 +22,7 @@ export default class SidebarButtons extends React.PureComponent { showRHSPlugin: PropTypes.func.isRequired, actions: PropTypes.shape({ getReviews: PropTypes.func.isRequired, - getUnreads: PropTypes.func.isRequired, + getTodos: PropTypes.func.isRequired, getYourPrs: PropTypes.func.isRequired, getYourAssignments: PropTypes.func.isRequired, updateRHSState: PropTypes.func.isRequired, @@ -61,7 +61,7 @@ export default class SidebarButtons extends React.PureComponent { this.setState({refreshing: true}); await Promise.all([ this.props.actions.getReviews(), - this.props.actions.getUnreads(), + this.props.actions.getTodos(), this.props.actions.getYourPrs(), this.props.actions.getYourAssignments(), ]); @@ -115,7 +115,7 @@ export default class SidebarButtons extends React.PureComponent { const baseURL = this.props.gitlabURL || 'https://gitlab.com'; const reviews = this.props.reviews || []; const yourPrs = this.props.yourPrs || []; - const unreads = this.props.unreads || []; + const todos = this.props.todos || []; const yourAssignments = this.props.yourAssignments || []; const refreshClass = this.state.refreshing ? ' fa-spin' : ''; @@ -133,7 +133,7 @@ export default class SidebarButtons extends React.PureComponent { {'Your open merge requests'}} + overlay={{'Merge requests assigned'}} > this.openRHS(RHSStates.PRS)} @@ -146,7 +146,7 @@ export default class SidebarButtons extends React.PureComponent { {'Merge requests that need review'}} + overlay={{'Merge requests needing review'}} > this.openRHS(RHSStates.REVIEWS)} @@ -159,7 +159,7 @@ export default class SidebarButtons extends React.PureComponent { {'Your assignments'}} + overlay={{'Issues'}} > this.openRHS(RHSStates.ASSIGNMENTS)} @@ -170,16 +170,16 @@ export default class SidebarButtons extends React.PureComponent { {'Unread messages'}} + overlay={{'To-Do list'}} > this.openRHS(RHSStates.UNREADS)} + onClick={() => this.openRHS(RHSStates.TODOS)} style={button} > - {' ' + unreads.length} + {' ' + todos.length} { if (store.getState()[`plugins-${id}`].connected) { getReviews()(store.dispatch, store.getState); - getUnreads()(store.dispatch, store.getState); + getTodos()(store.dispatch, store.getState); getYourPrs()(store.dispatch, store.getState); getYourAssignments()(store.dispatch, store.getState); } From 176839cfbc251a7aec2b70d29f4184345b426b58 Mon Sep 17 00:00:00 2001 From: raghavaggarwal2308 Date: Fri, 18 Aug 2023 13:25:36 +0530 Subject: [PATCH 2/6] [MI-3405] Updated name of variables and functions --- server/plugin.go | 10 +++---- webapp/src/action_types/index.js | 4 +-- webapp/src/actions/index.js | 12 ++++---- webapp/src/client/client.js | 4 +-- .../src/components/sidebar_buttons/index.js | 12 ++++---- .../sidebar_buttons/sidebar_buttons.jsx | 30 +++++++++---------- webapp/src/components/sidebar_right/index.tsx | 20 ++++++------- webapp/src/constants/index.js | 2 +- webapp/src/reducers/index.js | 12 ++++---- webapp/src/selectors/index.js | 4 +-- webapp/src/websocket/index.js | 12 ++++---- 11 files changed, 61 insertions(+), 61 deletions(-) diff --git a/server/plugin.go b/server/plugin.go index 62428a189..4f69f5304 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -647,25 +647,25 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri assignmentText := "" g.Go(func() error { - var yourAssignments []*gitlab.Issue + var yourAssignedIssues []*gitlab.Issue err := p.useGitlabClient(user, func(info *gitlab.UserInfo, token *oauth2.Token) error { resp, err := p.GitlabClient.GetYourAssignedIssues(ctx, info, token) if err != nil { return err } - yourAssignments = resp + yourAssignedIssues = resp return nil }) if err != nil { return err } - if len(yourAssignments) == 0 { + if len(yourAssignedIssues) == 0 { assignmentText += "You don't have any issues awaiting your dev.\n" } else { - assignmentText += fmt.Sprintf("You have %v issues awaiting dev:\n", len(yourAssignments)) + assignmentText += fmt.Sprintf("You have %v issues awaiting dev:\n", len(yourAssignedIssues)) - for _, pr := range yourAssignments { + for _, pr := range yourAssignedIssues { assignmentText += fmt.Sprintf("* [%v](%v)\n", pr.Title, pr.WebURL) } diff --git a/webapp/src/action_types/index.js b/webapp/src/action_types/index.js index cdd18449f..48ddad5bc 100644 --- a/webapp/src/action_types/index.js +++ b/webapp/src/action_types/index.js @@ -2,10 +2,10 @@ import {id} from '../manifest'; export default { RECEIVED_REVIEWS: `${id}_received_reviews`, - RECEIVED_YOUR_PRS: `${id}_received_your_prs`, + RECEIVED_YOUR_ASSIGNED_PRS: `${id}_received_your_assigned_prs`, RECEIVED_YOUR_PR_DETAILS: `${id}_received_your_pr_details`, RECEIVED_REVIEW_DETAILS: `${id}_received_review_details`, - RECEIVED_YOUR_ASSIGNMENTS: `${id}_received_your_assignments`, + RECEIVED_YOUR_ASSIGNED_ISSUES: `${id}_received_your_assigned_issues`, RECEIVED_MENTIONS: `${id}_received_mentions`, RECEIVED_TODOS: `${id}_received_todos`, RECEIVED_CONNECTED: `${id}_received_connected`, diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index e0b81c98d..245b34594 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -87,11 +87,11 @@ export function getReviewDetails(prList) { }; } -export function getYourPrs() { +export function getYourAssignedPrs() { return async (dispatch, getState) => { let data; try { - data = await Client.getYourPrs(); + data = await Client.getYourAssignedPrs(); } catch (error) { return {error}; } @@ -105,7 +105,7 @@ export function getYourPrs() { } dispatch({ - type: ActionTypes.RECEIVED_YOUR_PRS, + type: ActionTypes.RECEIVED_YOUR_ASSIGNED_PRS, data, }); @@ -136,11 +136,11 @@ export function getYourPrDetails(prList) { }; } -export function getYourAssignments() { +export function getYourAssignedIssues() { return async (dispatch, getState) => { let data; try { - data = await Client.getYourAssignments(); + data = await Client.getYourAssignedIssues(); } catch (error) { return {error}; } @@ -154,7 +154,7 @@ export function getYourAssignments() { } dispatch({ - type: ActionTypes.RECEIVED_YOUR_ASSIGNMENTS, + type: ActionTypes.RECEIVED_YOUR_ASSIGNED_ISSUES, data, }); diff --git a/webapp/src/client/client.js b/webapp/src/client/client.js index 2286d9470..67dc557c9 100644 --- a/webapp/src/client/client.js +++ b/webapp/src/client/client.js @@ -14,7 +14,7 @@ export default class Client { return this.doGet(`${this.url}/reviews`); }; - getYourPrs = async () => { + getYourAssignedPrs = async () => { return this.doGet(`${this.url}/yourassignedprs`); }; @@ -22,7 +22,7 @@ export default class Client { return this.doPost(`${this.url}/prdetails`, prList); } - getYourAssignments = async () => { + getYourAssignedIssues = async () => { return this.doGet(`${this.url}/yourassignedissues`); }; diff --git a/webapp/src/components/sidebar_buttons/index.js b/webapp/src/components/sidebar_buttons/index.js index 70ba3da5e..9a77a3282 100644 --- a/webapp/src/components/sidebar_buttons/index.js +++ b/webapp/src/components/sidebar_buttons/index.js @@ -4,8 +4,8 @@ import {bindActionCreators} from 'redux'; import { getReviews, getTodos, - getYourPrs, - getYourAssignments, + getYourAssignedPrs, + getYourAssignedIssues, updateRHSState, } from '../../actions'; @@ -21,8 +21,8 @@ function mapStateToProps(state) { username: state[`plugins-${id}`].username, clientId: state[`plugins-${id}`].clientId, reviews: state[`plugins-${id}`].reviews, - yourPrs: state[`plugins-${id}`].yourPrs, - yourAssignments: state[`plugins-${id}`].yourAssignments, + yourAssignedPrs: state[`plugins-${id}`].yourAssignedPrs, + yourAssignedIssues: state[`plugins-${id}`].yourAssignedIssues, todos: state[`plugins-${id}`].todos, gitlabURL: state[`plugins-${id}`].gitlabURL, org: state[`plugins-${id}`].organization, @@ -37,8 +37,8 @@ function mapDispatchToProps(dispatch) { { getReviews, getTodos, - getYourPrs, - getYourAssignments, + getYourAssignedPrs, + getYourAssignedIssues, updateRHSState, }, dispatch, diff --git a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx index 0b394e923..8b2ff2e02 100644 --- a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx +++ b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx @@ -15,16 +15,16 @@ export default class SidebarButtons extends React.PureComponent { gitlabURL: PropTypes.string, reviews: PropTypes.arrayOf(PropTypes.object), todos: PropTypes.arrayOf(PropTypes.object), - yourPrs: PropTypes.arrayOf(PropTypes.object), - yourAssignments: PropTypes.arrayOf(PropTypes.object), + yourAssignedPrs: PropTypes.arrayOf(PropTypes.object), + yourAssignedIssues: PropTypes.arrayOf(PropTypes.object), isTeamSidebar: PropTypes.bool, pluginServerRoute: PropTypes.string.isRequired, showRHSPlugin: PropTypes.func.isRequired, actions: PropTypes.shape({ getReviews: PropTypes.func.isRequired, getTodos: PropTypes.func.isRequired, - getYourPrs: PropTypes.func.isRequired, - getYourAssignments: PropTypes.func.isRequired, + getYourAssignedPrs: PropTypes.func.isRequired, + getYourAssignedIssues: PropTypes.func.isRequired, updateRHSState: PropTypes.func.isRequired, }).isRequired, }; @@ -62,8 +62,8 @@ export default class SidebarButtons extends React.PureComponent { await Promise.all([ this.props.actions.getReviews(), this.props.actions.getTodos(), - this.props.actions.getYourPrs(), - this.props.actions.getYourAssignments(), + this.props.actions.getYourAssignedPrs(), + this.props.actions.getYourAssignedIssues(), ]); this.setState({refreshing: false}); }; @@ -114,9 +114,9 @@ export default class SidebarButtons extends React.PureComponent { const baseURL = this.props.gitlabURL || 'https://gitlab.com'; const reviews = this.props.reviews || []; - const yourPrs = this.props.yourPrs || []; + const yourAssignedPrs = this.props.yourAssignedPrs || []; const todos = this.props.todos || []; - const yourAssignments = this.props.yourAssignments || []; + const yourAssignedIssues = this.props.yourAssignedIssues || []; const refreshClass = this.state.refreshing ? ' fa-spin' : ''; return ( @@ -131,16 +131,16 @@ export default class SidebarButtons extends React.PureComponent { {'Merge requests assigned'}} + overlay={{'Merge requests assigned'}} > this.openRHS(RHSStates.PRS)} style={button} > - {' ' + yourPrs.length} + {' ' + yourAssignedPrs.length} {'Issues'}} + overlay={{'Issues'}} > this.openRHS(RHSStates.ASSIGNMENTS)} + onClick={() => this.openRHS(RHSStates.ISSUES)} style={button} > - {' ' + yourAssignments.length} + {' ' + yourAssignedIssues.length} (yourPrs) + const prevPrs = usePrevious(yourAssignedPrs) const prevReviews = usePrevious(reviews) useEffect(() => { - if (yourPrs && (!prevPrs || shouldUpdateDetails(yourPrs, prevPrs, RHSStates.PRS, rhsState))) { - dispatch(getYourPrDetails(yourPrs)); + if (yourAssignedPrs && (!prevPrs || shouldUpdateDetails(yourAssignedPrs, prevPrs, RHSStates.PRS, rhsState))) { + dispatch(getYourPrDetails(yourAssignedPrs)); } - }, [yourPrs, rhsState, prevPrs]); + }, [yourAssignedPrs, rhsState, prevPrs]); useEffect(() => { if (reviews && (!prevReviews || shouldUpdateDetails(reviews, prevReviews, RHSStates.REVIEWS, rhsState))) { @@ -104,7 +104,7 @@ function SidebarRight({theme}: {theme: Theme}) { switch (rhsState) { case RHSStates.PRS: - gitlabItems = yourPrs; + gitlabItems = yourAssignedPrs; title = 'Merge Requests Assigned'; listUrl = `${baseURL}${orgQuery}/merge_requests?state=opened&assignee_username=${username}`; break; @@ -118,8 +118,8 @@ function SidebarRight({theme}: {theme: Theme}) { title = 'To-Do List'; listUrl = `${baseURL}/dashboard/todos`; break; - case RHSStates.ASSIGNMENTS: - gitlabItems = yourAssignments; + case RHSStates.ISSUES: + gitlabItems = yourAssignedIssues; title = 'Issues'; listUrl = `${baseURL}${orgQuery}/issues?assignee_username=${username}`; break; diff --git a/webapp/src/constants/index.js b/webapp/src/constants/index.js index 4bbebc033..732f8e2f5 100644 --- a/webapp/src/constants/index.js +++ b/webapp/src/constants/index.js @@ -8,5 +8,5 @@ export const RHSStates = { PRS: 'pullRequests', REVIEWS: 'reviews', TODOS: 'todos', - ASSIGNMENTS: 'assignments', + ISSUES: 'issues', }; diff --git a/webapp/src/reducers/index.js b/webapp/src/reducers/index.js index ed2886e3e..f6cefac22 100644 --- a/webapp/src/reducers/index.js +++ b/webapp/src/reducers/index.js @@ -88,9 +88,9 @@ function reviewDetails(state = [], action) { } } -function yourPrs(state = [], action) { +function yourAssignedPrs(state = [], action) { switch (action.type) { - case ActionTypes.RECEIVED_YOUR_PRS: + case ActionTypes.RECEIVED_YOUR_ASSIGNED_PRS: return action.data; default: return state; @@ -106,9 +106,9 @@ function yourPrDetails(state = [], action) { } } -function yourAssignments(state = [], action) { +function yourAssignedIssues(state = [], action) { switch (action.type) { - case ActionTypes.RECEIVED_YOUR_ASSIGNMENTS: + case ActionTypes.RECEIVED_YOUR_ASSIGNED_ISSUES: return action.data; default: return state; @@ -184,8 +184,8 @@ export default combineReducers({ settings, clientId, reviews, - yourPrs, - yourAssignments, + yourAssignedPrs, + yourAssignedIssues, mentions, todos, gitlabUsers, diff --git a/webapp/src/selectors/index.js b/webapp/src/selectors/index.js index fcbd4c916..57ada0bf9 100644 --- a/webapp/src/selectors/index.js +++ b/webapp/src/selectors/index.js @@ -48,9 +48,9 @@ export const getSidebarData = createSelector( username: pluginState.username, reviewDetails: pluginState.reviewDetails, reviews: mapPrsToDetails(pluginState.reviews, pluginState.reviewDetails), - yourPrs: mapPrsToDetails(pluginState.yourPrs, pluginState.yourPrDetails), + yourAssignedPrs: mapPrsToDetails(pluginState.yourAssignedPrs, pluginState.yourPrDetails), yourPrDetails: pluginState.yourPrDetails, - yourAssignments: pluginState.yourAssignments, + yourAssignedIssues: pluginState.yourAssignedIssues, todos: pluginState.todos, org: pluginState.organization, gitlabURL: pluginState.gitlabURL, diff --git a/webapp/src/websocket/index.js b/webapp/src/websocket/index.js index 974dc0cca..855d7735e 100644 --- a/webapp/src/websocket/index.js +++ b/webapp/src/websocket/index.js @@ -4,8 +4,8 @@ import { getConnected, getReviews, getTodos, - getYourPrs, - getYourAssignments, + getYourAssignedPrs, + getYourAssignedIssues, } from '../actions'; import {id} from '../manifest'; @@ -51,8 +51,8 @@ export function handleReconnect(store, reminder = false) { if (data && data.connected) { getReviews()(store.dispatch, store.getState); getTodos()(store.dispatch, store.getState); - getYourPrs()(store.dispatch, store.getState); - getYourAssignments()(store.dispatch, store.getState); + getYourAssignedPrs()(store.dispatch, store.getState); + getYourAssignedIssues()(store.dispatch, store.getState); } }; } @@ -62,8 +62,8 @@ export function handleRefresh(store) { if (store.getState()[`plugins-${id}`].connected) { getReviews()(store.dispatch, store.getState); getTodos()(store.dispatch, store.getState); - getYourPrs()(store.dispatch, store.getState); - getYourAssignments()(store.dispatch, store.getState); + getYourAssignedPrs()(store.dispatch, store.getState); + getYourAssignedIssues()(store.dispatch, store.getState); } }; } From 900865f5fd7997ac40d7cb00827a219b481a3fa6 Mon Sep 17 00:00:00 2001 From: raghavaggarwal2308 Date: Fri, 18 Aug 2023 14:31:14 +0530 Subject: [PATCH 3/6] [MI-3405] Updated icons in sidebar --- .../sidebar_buttons/button_icons.tsx | 17 ++++++++++++++ .../sidebar_buttons/sidebar_buttons.jsx | 22 ++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 webapp/src/components/sidebar_buttons/button_icons.tsx diff --git a/webapp/src/components/sidebar_buttons/button_icons.tsx b/webapp/src/components/sidebar_buttons/button_icons.tsx new file mode 100644 index 000000000..518bb71d2 --- /dev/null +++ b/webapp/src/components/sidebar_buttons/button_icons.tsx @@ -0,0 +1,17 @@ +import React from 'react'; + +export const GitLabIssuesIcon = ({fill}: {fill: string}) => ( + +) + +export const GitLabMergeRequestIcon = ({fill}: {fill: string}) => ( + +) + +export const GitLabReviewsIcon = ({fill}: {fill: string}) => ( + +) + +export const GitLabTodosIcon = ({fill}: {fill: string}) => ( + +) diff --git a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx index 8b2ff2e02..d71305c11 100644 --- a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx +++ b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import {makeStyleFromTheme, changeOpacity} from 'mattermost-redux/utils/theme_utils'; import {RHSStates} from 'src/constants'; +import { GitLabIssuesIcon, GitLabMergeRequestIcon, GitLabReviewsIcon, GitLabTodosIcon } from './button_icons'; export default class SidebarButtons extends React.PureComponent { static propTypes = { @@ -139,8 +140,8 @@ export default class SidebarButtons extends React.PureComponent { onClick={() => this.openRHS(RHSStates.PRS)} style={button} > - - {' ' + yourAssignedPrs.length} + + {yourAssignedPrs.length} this.openRHS(RHSStates.REVIEWS)} style={button} > - - {' ' + reviews.length} + + {reviews.length} this.openRHS(RHSStates.ISSUES)} style={button} > - - {' ' + yourAssignedIssues.length} + + {yourAssignedIssues.length} this.openRHS(RHSStates.TODOS)} style={button} > - - {' ' + todos.length} + + {todos.length} { color: changeOpacity(theme.sidebarText, 0.6), textAlign: 'center', cursor: 'pointer', + display: 'flex', + alignItems: 'center', + }, + buttonCount: { + marginLeft: '2px', }, containerHeader: { marginTop: '10px', From 47247b109bfe8ab62ff6cf791fa8d905ccea30ec Mon Sep 17 00:00:00 2001 From: raghavaggarwal2308 Date: Fri, 18 Aug 2023 15:24:48 +0530 Subject: [PATCH 4/6] [MI-3405] Updated documentation --- README.md | 4 ++-- docs/feature-summary.md | 4 ++-- server/api.go | 6 +++--- server/command.go | 6 +++--- server/plugin.go | 8 ++++---- webapp/package-lock.json | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index cdccd921d..f1f59b096 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Each user in Mattermost is connected with their own personal GitLab account. Use ### Sidebar buttons -Team members can stay up-to-date with how many reviews, unread messages, assignments, and open merge requests they have by using buttons in the Mattermost sidebar. +Team members can stay up-to-date with how many reviews, todos, assigned issues, and assigned merge requests they have by using buttons in the Mattermost sidebar. ## Admin guide @@ -142,7 +142,7 @@ Connect your Mattermost account to your GitLab account using `/gitlab connect` a ### Get "To Do" items -Use `/gitlab todo` to get a list of unread messages and merge requests awaiting your review. +Use `/gitlab todo` to get a list of todos, assigned issues, assigned merge requests and merge requests awaiting your review. ### Update settings diff --git a/docs/feature-summary.md b/docs/feature-summary.md index 70e4fd734..aa49fef6b 100644 --- a/docs/feature-summary.md +++ b/docs/feature-summary.md @@ -33,7 +33,7 @@ Each user in Mattermost is connected with their own personal GitLab account. Use ### Sidebar Buttons -Team members can stay up-to-date with how many reviews, unread messages, assignments, and open merge requests they have by using buttons in the Mattermost sidebar. +Team members can stay up-to-date with how many reviews, todos, assigned issues, and assigned merge requests they have by using buttons in the Mattermost sidebar. @@ -57,7 +57,7 @@ Connect your Mattermost account to your GitLab account using `/gitlab connect` a ### Get "To Do" Items -Use `/gitlab todo` to get a list of unread messages and merge requests awaiting your review. +Use `/gitlab todo` to get a list of todos, assigned issues, assigned merge requests and merge requests awaiting your review. ### Update Settings diff --git a/server/api.go b/server/api.go index af4258e66..ce33e9c45 100644 --- a/server/api.go +++ b/server/api.go @@ -396,10 +396,10 @@ func (p *Plugin) completeConnectUserToGitlab(c *Context, w http.ResponseWriter, "Turn off notifications with `/gitlab settings notifications off`.\n\n"+ "##### Sidebar Buttons\n"+ "Check out the buttons in the left-hand sidebar of Mattermost.\n"+ - "* The first button tells you how many merge requests you have submitted.\n"+ + "* The first button tells you how many merge requests you are assigned to.\n"+ "* The second shows the number of merge requests that are awaiting your review.\n"+ - "* The third shows the number of merge requests and issues you are assigned to.\n"+ - "* The fourth tracks the number of unread messages you have.\n"+ + "* The third shows the number of issues you are assigned to.\n"+ + "* The fourth tracks the number of todos you have.\n"+ "* The fifth will refresh the numbers.\n\n"+ "Click on them!\n\n"+ "##### Slash Commands\n"+ diff --git a/server/command.go b/server/command.go index 88ead39cc..c3f0dad9e 100644 --- a/server/command.go +++ b/server/command.go @@ -19,7 +19,7 @@ import ( const commandHelp = `* |/gitlab connect| - Connect your Mattermost account to your GitLab account * |/gitlab disconnect| - Disconnect your Mattermost account from your GitLab account -* |/gitlab todo| - Get a list of unread messages and merge requests awaiting your review +* |/gitlab todo| - Get a list of todos, assigned issues, assigned merge requests and merge requests awaiting your review * |/gitlab subscriptions list| - Will list the current channel subscriptions * |/gitlab subscriptions add owner[/repo] [features]| - Subscribe the current channel to receive notifications about opened merge requests and issues for a group or repository * |features| is a comma-delimited list of one or more the following: @@ -248,7 +248,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (res _, text, err := p.GetToDo(ctx, info) if err != nil { p.client.Log.Warn("can't get todo in command", "err", err.Error()) - return p.getCommandResponse(args, "Encountered an error getting your to do items."), nil + return p.getCommandResponse(args, "Encountered an error getting your todo items."), nil } return p.getCommandResponse(args, text), nil case "me": @@ -773,7 +773,7 @@ func getAutocompleteData(config *configuration) *model.AutocompleteData { disconnect := model.NewAutocompleteData("disconnect", "", "disconnect your GitLab account") gitlab.AddCommand(disconnect) - todo := model.NewAutocompleteData("todo", "", "Get a list of unread messages and merge requests awaiting your review") + todo := model.NewAutocompleteData("todo", "", "Get a list of todos, assigned issues, assigned merge requests and merge requests awaiting your review") gitlab.AddCommand(todo) subscriptions := model.NewAutocompleteData("subscriptions", "[command]", "Available commands: Add, List, Delete") diff --git a/server/plugin.go b/server/plugin.go index 4f69f5304..c511d16a0 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -604,9 +604,9 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri } if notificationCount == 0 { - notificationText += "You don't have any unread messages.\n" + notificationText += "You don't have any todos.\n" } else { - notificationText += fmt.Sprintf("You have %v unread messages:\n", notificationCount) + notificationText += fmt.Sprintf("You have %v todos:\n", notificationCount) notificationText += notificationContent hasTodo = true @@ -691,9 +691,9 @@ func (p *Plugin) GetToDo(ctx context.Context, user *gitlab.UserInfo) (bool, stri } if len(mergeRequests) == 0 { - mergeRequestText += "You don't have any open merge requests.\n" + mergeRequestText += "You don't have any merge requests assigned.\n" } else { - mergeRequestText += fmt.Sprintf("You have %v open merge requests:\n", len(mergeRequests)) + mergeRequestText += fmt.Sprintf("You have %v merge requests assigned:\n", len(mergeRequests)) for _, pr := range mergeRequests { mergeRequestText += fmt.Sprintf("* [%v](%v)\n", pr.Title, pr.WebURL) diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 28a39006d..89f194202 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -6139,7 +6139,7 @@ "react-custom-scrollbars": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/react-custom-scrollbars/-/react-custom-scrollbars-4.2.1.tgz", - "integrity": "sha1-gw/ZUCkn6X6KeMIIaBOJmyqLZts=", + "integrity": "sha512-VtJTUvZ7kPh/auZWIbBRceGPkE30XBYe+HktFxuMWBR2eVQQ+Ur6yFJMoaYcNpyGq22uYJ9Wx4UAEcC0K+LNPQ==", "requires": { "dom-css": "^2.0.0", "prop-types": "^15.5.10", @@ -7431,7 +7431,7 @@ "to-camel-case": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-camel-case/-/to-camel-case-1.0.0.tgz", - "integrity": "sha1-GlYFSy+daWKYzmamCJcyK29CPkY=", + "integrity": "sha512-nD8pQi5H34kyu1QDMFjzEIYqk0xa9Alt6ZfrdEMuHCFOfTLhDG5pgTu/aAM9Wt9lXILwlXmWP43b8sav0GNE8Q==", "requires": { "to-space-case": "^1.0.0" } @@ -7445,7 +7445,7 @@ "to-no-case": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/to-no-case/-/to-no-case-1.0.2.tgz", - "integrity": "sha1-xyKQcWTvaxeBMsjmmTAhLRtKoWo=" + "integrity": "sha512-Z3g735FxuZY8rodxV4gH7LxClE4H0hTIyHNIHdk+vpQxjLm0cwnKXq/OFVZ76SOQmto7txVcwSCwkU5kqp+FKg==" }, "to-object-path": { "version": "0.3.0", @@ -7492,7 +7492,7 @@ "to-space-case": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-space-case/-/to-space-case-1.0.0.tgz", - "integrity": "sha1-sFLar7Gysp3HcM6gFj5ewOvJ/Bc=", + "integrity": "sha512-rLdvwXZ39VOn1IxGL3V6ZstoTbwLRckQmn/U8ZDLuWwIXNpuZDhQ3AiRUlhTbOXFVE9C+dR51wM0CBDhk31VcA==", "requires": { "to-no-case": "^1.0.0" } From 9c6dceba4c9c991f7adbefc2cdb3e3cff08049e4 Mon Sep 17 00:00:00 2001 From: raghavaggarwal2308 Date: Fri, 18 Aug 2023 15:32:55 +0530 Subject: [PATCH 5/6] [MI-3405] Reverted package-lock file changes --- webapp/package-lock.json | 8 ++++---- .../src/components/sidebar_buttons/sidebar_buttons.jsx | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 89f194202..28a39006d 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -6139,7 +6139,7 @@ "react-custom-scrollbars": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/react-custom-scrollbars/-/react-custom-scrollbars-4.2.1.tgz", - "integrity": "sha512-VtJTUvZ7kPh/auZWIbBRceGPkE30XBYe+HktFxuMWBR2eVQQ+Ur6yFJMoaYcNpyGq22uYJ9Wx4UAEcC0K+LNPQ==", + "integrity": "sha1-gw/ZUCkn6X6KeMIIaBOJmyqLZts=", "requires": { "dom-css": "^2.0.0", "prop-types": "^15.5.10", @@ -7431,7 +7431,7 @@ "to-camel-case": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-camel-case/-/to-camel-case-1.0.0.tgz", - "integrity": "sha512-nD8pQi5H34kyu1QDMFjzEIYqk0xa9Alt6ZfrdEMuHCFOfTLhDG5pgTu/aAM9Wt9lXILwlXmWP43b8sav0GNE8Q==", + "integrity": "sha1-GlYFSy+daWKYzmamCJcyK29CPkY=", "requires": { "to-space-case": "^1.0.0" } @@ -7445,7 +7445,7 @@ "to-no-case": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/to-no-case/-/to-no-case-1.0.2.tgz", - "integrity": "sha512-Z3g735FxuZY8rodxV4gH7LxClE4H0hTIyHNIHdk+vpQxjLm0cwnKXq/OFVZ76SOQmto7txVcwSCwkU5kqp+FKg==" + "integrity": "sha1-xyKQcWTvaxeBMsjmmTAhLRtKoWo=" }, "to-object-path": { "version": "0.3.0", @@ -7492,7 +7492,7 @@ "to-space-case": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-space-case/-/to-space-case-1.0.0.tgz", - "integrity": "sha512-rLdvwXZ39VOn1IxGL3V6ZstoTbwLRckQmn/U8ZDLuWwIXNpuZDhQ3AiRUlhTbOXFVE9C+dR51wM0CBDhk31VcA==", + "integrity": "sha1-sFLar7Gysp3HcM6gFj5ewOvJ/Bc=", "requires": { "to-no-case": "^1.0.0" } diff --git a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx index d71305c11..88f7b353d 100644 --- a/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx +++ b/webapp/src/components/sidebar_buttons/sidebar_buttons.jsx @@ -4,7 +4,8 @@ import PropTypes from 'prop-types'; import {makeStyleFromTheme, changeOpacity} from 'mattermost-redux/utils/theme_utils'; import {RHSStates} from 'src/constants'; -import { GitLabIssuesIcon, GitLabMergeRequestIcon, GitLabReviewsIcon, GitLabTodosIcon } from './button_icons'; + +import {GitLabIssuesIcon, GitLabMergeRequestIcon, GitLabReviewsIcon, GitLabTodosIcon} from './button_icons'; export default class SidebarButtons extends React.PureComponent { static propTypes = { @@ -141,7 +142,7 @@ export default class SidebarButtons extends React.PureComponent { style={button} > - {yourAssignedPrs.length} + {yourAssignedPrs.length} this.openRHS(RHSStates.REVIEWS)} style={button} > - - {reviews.length} + + {reviews.length} Date: Tue, 22 Aug 2023 16:10:32 +0530 Subject: [PATCH 6/6] [MI-3405] Review fixes --- server/api.go | 4 ++-- webapp/src/client/client.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/api.go b/server/api.go index ce33e9c45..0487f2843 100644 --- a/server/api.go +++ b/server/api.go @@ -56,9 +56,9 @@ func (p *Plugin) initializeAPI() { apiRouter.HandleFunc("/user", p.checkAuth(p.attachContext(p.getGitlabUser), ResponseTypeJSON)).Methods(http.MethodPost) apiRouter.HandleFunc("/todo", p.checkAuth(p.attachUserContext(p.postToDo), ResponseTypeJSON)).Methods(http.MethodPost) apiRouter.HandleFunc("/reviews", p.checkAuth(p.attachUserContext(p.getReviews), ResponseTypePlain)).Methods(http.MethodGet) - apiRouter.HandleFunc("/yourassignedprs", p.checkAuth(p.attachUserContext(p.getYourAssignedPrs), ResponseTypePlain)).Methods(http.MethodGet) + apiRouter.HandleFunc("/assignedprs", p.checkAuth(p.attachUserContext(p.getYourAssignedPrs), ResponseTypePlain)).Methods(http.MethodGet) apiRouter.HandleFunc("/prdetails", p.checkAuth(p.attachUserContext(p.getPrDetails), ResponseTypePlain)).Methods(http.MethodPost) - apiRouter.HandleFunc("/yourassignedissues", p.checkAuth(p.attachUserContext(p.getYourAssignedIssues), ResponseTypePlain)).Methods(http.MethodGet) + apiRouter.HandleFunc("/assignedissues", p.checkAuth(p.attachUserContext(p.getYourAssignedIssues), ResponseTypePlain)).Methods(http.MethodGet) apiRouter.HandleFunc("/todolist", p.checkAuth(p.attachUserContext(p.getToDoList), ResponseTypePlain)).Methods(http.MethodGet) apiRouter.HandleFunc("/settings", p.checkAuth(p.attachUserContext(p.updateSettings), ResponseTypePlain)).Methods(http.MethodPost) diff --git a/webapp/src/client/client.js b/webapp/src/client/client.js index 67dc557c9..734c80cd9 100644 --- a/webapp/src/client/client.js +++ b/webapp/src/client/client.js @@ -15,7 +15,7 @@ export default class Client { }; getYourAssignedPrs = async () => { - return this.doGet(`${this.url}/yourassignedprs`); + return this.doGet(`${this.url}/assignedprs`); }; getPrsDetails = async (prList) => { @@ -23,7 +23,7 @@ export default class Client { } getYourAssignedIssues = async () => { - return this.doGet(`${this.url}/yourassignedissues`); + return this.doGet(`${this.url}/assignedissues`); }; getMentions = async () => {