Repository: ctreminiom/go-atlassian
Pull request #169 (2022-12-26 21:10:18)

🧱 Added more parameters on the ProjectParamsScheme


Patch:
diff --git a/jira/internal/project_impl.go b/jira/internal/project_impl.go
index bd27592..c873db6 100644
--- a/jira/internal/project_impl.go
+++ b/jira/internal/project_impl.go
@@ -201,6 +201,18 @@ func (i *internalProjectImpl) Search(ctx context.Context, options *model.Project
 			params.Add("expand", strings.Join(options.Expand, ","))
 		}
 
+		if len(options.IDs) != 0 {
+			for _, id := range options.IDs {
+				params.Add("id", strconv.Itoa(id))
+			}
+		}
+
+		if len(options.Keys) != 0 {
+			for _, key := range options.Keys {
+				params.Add("keys", key)
+			}
+		}
+
 		if len(options.OrderBy) != 0 {
 			params.Add("orderBy", options.OrderBy)
 		}
@@ -209,8 +221,8 @@ func (i *internalProjectImpl) Search(ctx context.Context, options *model.Project
 			params.Add("query", options.Query)
 		}
 
-		if len(options.ProjectKeyType) != 0 {
-			params.Add("typeKey", options.ProjectKeyType)
+		if len(options.TypeKeys) != 0 {
+			params.Add("typeKey", strings.Join(options.TypeKeys, ","))
 		}
 
 		if options.CategoryID != 0 {
@@ -220,6 +232,14 @@ func (i *internalProjectImpl) Search(ctx context.Context, options *model.Project
 		if len(options.Action) != 0 {
 			params.Add("action", options.Action)
 		}
+
+		if len(options.Status) != 0 {
+			params.Add("status", strings.Join(options.Status, ","))
+		}
+
+		if len(options.Properties) != 0 {
+			params.Add("properties", strings.Join(options.Properties, ","))
+		}
 	}
 
 	endpoint := fmt.Sprintf("rest/api/%v/project/search?%v", i.version, params.Encode())
diff --git a/pkg/infra/models/confluence_content.go b/pkg/infra/models/confluence_content.go
index 1f52d8a..f8f11f1 100644
--- a/pkg/infra/models/confluence_content.go
+++ b/pkg/infra/models/confluence_content.go
@@ -58,12 +58,12 @@ type ContentExtensionScheme struct {
 }
 
 type BodyScheme struct {
-	View                *BodyNodeScheme `json:"view"`
-	ExportView          *BodyNodeScheme `json:"export_view"`
-	StyledView          *BodyNodeScheme `json:"styled_view"`
-	Storage             *BodyNodeScheme `json:"storage"`
-	Editor2             *BodyNodeScheme `json:"editor2"`
-	AnonymousExportView *BodyNodeScheme `json:"anonymous_export_view"`
+	View                *BodyNodeScheme `json:"view,omitempty"`
+	ExportView          *BodyNodeScheme `json:"export_view,omitempty"`
+	StyledView          *BodyNodeScheme `json:"styled_view,omitempty"`
+	Storage             *BodyNodeScheme `json:"storage,omitempty"`
+	Editor2             *BodyNodeScheme `json:"editor2,omitempty"`
+	AnonymousExportView *BodyNodeScheme `json:"anonymous_export_view,omitempty"`
 }
 
 type BodyNodeScheme struct {
diff --git a/pkg/infra/models/jira_project.go b/pkg/infra/models/jira_project.go
index be73ac5..34ae699 100644
--- a/pkg/infra/models/jira_project.go
+++ b/pkg/infra/models/jira_project.go
@@ -41,12 +41,51 @@ type NewProjectCreatedScheme struct {
 }
 
 type ProjectSearchOptionsScheme struct {
-	OrderBy        string
-	Query          string
-	Action         string
-	ProjectKeyType string
-	CategoryID     int
-	Expand         []string
+	OrderBy string
+
+	// The project IDs to filter the results by.
+	// To include multiple IDs, provide an ampersand-separated list.
+	IDs []int
+
+	// The project keys to filter the results by.
+	// To include multiple keys, provide an ampersand-separated list.
+	Keys []string
+
+	// Filter the results using a literal string.
+	// Projects with a matching key or name are returned (case-insensitive).
+	Query string
+
+	// Orders results by the project type.
+	// This parameter accepts a comma-separated list.
+	// Valid values are business, service_desk, and software.
+	TypeKeys []string
+
+	// The ID of the project's category.
+	// A complete list of category IDs is found using the Get all project categories operation.
+	CategoryID int
+
+	Action string
+
+	// EXPERIMENTAL. Filter results by project status:
+	// 1. live: Search live projects.
+	// 2. archived: Search archived projects.
+	// 3. deleted: Search deleted projects, those in the recycle bin.
+	Status []string
+
+	// Use expand to include additional information in the response.
+	// This parameter accepts a comma-separated list.
+	Expand []string
+
+	// EXPERIMENTAL. A list of project properties to return for the project.
+	// This parameter accepts a comma-separated list.
+	Properties []string
+
+	// EXPERIMENTAL. A query string used to search properties.
+	// The query string cannot be specified using a JSON object.
+	// For example, to search for the value of nested from {"something":{"nested":1,"other":2}}
+	// use [thepropertykey].something.nested=1.
+	// Note that thepropertykey is only returned when included in properties.
+	PropertyQuery string
 }
 
 type ProjectSearchScheme struct {


Test patch:
diff --git a/jira/internal/project_impl_test.go b/jira/internal/project_impl_test.go
index a5c65a8..da64c45 100644
--- a/jira/internal/project_impl_test.go
+++ b/jira/internal/project_impl_test.go
@@ -177,6 +177,20 @@ func Test_internalProjectImpl_Create(t *testing.T) {
 
 func Test_internalProjectImpl_Search(t *testing.T) {
 
+	mockedParams := &model.ProjectSearchOptionsScheme{
+		OrderBy:       "category",
+		IDs:           []int{10000, 10001},
+		Keys:          []string{"PA", "PB"},
+		Query:         "ADM",
+		TypeKeys:      []string{"business", "service_desk"},
+		CategoryID:    48882,
+		Action:        "view",
+		Status:        []string{"live", "archived"},
+		Expand:        []string{"description"},
+		Properties:    []string{"data.is.completed?"},
+		PropertyQuery: "[thepropertykey].something.nested=1",
+	}
+
 	type fields struct {
 		c       service.Client
 		version string
@@ -200,15 +214,8 @@ func Test_internalProjectImpl_Search(t *testing.T) {
 			name:   "when the api version is v3",
 			fields: fields{version: "3"},
 			args: args{
-				ctx: context.TODO(),
-				options: &model.ProjectSearchOptionsScheme{
-					OrderBy:        "category",
-					Query:          "dummy project",
-					Action:         "view",
-					ProjectKeyType: "[thepropertykey].something.nested=1",
-					CategoryID:     400,
-					Expand:         []string{"description", "projectKeys"},
-				},
+				ctx:        context.TODO(),
+				options:    mockedParams,
 				startAt:    0,
 				maxResults: 50,
 			},
@@ -219,7 +226,7 @@ func Test_internalProjectImpl_Search(t *testing.T) {
 				client.On("NewRequest",
 					context.Background(),
 					http.MethodGet,
-					"rest/api/3/project/search?action=view&categoryId=400&expand=description%2CprojectKeys&maxResults=50&orderBy=category&query=dummy+project&startAt=0&typeKey=%5Bthepropertykey%5D.something.nested%3D1",
+					"rest/api/3/project/search?action=view&categoryId=48882&expand=description&id=10000&id=10001&keys=PA&keys=PB&maxResults=50&orderBy=category&properties=data.is.completed%3F&query=ADM&startAt=0&status=live%2Carchived&typeKey=business%2Cservice_desk",
 					nil).
 					Return(&http.Request{}, nil)
 
@@ -238,15 +245,8 @@ func Test_internalProjectImpl_Search(t *testing.T) {
 			name:   "when the api version is v2",
 			fields: fields{version: "2"},
 			args: args{
-				ctx: context.TODO(),
-				options: &model.ProjectSearchOptionsScheme{
-					OrderBy:        "category",
-					Query:          "dummy project",
-					Action:         "view",
-					ProjectKeyType: "[thepropertykey].something.nested=1",
-					CategoryID:     400,
-					Expand:         []string{"description", "projectKeys"},
-				},
+				ctx:        context.TODO(),
+				options:    mockedParams,
 				startAt:    0,
 				maxResults: 50,
 			},
@@ -257,7 +257,7 @@ func Test_internalProjectImpl_Search(t *testing.T) {
 				client.On("NewRequest",
 					context.Background(),
 					http.MethodGet,
-					"rest/api/2/project/search?action=view&categoryId=400&expand=description%2CprojectKeys&maxResults=50&orderBy=category&query=dummy+project&startAt=0&typeKey=%5Bthepropertykey%5D.something.nested%3D1",
+					"rest/api/2/project/search?action=view&categoryId=48882&expand=description&id=10000&id=10001&keys=PA&keys=PB&maxResults=50&orderBy=category&properties=data.is.completed%3F&query=ADM&startAt=0&status=live%2Carchived&typeKey=business%2Cservice_desk",
 					nil).
 					Return(&http.Request{}, nil)
 
@@ -276,15 +276,8 @@ func Test_internalProjectImpl_Search(t *testing.T) {
 			name:   "when the http request cannot be created",
 			fields: fields{version: "3"},
 			args: args{
-				ctx: context.TODO(),
-				options: &model.ProjectSearchOptionsScheme{
-					OrderBy:        "category",
-					Query:          "dummy project",
-					Action:         "view",
-					ProjectKeyType: "[thepropertykey].something.nested=1",
-					CategoryID:     400,
-					Expand:         []string{"description", "projectKeys"},
-				},
+				ctx:        context.TODO(),
+				options:    mockedParams,
 				startAt:    0,
 				maxResults: 50,
 			},
@@ -295,7 +288,7 @@ func Test_internalProjectImpl_Search(t *testing.T) {
 				client.On("NewRequest",
 					context.Background(),
 					http.MethodGet,
-					"rest/api/3/project/search?action=view&categoryId=400&expand=description%2CprojectKeys&maxResults=50&orderBy=category&query=dummy+project&startAt=0&typeKey=%5Bthepropertykey%5D.something.nested%3D1",
+					"rest/api/3/project/search?action=view&categoryId=48882&expand=description&id=10000&id=10001&keys=PA&keys=PB&maxResults=50&orderBy=category&properties=data.is.completed%3F&query=ADM&startAt=0&status=live%2Carchived&typeKey=business%2Cservice_desk",
 					nil).
 					Return(&http.Request{}, errors.New("error, unable to create the http request"))