Skip to content

Commit

Permalink
feat(issue): add mutations for activities/componentVersions (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
MR2011 authored Jul 15, 2024
1 parent a1ab4ed commit 8ce2f55
Show file tree
Hide file tree
Showing 21 changed files with 1,704 additions and 0 deletions.
472 changes: 472 additions & 0 deletions internal/api/graphql/graph/generated.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

mutation ($activityId: ID!, $issueId: ID!) {
addIssueToActivity (
activityId: $activityId,
issueId: $issueId
) {
id
issues {
edges {
node {
id
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

mutation ($activityId: ID!, $issueId: ID!) {
removeIssueFromActivity (
activityId: $activityId,
issueId: $issueId
) {
id
issues {
edges {
node {
id
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

mutation ($issueId: ID!, $componentVersionId: ID!) {
addComponentVersionToIssue (
issueId: $issueId,
componentVersionId: $componentVersionId
) {
id
componentVersions {
edges {
node {
id
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

mutation ($issueId: ID!, $componentVersionId: ID!) {
removeComponentVersionFromIssue (
issueId: $issueId,
componentVersionId: $componentVersionId
) {
id
componentVersions {
edges {
node {
id
}
}
}
}
}
88 changes: 88 additions & 0 deletions internal/api/graphql/graph/resolver/mutation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/api/graphql/graph/schema/mutation.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Mutation {
createIssue(input: IssueInput!): Issue!
updateIssue(id: ID!, input: IssueInput!): Issue!
deleteIssue(id: ID!): String!
addComponentVersionToIssue(issueId: ID!, componentVersionId: ID!): Issue!
removeComponentVersionFromIssue(issueId: ID!, componentVersionId: ID!): Issue!

createIssueVariant(input: IssueVariantInput!): IssueVariant!
updateIssueVariant(id: ID!, input: IssueVariantInput!): IssueVariant!
Expand All @@ -63,4 +65,6 @@ type Mutation {
deleteActivity(id: ID!): String!
addServiceToActivity(activityId: ID!, serviceId: ID!): Activity!
removeServiceFromActivity(activityId: ID!, serviceId: ID!): Activity!
addIssueToActivity(activityId: ID!, issueId: ID!): Activity!
removeIssueFromActivity(activityId: ID!, issueId: ID!): Activity!
}
34 changes: 34 additions & 0 deletions internal/app/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,37 @@ func (h *HeurekaApp) RemoveServiceFromActivity(activityId, serviceId int64) (*en

return h.GetActivity(activityId)
}

func (h *HeurekaApp) AddIssueToActivity(activityId, issueId int64) (*entity.Activity, error) {
l := logrus.WithFields(logrus.Fields{
"event": "app.AddIssueToActivity",
"activityId": activityId,
"issueId": issueId,
})

err := h.database.AddIssueToActivity(activityId, issueId)

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while adding issue to activity.")
}

return h.GetActivity(activityId)
}

func (h *HeurekaApp) RemoveIssueFromActivity(activityId, issueId int64) (*entity.Activity, error) {
l := logrus.WithFields(logrus.Fields{
"event": "app.RemoveIssueFromActivity",
"activityId": activityId,
"issueId": issueId,
})

err := h.database.RemoveIssueFromActivity(activityId, issueId)

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while removing issue from activity.")
}

return h.GetActivity(activityId)
}
44 changes: 44 additions & 0 deletions internal/app/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,47 @@ var _ = Describe("When modifying relationship of Service and Activity", Label("a
Expect(activity).NotTo(BeNil(), "activity should be returned")
})
})

var _ = Describe("When modifying relationship of Issue and Activity", Label("app", "IssueActivityRelationship"), func() {
var (
db *mocks.MockDatabase
heureka app.Heureka
issue entity.Issue
activity entity.Activity
filter *entity.ActivityFilter
)

BeforeEach(func() {
db = mocks.NewMockDatabase(GinkgoT())
issue = test.NewFakeIssueEntity()
activity = test.NewFakeActivityEntity()
first := 10
var after int64
after = 0
filter = &entity.ActivityFilter{
Paginated: entity.Paginated{
First: &first,
After: &after,
},
Id: []*int64{&activity.Id},
}
})

It("adds issue to activity", func() {
db.On("AddIssueToActivity", activity.Id, issue.Id).Return(nil)
db.On("GetActivities", filter).Return([]entity.Activity{activity}, nil)
heureka = app.NewHeurekaApp(db)
activity, err := heureka.AddIssueToActivity(activity.Id, issue.Id)
Expect(err).To(BeNil(), "no error should be thrown")
Expect(activity).NotTo(BeNil(), "activity should be returned")
})

It("removes issue from activity", func() {
db.On("RemoveIssueFromActivity", activity.Id, issue.Id).Return(nil)
db.On("GetActivities", filter).Return([]entity.Activity{activity}, nil)
heureka = app.NewHeurekaApp(db)
activity, err := heureka.RemoveIssueFromActivity(activity.Id, issue.Id)
Expect(err).To(BeNil(), "no error should be thrown")
Expect(activity).NotTo(BeNil(), "activity should be returned")
})
})
4 changes: 4 additions & 0 deletions internal/app/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Heureka interface {
CreateIssue(*entity.Issue) (*entity.Issue, error)
UpdateIssue(*entity.Issue) (*entity.Issue, error)
DeleteIssue(int64) error
AddComponentVersionToIssue(int64, int64) (*entity.Issue, error)
RemoveComponentVersionFromIssue(int64, int64) (*entity.Issue, error)

ListIssueVariants(*entity.IssueVariantFilter, *entity.ListOptions) (*entity.List[entity.IssueVariantResult], error)
ListEffectiveIssueVariants(*entity.IssueVariantFilter, *entity.ListOptions) (*entity.List[entity.IssueVariantResult], error)
Expand Down Expand Up @@ -72,6 +74,8 @@ type Heureka interface {
DeleteActivity(int64) error
AddServiceToActivity(int64, int64) (*entity.Activity, error)
RemoveServiceFromActivity(int64, int64) (*entity.Activity, error)
AddIssueToActivity(int64, int64) (*entity.Activity, error)
RemoveIssueFromActivity(int64, int64) (*entity.Activity, error)

ListEvidences(*entity.EvidenceFilter, *entity.ListOptions) (*entity.List[entity.EvidenceResult], error)
CreateEvidence(*entity.Evidence) (*entity.Evidence, error)
Expand Down
52 changes: 52 additions & 0 deletions internal/app/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ func (h *HeurekaApp) getIssueResults(filter *entity.IssueFilter) ([]entity.Issue
return issueResults, nil
}

func (h *HeurekaApp) GetIssue(id int64) (*entity.Issue, error) {
l := logrus.WithFields(logrus.Fields{
"event": "app.GetIssue",
"id": id,
})

issues, err := h.ListIssues(&entity.IssueFilter{Id: []*int64{&id}}, &entity.ListOptions{})

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while retrieving issue.")
}

if len(issues.Elements) != 1 {
return nil, heurekaError(fmt.Sprintf("Issue %d not found.", id))
}

return issues.Elements[0].Issue, nil
}

func (h *HeurekaApp) ListIssues(filter *entity.IssueFilter, options *entity.ListOptions) (*entity.List[entity.IssueResult], error) {
var count int64
var pageInfo *entity.PageInfo
Expand Down Expand Up @@ -175,3 +195,35 @@ func (h *HeurekaApp) DeleteIssue(id int64) error {

return nil
}

func (h *HeurekaApp) AddComponentVersionToIssue(issueId, componentVersionId int64) (*entity.Issue, error) {
l := logrus.WithFields(logrus.Fields{
"event": "app.AddComponentVersionToIssue",
"id": issueId,
})

err := h.database.AddComponentVersionToIssue(issueId, componentVersionId)

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while adding component version to issue.")
}

return h.GetIssue(issueId)
}

func (h *HeurekaApp) RemoveComponentVersionFromIssue(issueId, componentVersionId int64) (*entity.Issue, error) {
l := logrus.WithFields(logrus.Fields{
"event": "app.RemoveComponentVersionFromIssue",
"id": issueId,
})

err := h.database.RemoveComponentVersionFromIssue(issueId, componentVersionId)

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while removing component version from issue.")
}

return h.GetIssue(issueId)
}
Loading

0 comments on commit 8ce2f55

Please sign in to comment.