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

Optimized code to decrease the number of API calls to get label details #514

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/custom.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GO_BUILD_FLAGS += -ldflags '-X "github.com/mattermost/mattermost/server/public/p
.PHONY: mock
mock:
ifneq ($(HAS_SERVER),)
go install github.com/golang/mock/mockgen@v1.6.0
go get go.uber.org/mock/mockgen
mockgen -destination server/mocks/mock_gitlab.go github.com/mattermost/mattermost-plugin-gitlab/server/gitlab Gitlab
mockgen -destination server/gitlab/mocks/mock_gitlab.go github.com/mattermost/mattermost-plugin-gitlab/server/gitlab Gitlab
endif
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/mattermost/mattermost-plugin-gitlab
go 1.21

require (
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.0
github.com/mattermost/mattermost/server/public v0.0.9-0.20230830065520-5de1e306de52
github.com/microcosm-cc/bluemonday v1.0.19
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/xanzy/go-gitlab v0.97.0
go.uber.org/mock v0.4.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/sync v0.3.0
)

require (
Expand Down
17 changes: 4 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,24 @@ github.com/xanzy/go-gitlab v0.97.0 h1:StMqJ1Kvt00X43pYIBBjj52dFlghwSeBhRDRfzaZ7x
github.com/xanzy/go-gitlab v0.97.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
go.opentelemetry.io/otel v1.6.3/go.mod h1:7BgNga5fNlF/iZjG06hM3yofffp0ofKCDwSXx1GC4dI=
go.opentelemetry.io/otel/trace v1.6.3/go.mod h1:GNJQusJlUgZl9/TQBPKU/Y/ty+0iVB5fjhKeJGZPGFs=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -258,11 +257,9 @@ golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
Expand All @@ -280,21 +277,18 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -329,13 +323,10 @@ golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y=
Expand Down
2 changes: 1 addition & 1 deletion server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"testing"

"github.com/golang/mock/gomock"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin/plugintest"
"github.com/mattermost/mattermost/server/public/pluginapi"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
gitLabAPI "github.com/xanzy/go-gitlab"
"go.uber.org/mock/gomock"

"github.com/mattermost/mattermost-plugin-gitlab/server/gitlab"
mocks "github.com/mattermost/mattermost-plugin-gitlab/server/gitlab/mocks"
Expand Down
142 changes: 53 additions & 89 deletions server/gitlab/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

const (
stateOpened = "opened"
scopeAll = "all"
stateOpened = "opened"
scopeAll = "all"
getLabelsTrue = true

perPage = 20
)
Expand Down Expand Up @@ -48,19 +49,19 @@ type PRDetails struct {

type MergeRequest struct {
*internGitlab.MergeRequest
LabelsWithDetails []*internGitlab.Label `json:"labels_with_details,omitempty"`
LabelsWithDetails []*internGitlab.Label `json:"label_details,omitempty"`
}

type Issue struct {
*internGitlab.Issue
LabelsWithDetails []*internGitlab.Label `json:"labels_with_details,omitempty"`
LabelsWithDetails []*internGitlab.Label `json:"label_details,omitempty"`
}

type LHSContent struct {
AssignedPRs []*MergeRequest `json:"yourAssignedPrs"`
Reviews []*MergeRequest `json:"reviews"`
AssignedIssues []*Issue `json:"yourAssignedIssues"`
Todos []*internGitlab.Todo `json:"todos"`
AssignedPRs []*internGitlab.MergeRequest `json:"yourAssignedPrs"`
Reviews []*internGitlab.MergeRequest `json:"reviews"`
AssignedIssues []*internGitlab.Issue `json:"yourAssignedIssues"`
Todos []*internGitlab.Todo `json:"todos"`
}

// NewGroupHook creates a webhook associated with a GitLab group
Expand Down Expand Up @@ -313,19 +314,19 @@ func (g *gitlab) GetLHSData(ctx context.Context, user *UserInfo, token *oauth2.T

grp, ctx := errgroup.WithContext(ctx)

var reviews []*MergeRequest
var reviews []*internGitlab.MergeRequest
grp.Go(func() error {
reviews, err = g.GetReviews(ctx, user, client)
return err
})

var issues []*Issue
var issues []*internGitlab.Issue
grp.Go(func() error {
issues, err = g.GetYourAssignedIssues(ctx, user, client)
return err
})

var mergeRequests []*MergeRequest
var mergeRequests []*internGitlab.MergeRequest
grp.Go(func() error {
mergeRequests, err = g.GetYourAssignedPrs(ctx, user, client)
return err
Expand All @@ -349,17 +350,18 @@ func (g *gitlab) GetLHSData(ctx context.Context, user *UserInfo, token *oauth2.T
}, nil
}

func (g *gitlab) GetReviews(ctx context.Context, user *UserInfo, client *internGitlab.Client) ([]*MergeRequest, error) {
func (g *gitlab) GetReviews(ctx context.Context, user *UserInfo, client *internGitlab.Client) ([]*internGitlab.MergeRequest, error) {
opened := stateOpened
scope := scopeAll

getLabelDetails := getLabelsTrue
var mrs []*internGitlab.MergeRequest
if g.gitlabGroup == "" {
opt := &internGitlab.ListMergeRequestsOptions{
ReviewerID: internGitlab.ReviewerID(user.GitlabUserID),
State: &opened,
Scope: &scope,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
ReviewerID: internGitlab.ReviewerID(user.GitlabUserID),
State: &opened,
Scope: &scope,
WithLabelsDetails: &getLabelDetails,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
}
for {
current, resp, err := client.MergeRequests.ListMergeRequests(opt)
Expand All @@ -374,10 +376,11 @@ func (g *gitlab) GetReviews(ctx context.Context, user *UserInfo, client *internG
}
} else {
opt := &internGitlab.ListGroupMergeRequestsOptions{
ReviewerID: internGitlab.ReviewerID(user.GitlabUserID),
State: &opened,
Scope: &scope,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
ReviewerID: internGitlab.ReviewerID(user.GitlabUserID),
State: &opened,
Scope: &scope,
WithLabelsDetails: &getLabelDetails,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
}
for {
current, resp, err := client.MergeRequests.ListGroupMergeRequests(g.gitlabGroup, opt)
Expand All @@ -392,34 +395,21 @@ func (g *gitlab) GetReviews(ctx context.Context, user *UserInfo, client *internG
}
}

mergeRequests := []*MergeRequest{}
for _, mr := range mrs {
if mr.Labels != nil {
labelsWithDetails, err := g.GetLabelDetails(client, mr.ProjectID, mr.Labels)
if err != nil {
return nil, err
}
mergeRequest := &MergeRequest{
MergeRequest: mr,
LabelsWithDetails: labelsWithDetails,
}
mergeRequests = append(mergeRequests, mergeRequest)
}
}

return mergeRequests, nil
return mrs, nil
}

func (g *gitlab) GetYourAssignedPrs(ctx context.Context, user *UserInfo, client *internGitlab.Client) ([]*MergeRequest, error) {
func (g *gitlab) GetYourAssignedPrs(ctx context.Context, user *UserInfo, client *internGitlab.Client) ([]*internGitlab.MergeRequest, error) {
opened := stateOpened
scope := scopeAll
getLabelDetails := getLabelsTrue
var mrs []*internGitlab.MergeRequest
if g.gitlabGroup == "" {
opt := &internGitlab.ListMergeRequestsOptions{
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
WithLabelsDetails: &getLabelDetails,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
}
for {
current, resp, err := client.MergeRequests.ListMergeRequests(opt)
Expand All @@ -434,10 +424,11 @@ func (g *gitlab) GetYourAssignedPrs(ctx context.Context, user *UserInfo, client
}
} else {
opt := &internGitlab.ListGroupMergeRequestsOptions{
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
WithLabelsDetails: &getLabelDetails,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
}
for {
current, resp, err := client.MergeRequests.ListGroupMergeRequests(g.gitlabGroup, opt)
Expand All @@ -452,21 +443,7 @@ func (g *gitlab) GetYourAssignedPrs(ctx context.Context, user *UserInfo, client
}
}

mergeRequests := []*MergeRequest{}
for _, mr := range mrs {
if mr.Labels != nil {
labelsWithDetails, err := g.GetLabelDetails(client, mr.ProjectID, mr.Labels)
if err != nil {
return nil, err
}
mergeRequest := &MergeRequest{
MergeRequest: mr,
LabelsWithDetails: labelsWithDetails,
}
mergeRequests = append(mergeRequests, mergeRequest)
}
}
return mergeRequests, nil
return mrs, nil
}

func (g *gitlab) GetLabelDetails(client *internGitlab.Client, pid int, labels internGitlab.Labels) ([]*internGitlab.Label, error) {
Expand Down Expand Up @@ -563,17 +540,18 @@ func (g *gitlab) fetchYourPrDetails(c context.Context, log logger.Logger, client
return nil
}

func (g *gitlab) GetYourAssignedIssues(ctx context.Context, user *UserInfo, client *internGitlab.Client) ([]*Issue, error) {
func (g *gitlab) GetYourAssignedIssues(ctx context.Context, user *UserInfo, client *internGitlab.Client) ([]*internGitlab.Issue, error) {
opened := stateOpened
scope := scopeAll
var issues []*internGitlab.Issue

getLabelDetails := getLabelsTrue
if g.gitlabGroup == "" {
opt := &internGitlab.ListIssuesOptions{
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
WithLabelDetails: &getLabelDetails,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
}
for {
current, resp, err := client.Issues.ListIssues(opt)
Expand All @@ -588,10 +566,11 @@ func (g *gitlab) GetYourAssignedIssues(ctx context.Context, user *UserInfo, clie
}
} else {
opt := &internGitlab.ListGroupIssuesOptions{
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
AssigneeID: internGitlab.AssigneeID(user.GitlabUserID),
State: &opened,
Scope: &scope,
WithLabelDetails: &getLabelDetails,
ListOptions: internGitlab.ListOptions{Page: 1, PerPage: perPage},
}
for {
current, resp, err := client.Issues.ListGroupIssues(g.gitlabGroup, opt)
Expand All @@ -605,22 +584,7 @@ func (g *gitlab) GetYourAssignedIssues(ctx context.Context, user *UserInfo, clie
opt.Page = resp.NextPage
}
}

var result []*Issue
for _, issue := range issues {
if issue.Labels != nil {
labelsWithDetails, err := g.GetLabelDetails(client, issue.ProjectID, issue.Labels)
if err != nil {
return nil, err
}
issue := &Issue{
Issue: issue,
LabelsWithDetails: labelsWithDetails,
}
result = append(result, issue)
}
}
return result, nil
return issues, nil
}

func (g *gitlab) GetToDoList(ctx context.Context, user *UserInfo, client *internGitlab.Client) ([]*internGitlab.Todo, error) {
Expand Down Expand Up @@ -962,7 +926,7 @@ func (g *gitlab) GetIssueByID(ctx context.Context, user *UserInfo, owner, repo s
gitlabIssue := &Issue{
Issue: issue,
}
if issue.Labels != nil {
if len(issue.Labels) > 0 {
labelsWithDetails, err := g.GetLabelDetails(client, issue.ProjectID, issue.Labels)
if err != nil {
return nil, err
Expand Down Expand Up @@ -990,7 +954,7 @@ func (g *gitlab) GetMergeRequestByID(ctx context.Context, user *UserInfo, owner,
gitlabMergeRequest := &MergeRequest{
MergeRequest: mergeRequest,
}
if mergeRequest.Labels != nil {
if len(mergeRequest.Labels) > 0 {
labelsWithDetails, err := g.GetLabelDetails(client, mergeRequest.ProjectID, mergeRequest.Labels)
if err != nil {
return nil, err
Expand Down
Loading
Loading