nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: grafana/tanka
Pull request #614 (2021-10-01 14:03:00)

Add check for using spec.json and inline envs simultaneously
Fixes https://github.com/grafana/tanka/issues/612


Patch:
diff --git a/pkg/tanka/load.go b/pkg/tanka/load.go
index d4b925bd..7cf928a8 100644
--- a/pkg/tanka/load.go
+++ b/pkg/tanka/load.go
@@ -31,6 +31,12 @@ func Load(path string, opts Opts) (*LoadResult, error) {
 		return nil, err
 	}
 
+	// Check if there are still any inline environments in the manifests
+	// They are not real k8s resources, and cannot be applied
+	if envs := process.Filter(result.Resources, process.MustStrExps("Environment/.*")); len(envs) > 0 {
+		return nil, errors.New("found a tanka Environment resource. Check that you aren't using a spec.json and inline environments simultaneously")
+	}
+
 	return result, nil
 }
 


Test patch:
diff --git a/pkg/tanka/load_test.go b/pkg/tanka/load_test.go
index 0863a01d..b77a09f5 100644
--- a/pkg/tanka/load_test.go
+++ b/pkg/tanka/load_test.go
@@ -154,3 +154,8 @@ func TestLoadFailsWhenDuplicateEnv(t *testing.T) {
 	_, err := Load("./testdata/cases/withduplicateenv", Opts{Name: "withenv"})
 	assert.NotNil(t, err)
 }
+
+func TestLoadFailsWhenBothSpecAndInline(t *testing.T) {
+	_, err := Load("./testdata/cases/static_and_inline", Opts{Name: "inline"})
+	assert.EqualError(t, err, "found a tanka Environment resource. Check that you aren't using a spec.json and inline environments simultaneously")
+}
diff --git a/pkg/tanka/testdata/cases/static_and_inline/main.jsonnet b/pkg/tanka/testdata/cases/static_and_inline/main.jsonnet
new file mode 100644
index 00000000..d89f8a09
--- /dev/null
+++ b/pkg/tanka/testdata/cases/static_and_inline/main.jsonnet
@@ -0,0 +1,16 @@
+{
+  apiVersion: 'tanka.dev/v1alpha1',
+  kind: 'Environment',
+  metadata: {
+    name: 'inline',
+  },
+  spec: {
+    apiServer: 'https://localhost',
+    namespace: 'inline',
+  },
+  data: {
+    apiVersion: 'v1',
+    kind: 'ConfigMap',
+    metadata: { name: 'config' },
+  },
+}
diff --git a/pkg/tanka/testdata/cases/static_and_inline/spec.json b/pkg/tanka/testdata/cases/static_and_inline/spec.json
new file mode 100644
index 00000000..279417a2
--- /dev/null
+++ b/pkg/tanka/testdata/cases/static_and_inline/spec.json
@@ -0,0 +1,11 @@
+{
+  "apiVersion": "tanka.dev/v1alpha1",
+  "kind": "Environment",
+  "metadata": {
+    "name": "static"
+  },
+  "spec": {
+    "apiServer": "https://localhost",
+    "namespace": "static"
+  }
+}
Repository: grafana/tanka
Pull request #643 (2021-11-19 13:26:34)

Remove yaml.v3's version lock
Closes https://github.com/grafana/tanka/issues/629

This will cause whitespace changes for manifestYaml* native functions

We will still have yaml.v2 as a dependency but I commented here: https://github.com/grafana/tanka/issues/607#issuecomment-973683064 why I think we should wait a bit and see



julienduchesne: Merging this. It will be released tomorrow. I'll describe in the CHANGELOG how to upgrade only a few environments when using `export`

Patch:
diff --git a/go.mod b/go.mod
index c612ae73..7565b92a 100644
--- a/go.mod
+++ b/go.mod
@@ -2,10 +2,6 @@ module github.com/grafana/tanka
 
 go 1.17
 
-// Pin gopkg.in/yaml.v3
-// yaml.v3 should be bumped with care. The new versions change all list indents
-replace gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
-
 require (
 	github.com/Masterminds/semver v1.5.0
 	github.com/Masterminds/sprig/v3 v3.2.2
diff --git a/go.sum b/go.sum
index 8bb6d272..106012e9 100644
--- a/go.sum
+++ b/go.sum
@@ -261,8 +261,10 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 k8s.io/apimachinery v0.22.2 h1:ejz6y/zNma8clPVfNDLnPbleBo6MpoFy/HBiBqCouVk=


Test patch:
diff --git a/pkg/jsonnet/native/funcs_test.go b/pkg/jsonnet/native/funcs_test.go
index 71a9293d..5cb8b70e 100644
--- a/pkg/jsonnet/native/funcs_test.go
+++ b/pkg/jsonnet/native/funcs_test.go
@@ -114,9 +114,9 @@ func TestManifestYAMLFromJSONList(t *testing.T) {
 
 	assert.Empty(t, callerr)
 	assert.Equal(t, `list:
-  - a
-  - b
-  - c
+    - a
+    - b
+    - c
 `, ret)
 	assert.Empty(t, err)
 }
Repository: grafana/tanka
Pull request #881 (2023-06-16 08:33:59)

chore: add support for native `sha256()` function

github-actions[bot]: [PR Preview Action](https://github.com/rossjrw/pr-preview-action) v1.4.4
:---:
:rocket: Deployed preview to https://grafana.github.io/tanka/pr-preview/pr-881/
on branch [`gh-pages`](https://github.com/grafana/tanka/tree/gh-pages) at 2023-06-16 08:37 UTC
<!-- Sticky Pull Request Commentpr-preview -->

Patch:
diff --git a/docs/docs/jsonnet/native-functions.md b/docs/docs/jsonnet/native-functions.md
index 38ed6dfb..da7eb4b9 100644
--- a/docs/docs/jsonnet/native-functions.md
+++ b/docs/docs/jsonnet/native-functions.md
@@ -18,6 +18,32 @@ To use them in your code, you need to access them using `std.native` from the st
 
 `std.native` takes the native function's name as a `string` argument and returns a `function`, which is called using the second set of parentheses.
 
+## sha256
+
+### Signature
+
+```ts
+sha256(string str) string
+```
+
+`sha256` computes the SHA256 sum of the given string.
+
+### Examples
+
+```jsonnet
+{
+  sum: std.native('sha256')('Hello, World!'),
+}
+```
+
+Evaluating with Tanka results in the JSON:
+
+```json
+{
+  "sum": "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f"
+}
+```
+
 ## parseJson
 
 ### Signature
diff --git a/pkg/jsonnet/native/funcs.go b/pkg/jsonnet/native/funcs.go
index e6ef0f06..d42fc33d 100644
--- a/pkg/jsonnet/native/funcs.go
+++ b/pkg/jsonnet/native/funcs.go
@@ -2,7 +2,9 @@ package native
 
 import (
 	"bytes"
+	"crypto/sha256"
 	"encoding/json"
+	"fmt"
 	"io"
 	"regexp"
 	"strings"
@@ -32,6 +34,9 @@ func Funcs() []*jsonnet.NativeFunction {
 		regexMatch(),
 		regexSubst(),
 
+		// Hash functions
+		hashSha256(),
+
 		helm.NativeFunc(helm.ExecHelm{}),
 		kustomize.NativeFunc(kustomize.ExecKustomize{}),
 	}
@@ -50,6 +55,18 @@ func parseJSON() *jsonnet.NativeFunction {
 	}
 }
 
+func hashSha256() *jsonnet.NativeFunction {
+	return &jsonnet.NativeFunction{
+		Name:   "sha256",
+		Params: ast.Identifiers{"str"},
+		Func: func(dataString []interface{}) (interface{}, error) {
+			h := sha256.New()
+			h.Write([]byte(dataString[0].(string)))
+			return fmt.Sprintf("%x", h.Sum(nil)), nil
+		},
+	}
+}
+
 // parseYAML wraps `yaml.Unmarshal` to convert a string of yaml document(s) into a (set of) dicts
 func parseYAML() *jsonnet.NativeFunction {
 	return &jsonnet.NativeFunction{


Test patch:
diff --git a/pkg/jsonnet/native/funcs_test.go b/pkg/jsonnet/native/funcs_test.go
index 5cb8b70e..afa13a8f 100644
--- a/pkg/jsonnet/native/funcs_test.go
+++ b/pkg/jsonnet/native/funcs_test.go
@@ -21,6 +21,14 @@ func callNative(name string, data []interface{}) (res interface{}, err error, ca
 	return nil, nil, fmt.Errorf("could not find native function %s", name)
 }
 
+func TestSha256(t *testing.T) {
+	ret, err, callerr := callNative("sha256", []interface{}{"foo"})
+
+	assert.Empty(t, callerr)
+	assert.Equal(t, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae", ret)
+	assert.Empty(t, err)
+}
+
 func TestParseJSONEmptyDict(t *testing.T) {
 	ret, err, callerr := callNative("parseJson", []interface{}{"{}"})
Repository: prebid/prebid-server
Pull request #2767 (2023-05-10 20:33:32)

Get Bid Type For Adjustments Bug Fix
Addresses issue with `getBidTypeForAdjustments`, which is used to determine what bid type should be used to get the relevant bid adjustment. This is necessary specifically for the case where the bid type on the request is `Video`, but for bid adjustments we need to determine if that bid type is `video-instream` or `video-outstream` by looking at the Imp tied to a request.

The issue here was I assumed that if the bid type was `video`, that the imp would also have a `video` type in it. But it turns out `Video` could be nil in the imp, which lead to a nil dereference panic.

So I just needed to add a nil check into this function, and added an extra unit test for coverage.


Patch:
diff --git a/exchange/bidder.go b/exchange/bidder.go
index e355c18c..f5efcff3 100644
--- a/exchange/bidder.go
+++ b/exchange/bidder.go
@@ -699,7 +699,7 @@ func getBidTypeForAdjustments(bidType openrtb_ext.BidType, impID string, imp []o
 	if bidType == openrtb_ext.BidTypeVideo {
 		for _, imp := range imp {
 			if imp.ID == impID {
-				if imp.Video.Plcmt == adcom1.VideoPlcmtAccompanyingContent {
+				if imp.Video != nil && imp.Video.Plcmt == adcom1.VideoPlcmtAccompanyingContent {
 					return "video-outstream"
 				}
 				break


Test patch:
diff --git a/exchange/bidder_test.go b/exchange/bidder_test.go
index 3bd023dd..4e94a18f 100644
--- a/exchange/bidder_test.go
+++ b/exchange/bidder_test.go
@@ -3036,6 +3036,17 @@ func TestGetBidType(t *testing.T) {
 			givenImpId:   "imp-id",
 			expected:     string(openrtb_ext.BidTypeBanner),
 		},
+		{
+			name: "VideoBidTypeImpVideoIsNil",
+			givenImp: []openrtb2.Imp{
+				{
+					ID: "imp-id",
+				},
+			},
+			givenBidType: openrtb_ext.BidTypeVideo,
+			givenImpId:   "imp-id",
+			expected:     "video-instream",
+		},
 	}
 
 	for _, test := range testCases {