Skip to content

Commit

Permalink
Merge pull request #26 from ConductorOne/scott/add-new-status-api
Browse files Browse the repository at this point in the history
Add new status API for jira datacenter
  • Loading branch information
ButternCream authored Aug 1, 2024
2 parents 5ab5018 + 844f04a commit 7cf3499
Show file tree
Hide file tree
Showing 46 changed files with 155 additions and 80 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/conductorone/baton-jira-datacenter
go 1.22.2

require (
github.com/andygrunwald/go-jira/v2 v2.0.0-20240419124508-6752705de4c7
github.com/conductorone/baton-sdk v0.2.13
github.com/conductorone/go-jira/v2 v2.0.0-20240730210232-f451d98f0fdb
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
go.uber.org/zap v1.27.0
google.golang.org/protobuf v1.34.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/andygrunwald/go-jira/v2 v2.0.0-20240419124508-6752705de4c7 h1:FYIM+f7fL+ji6i+wo8jmP1jS4cSnGjBQ2HAzmXL/BkM=
github.com/andygrunwald/go-jira/v2 v2.0.0-20240419124508-6752705de4c7/go.mod h1:ZqySL3V+2YaH61NHTM9ZDOLpAXvS2KgbxCmVXOBpwv0=
github.com/aws/aws-sdk-go-v2 v1.27.0 h1:7bZWKoXhzI+mMR/HjdMx8ZCC5+6fY0lS5tr0bbgiLlo=
github.com/aws/aws-sdk-go-v2 v1.27.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
Expand Down Expand Up @@ -54,6 +52,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/conductorone/baton-sdk v0.2.13 h1:/9wJGlbiPxDQmjqKOTqyKpJ1Ui2+o7oYHInMqqR1PyQ=
github.com/conductorone/baton-sdk v0.2.13/go.mod h1:cg5FyUcJnD7xK5SPbHe/KNpwUVVlpHJ9rnmd3UwxSkU=
github.com/conductorone/go-jira/v2 v2.0.0-20240730210232-f451d98f0fdb h1:/Hq65KWucwOsT0IB6sddPGwFLPypWh/NUcxX8wWYF+M=
github.com/conductorone/go-jira/v2 v2.0.0-20240730210232-f451d98f0fdb/go.mod h1:eMJODGFmHWC1egXOWdPaYfiACqNcHaS5Cnf1VMHVRBU=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/url"
"slices"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
"github.com/conductorone/baton-sdk/pkg/uhttp"
jira "github.com/conductorone/go-jira/v2/onpremise"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"context"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
jira "github.com/conductorone/go-jira/v2/onpremise"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
)
Expand Down
28 changes: 27 additions & 1 deletion pkg/client/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
jira "github.com/conductorone/go-jira/v2/onpremise"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -63,3 +63,29 @@ func (c *Client) ListStatuses(ctx context.Context) ([]*jira.Status, error) {

return ret, nil
}

func (c *Client) ListStatusesForProject(ctx context.Context, projectID string) ([]*jira.Status, error) {
l := ctxzap.Extract(ctx)

if projectID == "" {
return nil, errors.New("projectID is required")
}

statuses, _, err := c.client.Status.GetStatusesPaginated(ctx, &jira.StatusSearchOptions{
ProjectIDs: []string{projectID},
})
if err != nil {
l.Error("error getting statuses for project", zap.Error(err))
return nil, err
}

ret := make([]*jira.Status, 0, len(statuses))
for _, status := range statuses {
if status.StatusCategory.Key == "done" {
status := status
ret = append(ret, &status)
}
}

return ret, nil
}
7 changes: 3 additions & 4 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import (
)

type Connector struct {
jiraClient *client.Client
ticketSchemas map[string]*v2.TicketSchema
ticketStatuses []*v2.TicketStatus
projectKeys []string
jiraClient *client.Client
ticketSchemas map[string]*v2.TicketSchema
projectKeys []string
}

// ResourceSyncers returns a ResourceSyncer for each resource type that should be synced from the upstream service.
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/internal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"strconv"
"testing"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
"github.com/conductorone/baton-jira-datacenter/pkg/client"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/pagination"
ent "github.com/conductorone/baton-sdk/pkg/types/entitlement"
"github.com/conductorone/baton-sdk/pkg/types/grant"
jira "github.com/conductorone/go-jira/v2/onpremise"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"net/http"
"strconv"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/pagination"
"github.com/conductorone/baton-sdk/pkg/types/grant"
sdkResource "github.com/conductorone/baton-sdk/pkg/types/resource"
jira "github.com/conductorone/go-jira/v2/onpremise"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
"golang.org/x/exp/slices"
Expand Down
23 changes: 5 additions & 18 deletions pkg/connector/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"path"
"time"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/pagination"
sdkTicket "github.com/conductorone/baton-sdk/pkg/types/ticket"
jira "github.com/conductorone/go-jira/v2/onpremise"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -61,12 +61,8 @@ func (d *Connector) ListTicketSchemas(ctx context.Context, pToken *pagination.To
return ret, "", nil, nil
}

func (d *Connector) getTicketStatuses(ctx context.Context) ([]*v2.TicketStatus, error) {
if d.ticketStatuses != nil {
return d.ticketStatuses, nil
}

statuses, err := d.jiraClient.ListStatuses(ctx)
func (d *Connector) getTicketStatuses(ctx context.Context, projectId string) ([]*v2.TicketStatus, error) {
statuses, err := d.jiraClient.ListStatusesForProject(ctx, projectId)
if err != nil {
return nil, err
}
Expand All @@ -79,8 +75,6 @@ func (d *Connector) getTicketStatuses(ctx context.Context) ([]*v2.TicketStatus,
})
}

d.ticketStatuses = ret

return ret, nil
}

Expand Down Expand Up @@ -152,7 +146,7 @@ func (d *Connector) schemaForProject(ctx context.Context, project *jira.Project)
CustomFields: customFields,
}

statuses, err := d.getTicketStatuses(ctx)
statuses, err := d.getTicketStatuses(ctx, project.ID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -251,14 +245,6 @@ func (d *Connector) issueToTicket(ctx context.Context, issue *jira.Issue) (*v2.T
}
ret.CustomFields = retCustomFields

valid, err := sdkTicket.ValidateTicket(ctx, schema, ret)
if err != nil {
return nil, err
}
if !valid {
return nil, errors.New("ticket is invalid")
}

return ret, nil
}
func (d *Connector) GetTicket(ctx context.Context, ticketId string) (*v2.Ticket, annotations.Annotations, error) {
Expand Down Expand Up @@ -325,6 +311,7 @@ func (d *Connector) CreateTicket(ctx context.Context, ticket *v2.Ticket, schema
if err != nil {
return nil, nil, err
}

ticketOptions = append(ticketOptions, client.WithType(issueType.GetId()))
default:
val, err := sdkTicket.GetCustomFieldValue(ticketFields[id])
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package connector
import (
"context"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/pagination"
sdkResource "github.com/conductorone/baton-sdk/pkg/types/resource"
jira "github.com/conductorone/go-jira/v2/onpremise"

"github.com/conductorone/baton-jira-datacenter/pkg/client"
)
Expand Down
46 changes: 0 additions & 46 deletions vendor/github.com/andygrunwald/go-jira/v2/onpremise/status.go

This file was deleted.

109 changes: 109 additions & 0 deletions vendor/github.com/conductorone/go-jira/v2/onpremise/status.go

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

6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ filippo.io/age/internal/stream
## explicit; go 1.20
filippo.io/edwards25519
filippo.io/edwards25519/field
# github.com/andygrunwald/go-jira/v2 v2.0.0-20240419124508-6752705de4c7
## explicit; go 1.18
github.com/andygrunwald/go-jira/v2/onpremise
# github.com/aws/aws-sdk-go-v2 v1.27.0
## explicit; go 1.20
github.com/aws/aws-sdk-go-v2/aws
Expand Down Expand Up @@ -189,6 +186,9 @@ github.com/conductorone/baton-sdk/pkg/ugrpc
github.com/conductorone/baton-sdk/pkg/uhttp
github.com/conductorone/baton-sdk/pkg/us3
github.com/conductorone/baton-sdk/pkg/utls
# github.com/conductorone/go-jira/v2 v2.0.0-20240730210232-f451d98f0fdb
## explicit; go 1.22
github.com/conductorone/go-jira/v2/onpremise
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
Expand Down

0 comments on commit 7cf3499

Please sign in to comment.