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

dev #102

Merged
merged 3 commits into from
Jan 31, 2022
Merged

dev #102

Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<a href="https://github.com/ctreminiom/go-atlassian/actions?query=workflow%3ATesting"><img src="https://img.shields.io/github/workflow/status/ctreminiom/go-atlassian/Testing?label=%F0%9F%A7%AA%20tests&style=flat&color=75C46B"></a>
<a href="https://docs.go-atlassian.io/"><img src="https://img.shields.io/badge/%F0%9F%92%A1%20go-documentation-00ACD7.svg?style=flat"></a>
<a href="https://bestpractices.coreinfrastructure.org/projects/4861"><img src="https://bestpractices.coreinfrastructure.org/projects/4861/badge"></a>
<a href="https://github.com/avelino/awesome-go#third-party-apis"><img src="https://awesome.re/mentioned-badge-flat.svg"></a>
</p>

Communicate with the [Atlassian API's](https://developer.atlassian.com/cloud/) quickly and easily
Expand Down
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