Repository: amp-labs/connectors
Pull request #1324 (2025-02-03 23:39:25)

[CON-1034] fix(Atlassian): ReadResult.Raw
# Testing
List Jira `Issues`:
![image](https://github.com/user-attachments/assets/0637026e-3e7b-4025-9aa5-c2036720c54e)
![image](https://github.com/user-attachments/assets/f19ff031-4e35-415e-8a27-c6947913635e)



Cobalt0s: > [!WARNING]
> <b>This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1324?utm_source=stack-comment-downstack-mergeability-warning" >on Graphite</a>.</b>
> <a href="https://graphite.dev/docs/merge-pull-requests">Learn more</a>

* **#1324** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1324?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a> 👈 <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1324?utm_source=stack-comment-view-in-graphite" target="_blank">(View in Graphite)</a>
* **#1321** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1321?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>: 1 other dependent PR ([#1320](https://github.com/amp-labs/connectors/pull/1320) <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1320?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>)
* `main`


<h2></h2>

This stack of pull requests is managed by <a href="https://graphite.dev?utm-source=stack-comment"><b>Graphite</b></a>. Learn more about <a href="https://stacking.dev/?utm_source=stack-comment">stacking</a>.
<!-- Current dependencies on/for this PR: -->

Patch:
diff --git a/providers/atlassian/parse.go b/providers/atlassian/parse.go
index 663a08ac..e1a207b2 100644
--- a/providers/atlassian/parse.go
+++ b/providers/atlassian/parse.go
@@ -30,36 +30,30 @@ Visual example of what will happen to each property:
 		}
 	}
 */
-func getRecords(node *ajson.Node) ([]map[string]any, error) {
-	arr, err := jsonquery.New(node).ArrayRequired("issues")
+func flattenRecord(item *ajson.Node) (map[string]any, error) {
+	fieldsObject, err := jsonquery.New(item).ObjectRequired("fields")
 	if err != nil {
-		return nil, err
+		return nil, errors.Join(common.ErrParseError, err)
 	}
 
-	list := make([]map[string]any, len(arr))
-
-	for index, item := range arr {
-		fieldsObject, err := jsonquery.New(item).ObjectRequired("fields")
-		if err != nil {
-			return nil, errors.Join(common.ErrParseError, err)
-		}
+	fields, err := jsonquery.Convertor.ObjectToMap(fieldsObject)
+	if err != nil {
+		return nil, errors.Join(common.ErrParseError, err)
+	}
 
-		fields, err := jsonquery.Convertor.ObjectToMap(fieldsObject)
-		if err != nil {
-			return nil, errors.Join(common.ErrParseError, err)
-		}
+	id, err := jsonquery.New(item).StringRequired("id")
+	if err != nil {
+		return nil, errors.Join(common.ErrParseError, err)
+	}
 
-		id, err := jsonquery.New(item).StringRequired("id")
-		if err != nil {
-			return nil, errors.Join(common.ErrParseError, err)
-		}
+	// Enhance response with id property.
+	fields["id"] = id
 
-		// Enhance response with id property.
-		fields["id"] = id
-		list[index] = fields
-	}
+	return fields, nil
+}
 
-	return list, nil
+func getRecords(node *ajson.Node) ([]*ajson.Node, error) {
+	return jsonquery.New(node).ArrayRequired("issues")
 }
 
 // Next starting page index is calculated base on current index and array size.
diff --git a/providers/atlassian/read.go b/providers/atlassian/read.go
index 491007a2..eccc1032 100644
--- a/providers/atlassian/read.go
+++ b/providers/atlassian/read.go
@@ -33,7 +33,7 @@ func (c *Connector) Read(ctx context.Context, config common.ReadParams) (*common
 		rsp,
 		getRecords,
 		getNextRecords,
-		common.GetMarshaledData,
+		common.MakeMarshaledDataFunc(flattenRecord),
 		config.Fields,
 	)
 }


Test patch:
diff --git a/providers/atlassian/read_test.go b/providers/atlassian/read_test.go
index 5c060cf4..98ca067b 100644
--- a/providers/atlassian/read_test.go
+++ b/providers/atlassian/read_test.go
@@ -228,10 +228,8 @@ func TestRead(t *testing.T) { //nolint:funlen,gocognit,cyclop,maintidx
 						"summary": "Another one",
 					},
 					Raw: map[string]any{
-						"id":                       "10001",
-						"description":              nil,
-						"created":                  "2024-07-22T22:41:48.474+0300",
-						"statuscategorychangedate": "2024-07-22T22:41:48.686+0300",
+						"id":  "10001",
+						"key": "AM-2",
 					},
 				}, {
 					Fields: map[string]any{
@@ -239,10 +237,8 @@ func TestRead(t *testing.T) { //nolint:funlen,gocognit,cyclop,maintidx
 						"summary": "First Issue on Jira",
 					},
 					Raw: map[string]any{
-						"id":                       "10000",
-						"description":              nil,
-						"created":                  "2024-07-22T22:41:35.069+0300",
-						"statuscategorychangedate": "2024-07-22T22:41:35.326+0300",
+						"id":  "10000",
+						"key": "AM-1",
 					},
 				}},
 				NextPage: "2",
diff --git a/test/atlassian/connector.go b/test/atlassian/connector.go
index b65aaabd..9dc6fb32 100644
--- a/test/atlassian/connector.go
+++ b/test/atlassian/connector.go
@@ -12,7 +12,7 @@ import (
 	"golang.org/x/oauth2"
 )
 
-const cloudId = "ebc887b2-7e61-4059-ab35-71f15cc16e12"
+const cloudId = "35745fff-f0de-466c-b08e-a63f69888611"
 
 func GetAtlassianConnector(ctx context.Context) *atlassian.Connector {
 	filePath := credscanning.LoadPath(providers.Atlassian)
@@ -25,6 +25,7 @@ func GetAtlassianConnector(ctx context.Context) *atlassian.Connector {
 		atlassian.WithMetadata(map[string]string{
 			// This value can be obtained by following this API reference.
 			// https://developer.atlassian.com/cloud/confluence/oauth-2-3lo-apps/#3-1-get-the-cloudid-for-your-site
+			// Another simplest solution is to run `connectors/test/atlassian/auth-metadata/main.go` script.
 			"cloudId": cloudId,
 		}),
 	)
diff --git a/test/atlassian/read/main.go b/test/atlassian/read/main.go
index a56f7e55..acf44a3a 100644
--- a/test/atlassian/read/main.go
+++ b/test/atlassian/read/main.go
@@ -24,7 +24,8 @@ func main() {
 	conn := connTest.GetAtlassianConnector(ctx)
 
 	res, err := conn.Read(ctx, common.ReadParams{
-		Fields: connectors.Fields("id", "summary", "status"),
+		ObjectName: "issues",
+		Fields:     connectors.Fields("id", "summary", "status"),
 		// Below is the example to get issues that were updated in the last 15 min.
 		// Since: time.Now().Add(-15 * time.Minute),
 	})