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 #22

Merged
merged 22 commits into from Apr 13, 2021
Merged

Dev #22

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ab796af
:label: Changed the types from From and To values from string to time…
ctreminiom Apr 10, 2021
c7548f3
:recycle: refactor DashboardService with the correct struct types and…
ctreminiom Apr 11, 2021
1639aa8
:recycle: refactor ApplicationRoleService with the correct struct typ…
ctreminiom Apr 11, 2021
9b01ccc
:recycle: refactor FilterService with the correct struct types, added…
ctreminiom Apr 11, 2021
f85954e
:recycle: refactor FilterShareService with the correct struct types, …
ctreminiom Apr 11, 2021
ad490e9
:recycle: refactor GroupService with the correct struct types
ctreminiom Apr 11, 2021
0dfc7c7
:recycle: refactor IssueService with the correct struct types and exa…
ctreminiom Apr 11, 2021
823163e
:white_check_mark: Increased the code coverage on the issueService
ctreminiom Apr 12, 2021
d8bcaa4
:recycle: refactor IssueCommentService with the correct struct types …
ctreminiom Apr 12, 2021
664307c
:recycle: refactor IssueFieldService with the correct struct types an…
ctreminiom Apr 12, 2021
477cf41
:recycle: refactor IssueFieldConfigurationService with the correct st…
ctreminiom Apr 13, 2021
b26e051
:recycle: refactor IssueFieldContextService with the correct struct t…
ctreminiom Apr 13, 2021
abf5e0c
:recycle: refactor IssueFieldContextOptionService with the correct st…
ctreminiom Apr 13, 2021
fab2c73
:recycle: refactor IssueLinkService with the correct struct types and…
ctreminiom Apr 13, 2021
5d3644b
:recycle: refactor IssueLinkTypeService with the correct struct types…
ctreminiom Apr 13, 2021
9a97dda
:white_check_mark: Increased the code coverage on the IssuePrioritySe…
ctreminiom Apr 13, 2021
b68947f
:white_check_mark: Increased the code coverage on the IssueResolution…
ctreminiom Apr 13, 2021
6240688
:recycle: refactor IssueSearchService with the correct struct types a…
ctreminiom Apr 13, 2021
e80e7b4
:recycle: refactor IssueSearchService with the correct struct types a…
ctreminiom Apr 13, 2021
a1d4306
:recycle: refactor IssueTypeService with the correct struct types and…
ctreminiom Apr 13, 2021
cda4f31
:recycle: refactor IssueTypeSchemeService with the correct struct typ…
ctreminiom Apr 13, 2021
59a51db
:recycle: refactor IssueTypeScreenSchemeService with the correct stru…
ctreminiom Apr 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions jira/applicationRole.go
Expand Up @@ -7,6 +7,9 @@ import (
"net/http"
)

// This service represents the Jira Cloud application roles
// Use it to get details of an application role or all application roles.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/application-roles
type ApplicationRoleService struct{ client *Client }

type ApplicationRoleScheme struct {
Expand All @@ -24,8 +27,9 @@ type ApplicationRoleScheme struct {
Platform bool `json:"platform,omitempty"`
}

// Returns all application roles.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/application-roles#application-roles
// Returns all application roles, this func needs the following parameters:
// 1. ctx = it's the context.context value
// Docs: https://docs.go-atlassian.io/jira-software-cloud/application-roles#get-all-application-roles
func (a *ApplicationRoleService) Gets(ctx context.Context) (result *[]ApplicationRoleScheme, response *Response, err error) {

var endpoint = "rest/api/3/applicationrole"
Expand All @@ -49,8 +53,10 @@ func (a *ApplicationRoleService) Gets(ctx context.Context) (result *[]Applicatio
return
}

// Returns an application role.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/application-roles#application-role
// Returns an application role, this func needs the following parameters:
// 1. ctx = it's the context.context value
// 2. key = The key of the application role, use Gets() method to get the key for each application role.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/application-roles#get-application-role
func (a *ApplicationRoleService) Get(ctx context.Context, key string) (result *ApplicationRoleScheme, response *Response, err error) {

if len(key) == 0 {
Expand Down
2 changes: 2 additions & 0 deletions jira/applicationRole_test.go
Expand Up @@ -85,7 +85,9 @@ func TestApplicationRoleService_Gets(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

//Init a new HTTP mock server
mockOptions := mockServerOptions{
Expand Down
90 changes: 49 additions & 41 deletions jira/audit.go
Expand Up @@ -7,54 +7,62 @@ import (
"net/http"
"net/url"
"strconv"
"time"
)

type AuditService struct{ client *Client }

type AuditRecordPageScheme struct {
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
Total int `json:"total,omitempty"`
Records []*AuditRecordScheme `json:"records,omitempty"`
}

type AuditRecordScheme struct {
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
Total int `json:"total,omitempty"`
Records []struct {
ID int `json:"id,omitempty"`
Summary string `json:"summary,omitempty"`
RemoteAddress string `json:"remoteAddress,omitempty"`
AuthorKey string `json:"authorKey,omitempty"`
Created string `json:"created,omitempty"`
Category string `json:"category,omitempty"`
EventSource string `json:"eventSource,omitempty"`
Description string `json:"description,omitempty"`
ObjectItem struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TypeName string `json:"typeName,omitempty"`
ParentID string `json:"parentId,omitempty"`
ParentName string `json:"parentName,omitempty"`
} `json:"objectItem,omitempty"`
ChangedValues []struct {
FieldName string `json:"fieldName,omitempty"`
ChangedFrom string `json:"changedFrom,omitempty"`
ChangedTo string `json:"changedTo,omitempty"`
} `json:"changedValues,omitempty"`
AssociatedItems []struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TypeName string `json:"typeName,omitempty"`
ParentID string `json:"parentId,omitempty"`
ParentName string `json:"parentName,omitempty"`
} `json:"associatedItems,omitempty"`
} `json:"records,omitempty"`
ID int `json:"id,omitempty"`
Summary string `json:"summary,omitempty"`
RemoteAddress string `json:"remoteAddress,omitempty"`
AuthorKey string `json:"authorKey,omitempty"`
Created string `json:"created,omitempty"`
Category string `json:"category,omitempty"`
EventSource string `json:"eventSource,omitempty"`
Description string `json:"description,omitempty"`
ObjectItem *AuditRecordObjectItemScheme `json:"objectItem,omitempty"`
ChangedValues []*AuditRecordChangedValueScheme `json:"changedValues,omitempty"`
AssociatedItems []*AuditRecordAssociatedItemScheme `json:"associatedItems,omitempty"`
}

type AuditRecordObjectItemScheme struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TypeName string `json:"typeName,omitempty"`
ParentID string `json:"parentId,omitempty"`
ParentName string `json:"parentName,omitempty"`
}

type AuditRecordChangedValueScheme struct {
FieldName string `json:"fieldName,omitempty"`
ChangedFrom string `json:"changedFrom,omitempty"`
ChangedTo string `json:"changedTo,omitempty"`
}

type AuditRecordAssociatedItemScheme struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
TypeName string `json:"typeName,omitempty"`
ParentID string `json:"parentId,omitempty"`
ParentName string `json:"parentName,omitempty"`
}

type AuditRecordGetOptions struct {
Filter string
From string
To string
Filter string
From, To time.Time
}

// Returns a list of audit records. The list can be filtered to include items:
// Docs: https://docs.go-atlassian.io/jira-software-cloud/audit-records#get-audit-records
func (a *AuditService) Get(ctx context.Context, options *AuditRecordGetOptions, offset, limit int) (result *AuditRecordScheme, response *Response, err error) {
func (a *AuditService) Get(ctx context.Context, options *AuditRecordGetOptions, offset, limit int) (result *AuditRecordPageScheme, response *Response, err error) {

params := url.Values{}
params.Add("offset", strconv.Itoa(offset))
Expand All @@ -66,12 +74,12 @@ func (a *AuditService) Get(ctx context.Context, options *AuditRecordGetOptions,
params.Add("filter", options.Filter)
}

if len(options.From) != 0 {
params.Add("from", options.From)
if !options.From.IsZero() {
params.Add("from", options.From.Format(DateFormatJira))
}

if len(options.To) != 0 {
params.Add("to", options.To)
if !options.To.IsZero() {
params.Add("to", options.To.Format(DateFormatJira))
}
}

Expand All @@ -88,7 +96,7 @@ func (a *AuditService) Get(ctx context.Context, options *AuditRecordGetOptions,
return
}

result = new(AuditRecordScheme)
result = new(AuditRecordPageScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return
}
Expand Down
32 changes: 16 additions & 16 deletions jira/audit_test.go
Expand Up @@ -34,8 +34,8 @@ func TestAuditService_Get(t *testing.T) {
name: "GetAuditRecordsWhenTheOptionsAreSet",
options: &AuditRecordGetOptions{
Filter: "",
From: mockDateTimeAsTime.AddDate(0, -1, 0).Format(DateFormatJira),
To: mockDateTimeAsTime.Format(DateFormatJira),
From: mockDateTimeAsTime.AddDate(0, -1, 0),
To: mockDateTimeAsTime,
},
offset: 0,
limit: 1000,
Expand All @@ -51,8 +51,8 @@ func TestAuditService_Get(t *testing.T) {
name: "GetAuditRecordsWhenTheOptionFilterIsSet",
options: &AuditRecordGetOptions{
Filter: "Workflow",
From: mockDateTimeAsTime.AddDate(0, -1, 0).Format(DateFormatJira),
To: mockDateTimeAsTime.Format(DateFormatJira),
From: mockDateTimeAsTime.AddDate(0, -1, 0),
To: mockDateTimeAsTime,
},
offset: 0,
limit: 1000,
Expand Down Expand Up @@ -81,8 +81,8 @@ func TestAuditService_Get(t *testing.T) {
name: "GetAuditRecordsWhenTheRequestMethodIsIncorrect",
options: &AuditRecordGetOptions{
Filter: "",
From: mockDateTimeAsTime.AddDate(0, -1, 0).Format(DateFormatJira),
To: mockDateTimeAsTime.Format(DateFormatJira),
From: mockDateTimeAsTime.AddDate(0, -1, 0),
To: mockDateTimeAsTime,
},
offset: 0,
limit: 1000,
Expand All @@ -98,8 +98,8 @@ func TestAuditService_Get(t *testing.T) {
name: "GetAuditRecordsWhenTheStatusCodeIsIncorrect",
options: &AuditRecordGetOptions{
Filter: "",
From: mockDateTimeAsTime.AddDate(0, -1, 0).Format(DateFormatJira),
To: mockDateTimeAsTime.Format(DateFormatJira),
From: mockDateTimeAsTime.AddDate(0, -1, 0),
To: mockDateTimeAsTime,
},
offset: 0,
limit: 1000,
Expand All @@ -115,8 +115,8 @@ func TestAuditService_Get(t *testing.T) {
name: "GetAuditRecordsWhenTheContextIsNil",
options: &AuditRecordGetOptions{
Filter: "",
From: mockDateTimeAsTime.AddDate(0, -1, 0).Format(DateFormatJira),
To: mockDateTimeAsTime.Format(DateFormatJira),
From: mockDateTimeAsTime.AddDate(0, -1, 0),
To: mockDateTimeAsTime,
},
offset: 0,
limit: 1000,
Expand All @@ -132,8 +132,8 @@ func TestAuditService_Get(t *testing.T) {
name: "GetAuditRecordsWhenTheEndpointIsIncorrect",
options: &AuditRecordGetOptions{
Filter: "",
From: mockDateTimeAsTime.AddDate(0, -1, 0).Format(DateFormatJira),
To: mockDateTimeAsTime.Format(DateFormatJira),
From: mockDateTimeAsTime.AddDate(0, -1, 0),
To: mockDateTimeAsTime,
},
offset: 0,
limit: 1000,
Expand All @@ -149,8 +149,8 @@ func TestAuditService_Get(t *testing.T) {
name: "GetAuditRecordsWhenTheResponseBodyHasADifferentFormat",
options: &AuditRecordGetOptions{
Filter: "",
From: mockDateTimeAsTime.AddDate(0, -1, 0).Format(DateFormatJira),
To: mockDateTimeAsTime.Format(DateFormatJira),
From: mockDateTimeAsTime.AddDate(0, -1, 0),
To: mockDateTimeAsTime,
},
offset: 0,
limit: 1000,
Expand All @@ -164,9 +164,9 @@ func TestAuditService_Get(t *testing.T) {
}

for _, testCase := range testCases {

testCase := testCase
t.Run(testCase.name, func(t *testing.T) {

t.Parallel()
//Init a new HTTP mock server
mockOptions := mockServerOptions{
Endpoint: testCase.endpoint,
Expand Down
42 changes: 14 additions & 28 deletions jira/dashboard.go
Expand Up @@ -11,11 +11,11 @@ import (

type DashboardService struct{ client *Client }

type DashboardsSchemeResult struct {
StartAt int `json:"startAt,omitempty"`
MaxResults int `json:"maxResults,omitempty"`
Total int `json:"total,omitempty"`
Dashboards []DashboardScheme `json:"dashboards,omitempty"`
type DashboardPageScheme struct {
StartAt int `json:"startAt,omitempty"`
MaxResults int `json:"maxResults,omitempty"`
Total int `json:"total,omitempty"`
Dashboards []*DashboardScheme `json:"dashboards,omitempty"`
}

type DashboardScheme struct {
Expand All @@ -29,8 +29,8 @@ type DashboardScheme struct {
}

// Returns a list of dashboards owned by or shared with the user. The list may be filtered to include only favorite or owned dashboards.
// Docs: https://docs.go-atlassian.io/jira-software-cloud/dashboards#get-dashboards
func (d *DashboardService) Gets(ctx context.Context, startAt, maxResults int, filter string) (result *DashboardsSchemeResult, response *Response, err error) {
// Docs: https://docs.go-atlassian.io/jira-software-cloud/dashboards#get-all-dashboards
func (d *DashboardService) Gets(ctx context.Context, startAt, maxResults int, filter string) (result *DashboardPageScheme, response *Response, err error) {

params := url.Values{}
params.Add("startAt", strconv.Itoa(startAt))
Expand All @@ -51,7 +51,7 @@ func (d *DashboardService) Gets(ctx context.Context, startAt, maxResults int, fi
return
}

result = new(DashboardsSchemeResult)
result = new(DashboardPageScheme)
if err = json.Unmarshal(response.BodyAsBytes, &result); err != nil {
return
}
Expand All @@ -60,26 +60,11 @@ func (d *DashboardService) Gets(ctx context.Context, startAt, maxResults int, fi
}

type SharePermissionScheme struct {
Type string `json:"type"`
Project *SharePermissionProjectScheme `json:"project,omitempty"`
Role *SharePermissionRoleScheme `json:"role,omitempty"`
Group *SharePermissionGroupScheme `json:"group,omitempty"`
}

type SharePermissionProjectScheme struct {
ID string `json:"id,omitempty"`
Email string `json:"email,omitempty"`
Favourite bool `json:"favourite,omitempty"`
}

type SharePermissionRoleScheme struct {
Name string `json:"name,omitempty"`
TranslatedName string `json:"translatedName,omitempty"`
CurrentUserRole bool `json:"currentUserRole,omitempty"`
}

type SharePermissionGroupScheme struct {
Name string `json:"name,omitempty"`
ID int `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Project *ProjectScheme `json:"project,omitempty"`
Role *ProjectRoleScheme `json:"role,omitempty"`
Group *GroupScheme `json:"group,omitempty"`
}

// Creates a dashboard.
Expand Down Expand Up @@ -170,6 +155,7 @@ type DashboardSearchScheme struct {
Self string `json:"self"`
SharePermissions []*SharePermissionScheme `json:"sharePermissions"`
View string `json:"view"`
Rank int `json:"rank"`
} `json:"values"`
}

Expand Down
12 changes: 6 additions & 6 deletions jira/dashboard_test.go
Expand Up @@ -202,14 +202,14 @@ func TestDashboardService_Copy(t *testing.T) {

projectPermission := &SharePermissionScheme{
Type: "project",
Project: &SharePermissionProjectScheme{
Project: &ProjectScheme{
ID: "10000",
},
}

groupPermission := &SharePermissionScheme{
Type: "group",
Group: &SharePermissionGroupScheme{Name: "jira-administrators"},
Group: &GroupScheme{Name: "jira-administrators"},
}

sharePermissionsMocked = append(sharePermissionsMocked, *projectPermission, *groupPermission)
Expand Down Expand Up @@ -453,14 +453,14 @@ func TestDashboardService_Create(t *testing.T) {

projectPermission := &SharePermissionScheme{
Type: "project",
Project: &SharePermissionProjectScheme{
Project: &ProjectScheme{
ID: "10000",
},
}

groupPermission := &SharePermissionScheme{
Type: "group",
Group: &SharePermissionGroupScheme{Name: "jira-administrators"},
Group: &GroupScheme{Name: "jira-administrators"},
}

sharePermissionsMocked = append(sharePermissionsMocked, *projectPermission, *groupPermission)
Expand Down Expand Up @@ -1185,14 +1185,14 @@ func TestDashboardService_Update(t *testing.T) {

projectPermission := &SharePermissionScheme{
Type: "project",
Project: &SharePermissionProjectScheme{
Project: &ProjectScheme{
ID: "10000",
},
}

groupPermission := &SharePermissionScheme{
Type: "group",
Group: &SharePermissionGroupScheme{Name: "jira-administrators"},
Group: &GroupScheme{Name: "jira-administrators"},
}

sharePermissionsMocked = append(sharePermissionsMocked, *projectPermission, *groupPermission)
Expand Down
4 changes: 2 additions & 2 deletions jira/examples/audit-records/get/get.go
Expand Up @@ -30,10 +30,10 @@ func main() {
Filter: "",

//Filter the records by the last month
From: time.Now().AddDate(0, -1, 0).Format(jira.DateFormatJira),
From: time.Now().AddDate(0, -1, 0),

// Today
To: time.Now().Format(jira.DateFormatJira),
To: time.Now(),
}

auditRecords, response, err := jiraCloud.Audit.Get(context.Background(), auditRecordOption, 0, 500)
Expand Down