-
Notifications
You must be signed in to change notification settings - Fork 124
/
project_resolver.go
57 lines (50 loc) · 2.11 KB
/
project_resolver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package graphql
import (
"context"
"fmt"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/evergreen/model/patch"
restModel "github.com/evergreen-ci/evergreen/rest/model"
"github.com/evergreen-ci/utility"
)
// IsFavorite is the resolver for the isFavorite field.
func (r *projectResolver) IsFavorite(ctx context.Context, obj *restModel.APIProjectRef) (bool, error) {
p, err := model.FindBranchProjectRef(*obj.Identifier)
if err != nil || p == nil {
return false, ResourceNotFound.Send(ctx, fmt.Sprintf("Could not find project: %s : %s", *obj.Identifier, err))
}
usr := mustHaveUser(ctx)
if utility.StringSliceContains(usr.FavoriteProjects, *obj.Identifier) {
return true, nil
}
return false, nil
}
// Patches is the resolver for the patches field.
func (r *projectResolver) Patches(ctx context.Context, obj *restModel.APIProjectRef, patchesInput PatchesInput) (*Patches, error) {
opts := patch.ByPatchNameStatusesCommitQueuePaginatedOptions{
Project: obj.Id,
PatchName: patchesInput.PatchName,
Statuses: patchesInput.Statuses,
Page: patchesInput.Page,
Limit: patchesInput.Limit,
OnlyCommitQueue: patchesInput.OnlyCommitQueue,
IncludeHidden: patchesInput.IncludeHidden,
}
patches, count, err := patch.ByPatchNameStatusesCommitQueuePaginated(ctx, opts)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("Error while fetching patches for this project : %s", err.Error()))
}
apiPatches := []*restModel.APIPatch{}
for _, p := range patches {
apiPatch := restModel.APIPatch{}
err = apiPatch.BuildFromService(p, nil) // Injecting DB info into APIPatch is handled by the resolvers.
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("problem building APIPatch from service for patch: %s : %s", p.Id.Hex(), err.Error()))
}
apiPatches = append(apiPatches, &apiPatch)
}
return &Patches{Patches: apiPatches, FilteredPatchCount: count}, nil
}
// Project returns ProjectResolver implementation.
func (r *Resolver) Project() ProjectResolver { return &projectResolver{r} }
type projectResolver struct{ *Resolver }