Skip to content

Commit

Permalink
✨ Added the Jira Project Feature service
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreminiom committed Jan 30, 2022
1 parent 5536973 commit f6049e4
Show file tree
Hide file tree
Showing 11 changed files with 817 additions and 0 deletions.
24 changes: 24 additions & 0 deletions jira/mocks/get-project-features.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"features": [
{
"projectId": 10001,
"state": "ENABLED",
"toggleLocked": true,
"feature": "jsw.classic.roadmap",
"prerequisites": [],
"localisedName": "Roadmap",
"localisedDescription": "Your roadmap is an optimized location to create and manage your epics.",
"imageUri": "https://jira.atlassian.com/s/sb53l8/b/3/ab8a7691e4738b4f147e293f0864adfd5b8d3c85/_/download/resources/com.atlassian.jira.rest:classic-project-features/simple-roadmap-feature.svg"
},
{
"projectId": 10001,
"state": "ENABLED",
"toggleLocked": true,
"feature": "jsw.classic.backlog",
"prerequisites": [],
"localisedName": "Backlog",
"localisedDescription": "Plan and prioritize work in a dedicated space. To enable and configure the backlog for each board, go to board settings.",
"imageUri": "https://jira.atlassian.com/s/sb53l8/b/3/ab8a7691e4738b4f147e293f0864adfd5b8d3c85/_/download/resources/com.atlassian.jira.rest:classic-project-features/simple-backlog-feature.svg"
}
]
}
1 change: 1 addition & 0 deletions jira/v2/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func New(httpClient *http.Client, site string) (client *Client, err error) {

Type: &ProjectTypeService{client: client},
Version: &ProjectVersionService{client: client},
Feature: &ProjectFeatureService{client: client},
}

client.User = &UserService{
Expand Down
1 change: 1 addition & 0 deletions jira/v2/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ProjectService struct {
Role *ProjectRoleService
Type *ProjectTypeService
Version *ProjectVersionService
Feature *ProjectFeatureService
}

// Create creates a project based on a project type template, as shown in the following table:
Expand Down
73 changes: 73 additions & 0 deletions jira/v2/projectFeature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package v2

import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"net/http"
)

type ProjectFeatureService struct{ client *Client }

// Gets returns the list of features for a project.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/projects/features#get-project-features
func (p *ProjectFeatureService) Gets(ctx context.Context, projectKeyOrID string) (result *models.ProjectFeaturesScheme, response *ResponseScheme, err error) {

if projectKeyOrID == "" {
return nil, nil, models.ErrNoProjectIDError
}

var endpoint = fmt.Sprintf("rest/api/2/project/%v/features", projectKeyOrID)

request, err := p.client.newRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return
}

request.Header.Set("Accept", "application/json")

response, err = p.client.call(request, &result)
if err != nil {
return
}

return
}

// Set sets the state of a project feature.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/projects/features#set-project-feature-state
func (p *ProjectFeatureService) Set(ctx context.Context, projectKeyOrID, featureKey, state string) (result *models.ProjectFeaturesScheme, response *ResponseScheme, err error) {

if projectKeyOrID == "" {
return nil, nil, models.ErrNoProjectIDError
}

if featureKey == "" {
return nil, nil, models.ErrNoProjectFeatureKeyError
}

payload := struct {
State string `json:"state,omitempty"`
}{
State: state,
}

payloadAsReader, _ := transformStructToReader(&payload)

var endpoint = fmt.Sprintf("rest/api/2/project/%v/features/%v", projectKeyOrID, featureKey)

request, err := p.client.newRequest(ctx, http.MethodPut, endpoint, payloadAsReader)
if err != nil {
return
}

request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")

response, err = p.client.call(request, &result)
if err != nil {
return
}

return
}
Loading

0 comments on commit f6049e4

Please sign in to comment.