nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jomei/notionapi
Pull request #3 (2021-07-06 00:29:42)

Add Url property to Page struct
Hey there, 
Notion has added a `url` property to the [Page object](https://developers.notion.com/reference/page) and I tried to add it to the Page struct.

I'm very new to Go so please tell me if there's any mistakes.


Patch:
diff --git a/page.go b/page.go
index 2b51c99..3a8506f 100644
--- a/page.go
+++ b/page.go
@@ -66,6 +66,7 @@ type Page struct {
 	Archived       bool       `json:"archived"`
 	Properties     Properties `json:"properties"`
 	Parent         Parent     `json:"parent"`
+	URL            string     `json:"url"`
 }
 
 func (p *Page) GetObject() ObjectType {


Test patch:
diff --git a/database_test.go b/database_test.go
index 7969720..8caa19f 100644
--- a/database_test.go
+++ b/database_test.go
@@ -186,6 +186,7 @@ func TestDatabaseClient(t *testing.T) {
 								DatabaseID: "some_id",
 							},
 							Archived: false,
+							URL:      "some_url",
 						},
 					},
 					HasMore:    false,
diff --git a/page_test.go b/page_test.go
index cc47e47..665f753 100644
--- a/page_test.go
+++ b/page_test.go
@@ -40,6 +40,7 @@ func TestPageClient(t *testing.T) {
 						DatabaseID: "some_id",
 					},
 					Archived: false,
+					URL:      "some_url",
 				},
 			},
 			{
@@ -121,6 +122,7 @@ func TestPageClient(t *testing.T) {
 						DatabaseID: "some_id",
 					},
 					Archived: false,
+					URL:      "some_url",
 				},
 			},
 		}
@@ -182,6 +184,7 @@ func TestPageClient(t *testing.T) {
 						DatabaseID: "some_id",
 					},
 					Archived: false,
+					URL:      "some_url",
 				},
 			},
 		}
diff --git a/testdata/database_query.json b/testdata/database_query.json
index 4f72979..3d6ffe5 100644
--- a/testdata/database_query.json
+++ b/testdata/database_query.json
@@ -11,6 +11,7 @@
         "database_id": "some_id"
       },
       "archived": false,
+      "url": "some_url",
       "properties": {
         "Tags": {
           "id": ";s|V",
diff --git a/testdata/page_create.json b/testdata/page_create.json
index 89c9991..bb58193 100644
--- a/testdata/page_create.json
+++ b/testdata/page_create.json
@@ -8,6 +8,7 @@
     "database_id": "some_id"
   },
   "archived": false,
+  "url": "some_url",
   "properties": {
     "Tags": {
       "id": ";s|V",
diff --git a/testdata/page_get.json b/testdata/page_get.json
index 4161536..3a1ff89 100644
--- a/testdata/page_get.json
+++ b/testdata/page_get.json
@@ -8,6 +8,7 @@
     "database_id": "some_id"
   },
   "archived": false,
+  "url": "some_url",
   "properties": {
     "Tags": {
       "id": ";s|V",
diff --git a/testdata/page_update.json b/testdata/page_update.json
index 569a4cf..bc51a45 100644
--- a/testdata/page_update.json
+++ b/testdata/page_update.json
@@ -8,6 +8,7 @@
     "database_id": "some_id"
   },
   "archived": false,
+  "url": "some_url",
   "properties": {
     "Tags": {
       "id": ";s|V",
Repository: jomei/notionapi
Pull request #21 (2021-08-30 10:10:04)

Fix Date object unmarshalling
Notion API can return date from page fields in the form of "yyyy-mm-dd"
if the field configuration does not include time. The resulting string from the API
isn't accepted by the time.RFC3339 format and thus causes an unmarshalling
error.

The present change fixes it by attempting to parse it as such in case
the standard format fails. If it fails again, the error is returned.

jomei: 🔥 🔥 🔥 🔥 

Patch:
diff --git a/object.go b/object.go
index bc09ff2..7877172 100644
--- a/object.go
+++ b/object.go
@@ -1,6 +1,8 @@
 package notionapi
 
-import "time"
+import (
+	"time"
+)
 
 type ObjectType string
 
@@ -73,6 +75,27 @@ func (d Date) MarshalText() ([]byte, error) {
 	return []byte(d.String()), nil
 }
 
+func (d *Date) UnmarshalText(data []byte) error {
+	t, err := time.Parse(time.RFC3339, string(data))
+
+	// Because the API does not distinguish between datetime with a
+	// timezone and dates, we eventually have to try both.
+	if err != nil {
+		if _, ok := err.(*time.ParseError); !ok {
+			return err
+		} else {
+			t, err = time.Parse("2006-01-02", string(data)) // Date
+			if err != nil {
+				// Still cannot parse it, nothing else to try.
+				return err
+			}
+		}
+	}
+
+	*d = Date(t)
+	return nil
+}
+
 type File struct {
 	Name string `json:"name"`
 }


Test patch:
diff --git a/object_test.go b/object_test.go
new file mode 100644
index 0000000..d942573
--- /dev/null
+++ b/object_test.go
@@ -0,0 +1,35 @@
+package notionapi_test
+
+import (
+	"testing"
+
+	"github.com/jomei/notionapi"
+)
+
+func TestDate(t *testing.T) {
+	t.Run(".UnmarshalText", func(t *testing.T) {
+		var d notionapi.Date
+
+		t.Run("OK datetime with timezone", func(t *testing.T) {
+			data := []byte("1987-02-13T00:00:00.000+01:00")
+			err := d.UnmarshalText(data)
+			if err != nil {
+				t.Fatal(err)
+			}
+		})
+		t.Run("OK date", func(t *testing.T) {
+			data := []byte("1985-01-02")
+			err := d.UnmarshalText(data)
+			if err != nil {
+				t.Fatal(err)
+			}
+		})
+		t.Run("NOK", func(t *testing.T) {
+			data := []byte("1985")
+			err := d.UnmarshalText(data)
+			if err == nil {
+				t.Fatalf("expected an error, got none")
+			}
+		})
+	})
+}
Repository: jomei/notionapi
Pull request #54 (2021-12-01 23:11:03)

Add parent and url fields to database type
This adds the parent and url fields to the database struct since the API Reference lists that it has them: https://developers.notion.com/reference/database#all-databases


Patch:
diff --git a/block.go b/block.go
index fc6e2bd..348e89d 100644
--- a/block.go
+++ b/block.go
@@ -141,6 +141,12 @@ type AppendBlockChildrenRequest struct {
 
 type Block interface {
 	GetType() BlockType
+	GetID() BlockID
+	GetObject() ObjectType
+	GetCreatedTime() *time.Time
+	GetLastEditedTime() *time.Time
+	GetHasChildren() bool
+	GetArchived() bool
 }
 
 // BasicBlock defines the common fields of all Notion block types.
@@ -160,6 +166,30 @@ func (b BasicBlock) GetType() BlockType {
 	return b.Type
 }
 
+func (b BasicBlock) GetID() BlockID {
+	return b.ID
+}
+
+func (b BasicBlock) GetObject() ObjectType {
+	return b.Object
+}
+
+func (b BasicBlock) GetCreatedTime() *time.Time {
+	return b.CreatedTime
+}
+
+func (b BasicBlock) GetLastEditedTime() *time.Time {
+	return b.LastEditedTime
+}
+
+func (b BasicBlock) GetHasChildren() bool {
+	return b.HasChildren
+}
+
+func (b BasicBlock) GetArchived() bool {
+	return b.Archived
+}
+
 type ParagraphBlock struct {
 	BasicBlock
 	Paragraph Paragraph `json:"paragraph"`
diff --git a/database.go b/database.go
index a60f657..5d7d73a 100644
--- a/database.go
+++ b/database.go
@@ -110,6 +110,8 @@ type Database struct {
 	CreatedTime    time.Time  `json:"created_time"`
 	LastEditedTime time.Time  `json:"last_edited_time"`
 	Title          []RichText `json:"title"`
+	Parent         Parent     `json:"parent"`
+	URL            string     `json:"url"`
 	// Properties is a map of property configurations that defines what Page.Properties each page of the database can use
 	Properties PropertyConfigs `json:"properties"`
 }


Test patch:
diff --git a/database_test.go b/database_test.go
index f6f3e96..30c2025 100644
--- a/database_test.go
+++ b/database_test.go
@@ -243,6 +243,10 @@ func TestDatabaseClient(t *testing.T) {
 					ID:             "some_id",
 					CreatedTime:    timestamp,
 					LastEditedTime: timestamp,
+					Parent: notionapi.Parent{
+						Type:   "page_id",
+						PageID: "48f8fee9-cd79-4180-bc2f-ec0398253067",
+					},
 					Title: []notionapi.RichText{
 						{
 							Type: notionapi.ObjectTypeText,
@@ -307,6 +311,10 @@ func TestDatabaseClient(t *testing.T) {
 					ID:             "some_id",
 					CreatedTime:    timestamp,
 					LastEditedTime: timestamp,
+					Parent: notionapi.Parent{
+						Type:   "page_id",
+						PageID: "a7744006-9233-4cd0-bf44-3a49de2c01b5",
+					},
 					Title: []notionapi.RichText{
 						{
 							Type:        notionapi.ObjectTypeText,