nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mlange-42/arche
Pull request #435 (2024-11-30 01:11:49)

Make node.GetArchetype more idiomatic

coveralls: ## Pull Request Test Coverage Report for [Build 12092308062](https://coveralls.io/builds/71120935)


### Details

* **10** of **10**   **(100.0%)**  changed or added relevant lines in **2** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **100.0%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/71120935/badge)](https://coveralls.io/builds/71120935) |
| :-- | --: |
| Change from base [Build 12041170297](https://coveralls.io/builds/71072984): |  0.0% |
| Covered Lines: | 6368 |
| Relevant Lines: | 6368 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/ecs/archetype_node.go b/ecs/archetype_node.go
index ac266a7..896db67 100644
--- a/ecs/archetype_node.go
+++ b/ecs/archetype_node.go
@@ -98,11 +98,12 @@ func (a *archNode) Archetypes() archetypes {
 // GetArchetype returns the archetype for the given relation target.
 //
 // The target is ignored if the node has no relation component.
-func (a *archNode) GetArchetype(target Entity) *archetype {
+func (a *archNode) GetArchetype(target Entity) (*archetype, bool) {
 	if a.HasRelation {
-		return a.archetypeMap[target]
+		arch, ok := a.archetypeMap[target]
+		return arch, ok
 	}
-	return a.archetype
+	return a.archetype, a.archetype != nil
 }
 
 // SetArchetype sets the archetype for a node without a relation.
diff --git a/ecs/world_internal.go b/ecs/world_internal.go
index 25aff31..a63cf4a 100644
--- a/ecs/world_internal.go
+++ b/ecs/world_internal.go
@@ -729,8 +729,8 @@ func (w *World) setRelation(entity Entity, comp ID, target Entity) {
 		return
 	}
 
-	arch := oldArch.node.GetArchetype(target)
-	if arch == nil {
+	arch, ok := oldArch.node.GetArchetype(target)
+	if !ok {
 		arch = w.createArchetype(oldArch.node, target, true)
 	}
 
@@ -824,8 +824,8 @@ func (w *World) setRelationArch(oldArch *archetype, oldArchLen uint32, comp ID,
 
 	oldIDs := oldArch.Components()
 
-	arch := oldArch.node.GetArchetype(target)
-	if arch == nil {
+	arch, ok := oldArch.node.GetArchetype(target)
+	if !ok {
 		arch = w.createArchetype(oldArch.node, target, true)
 	}
 
@@ -955,8 +955,8 @@ func (w *World) findOrCreateArchetype(start *archetype, add []ID, rem []ID, targ
 			curr = next
 		}
 	}
-	arch := curr.GetArchetype(target)
-	if arch == nil {
+	arch, ok := curr.GetArchetype(target)
+	if !ok {
 		arch = w.createArchetype(curr, target, true)
 	}
 	return arch


Test patch:
diff --git a/ecs/archetype_test.go b/ecs/archetype_test.go
index 2fa77af..92993ee 100644
--- a/ecs/archetype_test.go
+++ b/ecs/archetype_test.go
@@ -130,8 +130,9 @@ func TestArchetypeExtendLayouts(t *testing.T) {
 
 	node = newArchNode(All(id(0), id(1)), &nodeData{}, id(2), true, 8, comps)
 	node.CreateArchetype(16, entity)
-	arch2 := node.GetArchetype(entity)
+	arch2, ok := node.GetArchetype(entity)
 
+	assert.True(t, ok)
 	assert.Equal(t, len(arch2.layouts), 16)
 	node.ExtendArchetypeLayouts(16)
 	assert.Equal(t, len(arch2.layouts), 16)
Repository: mmcdole/gofeed
Pull request #136 (2020-02-09 15:31:17)

Fix: get gofeed.FeedLink from atom:link tag
For the DefaultRSSTranslator the FeedLink field should get its value from the /rss/channel/atom:link[@rel="self"]/@href tag.



coveralls: 
[![Coverage Status](https://coveralls.io/builds/28615974/badge)](https://coveralls.io/builds/28615974)

Coverage increased (+0.9%) to 60.839% when pulling **0ff7ba45c993df107947b2eddd64bfad01dcee2c on andrikod:master** into **b4a66758a404fdb3e5b322a36ce4f042ff36c6a1 on mmcdole:master**.

mmcdole: Thank you for the PR!

Patch:
diff --git a/translator.go b/translator.go
index 4756b4b..cfe79a9 100644
--- a/translator.go
+++ b/translator.go
@@ -103,8 +103,8 @@ func (t *DefaultRSSTranslator) translateFeedFeedLink(rss *rss.Feed) (link string
 	for _, ex := range atomExtensions {
 		if links, ok := ex["link"]; ok {
 			for _, l := range links {
-				if l.Attrs["Rel"] == "self" {
-					link = l.Value
+				if l.Attrs["rel"] == "self" {
+					link = l.Attrs["href"]
 				}
 			}
 		}


Test patch:
diff --git a/testdata/translator/rss/feed_link_-_rss_channel_atom_link.json b/testdata/translator/rss/feed_link_-_rss_channel_atom_link.json
new file mode 100644
index 0000000..904d3ad
--- /dev/null
+++ b/testdata/translator/rss/feed_link_-_rss_channel_atom_link.json
@@ -0,0 +1,22 @@
+{  
+  "items": [],
+  "feedType": "rss",
+  "feedVersion": "2.0",
+  "feedLink": "http://example.org",
+  "extensions": {
+        "atom": {
+            "link": [
+                {
+                    "name": "link",
+                    "value": "",
+                    "attrs": {
+                        "href": "http://example.org",
+                        "rel": "self",
+                        "type": "application/rss+xml"
+                    },
+                    "children": {}
+                }
+            ]
+        }
+    }
+}
diff --git a/testdata/translator/rss/feed_link_-_rss_channel_atom_link.xml b/testdata/translator/rss/feed_link_-_rss_channel_atom_link.xml
new file mode 100644
index 0000000..f44c733
--- /dev/null
+++ b/testdata/translator/rss/feed_link_-_rss_channel_atom_link.xml
@@ -0,0 +1,8 @@
+<!--
+Description: atom link
+-->
+<rss version="2.0">
+  <channel>    
+    <atom:link href="http://example.org" rel="self" type="application/rss+xml"/>
+  </channel>
+</rss>
Repository: mmcdole/gofeed
Pull request #141 (2020-03-15 00:08:10)

Add sort.Interface implementation for Feed
Order Feed.Items by oldest to newest publish time.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/29359728/badge)](https://coveralls.io/builds/29359728)

Coverage increased (+0.2%) to 60.816% when pulling **b4d7890e49fc4010aaf09e280c48e3683887ef56 on grafoo:sort** into **1ed4d84b36ec028b02a00b3651a7ca9918082e13 on mmcdole:master**.


Patch:
diff --git a/README.md b/README.md
index 1606160..3d50265 100644
--- a/README.md
+++ b/README.md
@@ -99,6 +99,16 @@ feed, _ := fp.Parse(file)
 fmt.Println(feed.Title)
 ```
 
+##### Parse a feed from an URL with a 60s timeout:
+
+```go
+ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
+defer cancel()
+fp := gofeed.NewParser()
+feed, _ := fp.ParseURLWithContext("http://feeds.twit.tv/twit.xml", ctx)
+fmt.Println(feed.Title)
+```
+
 #### Feed Specific Parsers
 
 You can easily use the `rss.Parser` and `atom.Parser` directly if you have a usage scenario that requires it:
diff --git a/feed.go b/feed.go
index 9ee1eaa..8d95c04 100644
--- a/feed.go
+++ b/feed.go
@@ -10,6 +10,8 @@ import (
 // Feed is the universal Feed type that atom.Feed
 // and rss.Feed gets translated to. It represents
 // a web feed.
+// Sorting with sort.Sort will order the Items by
+// oldest to newest publish time.
 type Feed struct {
 	Title           string                   `json:"title,omitempty"`
 	Description     string                   `json:"description,omitempty"`
@@ -82,3 +84,21 @@ type Enclosure struct {
 	Length string `json:"length,omitempty"`
 	Type   string `json:"type,omitempty"`
 }
+
+// Len returns the length of Items.
+func (f Feed) Len() int {
+	return len(f.Items)
+}
+
+// Less compares PublishedParsed of Items[i], Items[k]
+// and returns true if Items[i] is less than Items[k].
+func (f Feed) Less(i, k int) bool {
+	return f.Items[i].PublishedParsed.Before(
+		*f.Items[k].PublishedParsed,
+	)
+}
+
+// Swap swaps Items[i] and Items[k].
+func (f Feed) Swap(i, k int) {
+	f.Items[i], f.Items[k] = f.Items[k], f.Items[i]
+}


Test patch:
diff --git a/feed_test.go b/feed_test.go
new file mode 100644
index 0000000..7baa8df
--- /dev/null
+++ b/feed_test.go
@@ -0,0 +1,50 @@
+package gofeed_test
+
+import (
+	"sort"
+	"testing"
+	"time"
+
+	"github.com/mmcdole/gofeed"
+)
+
+func TestFeedSort(t *testing.T) {
+	oldestItem := &gofeed.Item{
+		PublishedParsed: &[]time.Time{time.Unix(0, 0)}[0],
+	}
+	inbetweenItem := &gofeed.Item{
+		PublishedParsed: &[]time.Time{time.Unix(1, 0)}[0],
+	}
+	newestItem := &gofeed.Item{
+		PublishedParsed: &[]time.Time{time.Unix(2, 0)}[0],
+	}
+
+	feed := gofeed.Feed{
+		Items: []*gofeed.Item{
+			newestItem,
+			oldestItem,
+			inbetweenItem,
+		},
+	}
+	expected := gofeed.Feed{
+		Items: []*gofeed.Item{
+			oldestItem,
+			inbetweenItem,
+			newestItem,
+		},
+	}
+
+	sort.Sort(feed)
+
+	for i, item := range feed.Items {
+		if !item.PublishedParsed.Equal(
+			*expected.Items[i].PublishedParsed,
+		) {
+			t.Errorf(
+				"Item PublishedParsed = %s; want %s",
+				item.PublishedParsed,
+				expected.Items[i].PublishedParsed,
+			)
+		}
+	}
+}
Repository: mmcdole/gofeed
Pull request #221 (2024-02-22 22:33:50)

Added fallback to atom icon when atom logo is missing
First off, fantastic library! :clap:  Great job.

While integrating it into [Feeder](https://github.com/spacecowboy/feeder) (my Android feed reader) one of my unit tests failed. :disappointed: 

This PR would make the test pass in my project. What do you think?

For reference, it is this assertion: https://github.com/spacecowboy/Feeder/blob/master/app/src/test/java/com/nononsenseapps/feeder/model/FeedParserTest.kt#L673

Which parses the file at: https://github.com/spacecowboy/Feeder/blob/master/app/src/test/resources/com/nononsenseapps/feeder/model/atom_cowboy.xml

mmcdole: Icon being a fallback for Feed.Image seems reasonable to me. Thanks for the contribution (and tests)!

Patch:
diff --git a/translator.go b/translator.go
index e436c35..638f8de 100644
--- a/translator.go
+++ b/translator.go
@@ -613,6 +613,10 @@ func (t *DefaultAtomTranslator) translateFeedImage(atom *atom.Feed) (image *Imag
 		feedImage := Image{}
 		feedImage.URL = atom.Logo
 		image = &feedImage
+	} else if atom.Icon != "" {
+		feedImage := Image{}
+		feedImage.URL = atom.Icon
+		image = &feedImage
 	}
 	return
 }


Test patch:
diff --git a/testdata/translator/atom/feed_image_-_atom10_feed_icon.json b/testdata/translator/atom/feed_image_-_atom10_feed_icon.json
new file mode 100644
index 0000000..8be1ee3
--- /dev/null
+++ b/testdata/translator/atom/feed_image_-_atom10_feed_icon.json
@@ -0,0 +1,8 @@
+{
+    "image": {
+        "url": "http://example.org/icon.jpg"
+    },
+    "items": [],
+    "feedType": "atom",
+    "feedVersion": "1.0"
+}
diff --git a/testdata/translator/atom/feed_image_-_atom10_feed_icon.xml b/testdata/translator/atom/feed_image_-_atom10_feed_icon.xml
new file mode 100644
index 0000000..41d2661
--- /dev/null
+++ b/testdata/translator/atom/feed_image_-_atom10_feed_icon.xml
@@ -0,0 +1,6 @@
+<!--
+Description: feed icon
+-->
+<feed xmlns="http://www.w3.org/2005/Atom">
+  <icon>http://example.org/icon.jpg</icon>
+</feed>
diff --git a/testdata/translator/atom/feed_image_-_atom10_feed_logo.xml b/testdata/translator/atom/feed_image_-_atom10_feed_logo.xml
index e625ccd..d4d8e3d 100644
--- a/testdata/translator/atom/feed_image_-_atom10_feed_logo.xml
+++ b/testdata/translator/atom/feed_image_-_atom10_feed_logo.xml
@@ -3,4 +3,5 @@ Description: feed logo
 -->
 <feed xmlns="http://www.w3.org/2005/Atom">
   <logo>http://example.org/logo.jpg</logo>
+  <icon>http://example.org/icon.jpg</icon>
 </feed>