nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pinojs/pino
Pull request #944 (2020-12-30 11:17:54)

access log level in hook #909
For https://github.com/pinojs/pino/issues/909

DoranYun: > Good work! Can you please add a unit test?

ok.

Patch:
diff --git a/docs/api.md b/docs/api.md
index 52f4100..4b50eab 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -175,10 +175,10 @@ internal logger operations. Hook functions ***must*** be synchronous functions.
 ##### `logMethod`
 
 Allows for manipulating the parameters passed to logger methods. The signature
-for this hook is `logMethod (args, method) {}`, where `args` is an array
+for this hook is `logMethod (args, method, level) {}`, where `args` is an array
 of the arguments that were passed to the log method and `method` is the log
-method itself. This hook ***must*** invoke the `method` function by using
-apply, like so: `method.apply(this, newArgumentsArray)`.
+method itself, `level` is the log level itself. This hook ***must*** invoke the
+`method` function by using apply, like so: `method.apply(this, newArgumentsArray)`.
 
 For example, Pino expects a binding object to be the first parameter with an
 optional string message as the second parameter. Using this hook the parameters
@@ -186,7 +186,7 @@ can be flipped:
 
 ```js
 const hooks = {
-  logMethod (inputArgs, method) {
+  logMethod (inputArgs, method, level) {
     if (inputArgs.length >= 2) {
       const arg1 = inputArgs.shift()
       const arg2 = inputArgs.shift()
diff --git a/lib/tools.js b/lib/tools.js
index e6b2abd..274c09c 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -31,7 +31,7 @@ function genLog (level, hook) {
   if (!hook) return LOG
 
   return function hookWrappedLog (...args) {
-    hook.call(this, args, LOG)
+    hook.call(this, args, LOG, level)
   }
 
   function LOG (o, ...n) {


Test patch:
diff --git a/test/hooks.test.js b/test/hooks.test.js
index d5a7d6a..36f3858 100644
--- a/test/hooks.test.js
+++ b/test/hooks.test.js
@@ -6,14 +6,16 @@ const pino = require('../')
 
 tap.test('log method hook', t => {
   t.test('gets invoked', async t => {
-    t.plan(6)
+    t.plan(8)
 
     const stream = sink()
     const logger = pino({
       hooks: {
-        logMethod (args, method) {
+        logMethod (args, method, level) {
           t.type(args, Array)
+          t.type(level, 'number')
           t.is(args.length, 3)
+          t.is(level, this.levels.values.info)
           t.deepEqual(args, ['a', 'b', 'c'])
 
           t.type(method, Function)
@@ -71,5 +73,25 @@ tap.test('log method hook', t => {
     t.match(await o, { msg: 'c-d' })
   })
 
+  t.test('get log level', async t => {
+    t.plan(3)
+
+    const stream = sink()
+    const logger = pino({
+      hooks: {
+        logMethod (args, method, level) {
+          t.type(level, 'number')
+          t.is(level, this.levels.values.error)
+
+          method.apply(this, [args.join('-')])
+        }
+      }
+    }, stream)
+
+    const o = once(stream, 'data')
+    logger.error('a')
+    t.match(await o, { msg: 'a' })
+  })
+
   t.end()
 })
Repository: JanDeDobbeleer/oh-my-posh
Pull request #3539 (2023-02-27 13:25:58)

fix(unity): output corrupt with CRLF line ending
### Prerequisites

- [x] I have read and understood the [contributing guide][CONTRIBUTING.md]
- [x] The commit message follows the [conventional commits][cc] guidelines
- [x] Tests for the changes have been added (for bug fixes/features)
- [x] Docs have been added/updated (for bug fixes/features)

### Description

Segments before the Unity segment get cut off if `ProjectSettings/ProjctVersion.txt` has CLRF line endings. Sorry for not catching this the first time around. I started trying it out on all the Unity projects on my machine, and stumbled across 2 projects that have this issue.

![oh-my-posh-debugging](https://user-images.githubusercontent.com/6819362/221575260-dfc78d7c-c5c1-4ade-aaee-256a635b6ceb.png)


Patch:
diff --git a/src/segments/unity.go b/src/segments/unity.go
index e6c95ccd..3bf9fc16 100644
--- a/src/segments/unity.go
+++ b/src/segments/unity.go
@@ -64,6 +64,7 @@ func (u *Unity) GetUnityVersion() (version string, err error) {
 
 	versionStartIndex := versionPrefixIndex + len(versionPrefix)
 	unityVersion := firstLine[versionStartIndex:]
+	unityVersion = strings.TrimSpace(unityVersion)
 
 	return strings.TrimSuffix(unityVersion, "f1"), nil
 }


Test patch:
diff --git a/src/segments/unity_test.go b/src/segments/unity_test.go
index 4cb9a75e..58fd9fba 100644
--- a/src/segments/unity_test.go
+++ b/src/segments/unity_test.go
@@ -147,6 +147,18 @@ func TestUnitySegment(t *testing.T) {
 			VersionFileExists:   true,
 			VersionFileText:     "2021.3.16f1",
 		},
+		{
+			Case:                "CRLF line ending",
+			ExpectedOutput:      "\ue721 2021.3.16 C# 9",
+			ExpectedToBeEnabled: true,
+			VersionFileExists:   true,
+			VersionFileText:     "m_EditorVersion: 2021.3.16f1\r\nm_EditorVersionWithRevision: 2021.3.16f1 (4016570cf34f)\r\n",
+			CacheGet: CacheGet{
+				key:   "2021.3",
+				val:   "C# 9",
+				found: true,
+			},
+		},
 	}
 
 	for _, tc := range cases {
Repository: JanDeDobbeleer/oh-my-posh
Pull request #3597 (2023-03-16 06:07:18)

fix(yaml): parse float64 from uint64
fix(yaml): parse float64 from uint64

resolves ##3591



Patch:
diff --git a/src/properties/properties.go b/src/properties/properties.go
index 74dfc9e0..71a497fe 100644
--- a/src/properties/properties.go
+++ b/src/properties/properties.go
@@ -98,17 +98,18 @@ func (m Map) GetFloat64(property Property, defaultValue float64) float64 {
 		return defaultValue
 	}
 
-	if floatValue, ok := val.(float64); ok {
-		return floatValue
-	}
-
-	// config parser parses an int
-	intValue, ok := val.(int)
-	if !ok {
+	switch v := val.(type) {
+	case int:
+		return float64(v)
+	case int64:
+		return float64(v)
+	case uint64:
+		return float64(v)
+	case float64:
+		return v
+	default:
 		return defaultValue
 	}
-
-	return float64(intValue)
 }
 
 func (m Map) GetInt(property Property, defaultValue int) int {


Test patch:
diff --git a/src/properties/properties_test.go b/src/properties/properties_test.go
index 409423c9..6619c6b0 100644
--- a/src/properties/properties_test.go
+++ b/src/properties/properties_test.go
@@ -86,10 +86,23 @@ func TestGetBoolInvalidProperty(t *testing.T) {
 }
 
 func TestGetFloat64(t *testing.T) {
-	expected := float64(1337)
-	var properties = Map{Foo: expected}
-	value := properties.GetFloat64(Foo, 9001)
-	assert.Equal(t, expected, value)
+	cases := []struct {
+		Case     string
+		Expected float64
+		Input    interface{}
+	}{
+		{Case: "int", Expected: 1337, Input: 1337},
+		{Case: "float64", Expected: 1337, Input: float64(1337)},
+		{Case: "uint64", Expected: 1337, Input: uint64(1337)},
+		{Case: "int64", Expected: 1337, Input: int64(1337)},
+		{Case: "string", Expected: 9001, Input: "invalid"},
+		{Case: "bool", Expected: 9001, Input: true},
+	}
+	for _, tc := range cases {
+		properties := Map{Foo: tc.Input}
+		value := properties.GetFloat64(Foo, 9001)
+		assert.Equal(t, tc.Expected, value, tc.Case)
+	}
 }
 
 func TestGetFloat64PropertyNotInMap(t *testing.T) {
@@ -98,17 +111,3 @@ func TestGetFloat64PropertyNotInMap(t *testing.T) {
 	value := properties.GetFloat64(Foo, expected)
 	assert.Equal(t, expected, value)
 }
-
-func TestGetFloat64InvalidStringProperty(t *testing.T) {
-	expected := float64(1337)
-	var properties = Map{Foo: "invalid"}
-	value := properties.GetFloat64(Foo, expected)
-	assert.Equal(t, expected, value)
-}
-
-func TestGetFloat64InvalidBoolProperty(t *testing.T) {
-	expected := float64(1337)
-	var properties = Map{Foo: true}
-	value := properties.GetFloat64(Foo, expected)
-	assert.Equal(t, expected, value)
-}