nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: kopia/kopia
Pull request #616 (2020-09-13 06:28:21)

Remove maintenance lock file on disconnect


Patch:
diff --git a/repo/connect.go b/repo/connect.go
index 4b39c023..f643ae39 100644
--- a/repo/connect.go
+++ b/repo/connect.go
@@ -159,6 +159,11 @@ func Disconnect(ctx context.Context, configFile string) error {
 		}
 	}
 
+	maintenanceLock := configFile + ".mlock"
+	if err := os.RemoveAll(maintenanceLock); err != nil {
+		log(ctx).Warningf("unable to remove maintenance lock file", maintenanceLock)
+	}
+
 	return os.Remove(configFile)
 }
 


Test patch:
diff --git a/internal/repotesting/repotesting.go b/internal/repotesting/repotesting.go
index 99a1bf5a..777b245d 100644
--- a/internal/repotesting/repotesting.go
+++ b/internal/repotesting/repotesting.go
@@ -100,9 +100,6 @@ func (e *Environment) Close(ctx context.Context, t *testing.T) {
 		}
 	}
 
-	// may need to remove the maintenance lock
-	os.Remove(e.configFile() + ".mlock")
-
 	if err := os.Remove(e.configDir); err != nil {
 		// should be empty, assuming Disconnect was successful
 		t.Errorf("error removing config directory: %v", err)
Repository: sonatype-nexus-community/nancy
Pull request #10 (2019-02-14 03:32:42)

Print nancy version on error and set a default version of "development".

This pull request makes the following changes:
Print nancy version on error and set a default version of "development".


Inspired by #9


fitzoh: Added in 3eb60950cd49cf82c92c28a2772b674146efc29b @bhamail 

Patch:
diff --git a/buildversion/version.go b/buildversion/version.go
index e6d05bf..d672bb3 100644
--- a/buildversion/version.go
+++ b/buildversion/version.go
@@ -1,8 +1,8 @@
 package buildversion
 
 var (
-	// these are populated via build CLI
-	BuildVersion = ""
+	// these are overwritten/populated via build CLI
+	BuildVersion = "development"
 	BuildTime    = ""
 	BuildCommit  = ""
 )
diff --git a/customerrors/error.go b/customerrors/error.go
index 890214c..e31252e 100644
--- a/customerrors/error.go
+++ b/customerrors/error.go
@@ -15,6 +15,7 @@ package customerrors
 
 import (
 	"fmt"
+	"github.com/sonatype-nexus-community/nancy/buildversion"
 	"os"
 )
 
@@ -35,6 +36,7 @@ func Check(err error, message string) {
 	if err != nil {
 		myErr := SwError{Message: message, Err: err}
 		fmt.Println(myErr.Error())
+		fmt.Println("nancy version:", buildversion.BuildVersion)
 		myErr.Exit()
 	}
 }


Test patch:
diff --git a/buildversion/version_test.go b/buildversion/version_test.go
new file mode 100644
index 0000000..1bd00a9
--- /dev/null
+++ b/buildversion/version_test.go
@@ -0,0 +1,18 @@
+package buildversion
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestDefaultVersion(t *testing.T) {
+	assert.Equal(t, "development", BuildVersion)
+}
+
+func TestDefaultBuildTime(t *testing.T) {
+	assert.Equal(t, "", BuildTime)
+}
+
+func TestDefaultBuildCommit(t *testing.T) {
+	assert.Equal(t, "", BuildCommit)
+}
Repository: sonatype-nexus-community/nancy
Pull request #11 (2019-02-15 20:06:41)

Add in a user-agent header 
Add in a user-agent header on the request so that we can start seeing what version people end up using, if people are using `nancy` versus just hitting OSS Index on their own, etc...

This pull request makes the following changes:
* Add's a `User-agent` header to the request, sets it to `nancy-client/version`
* Abstracts the request code into it's own function (make the world a better place!)



Patch:
diff --git a/ossindex/ossindex.go b/ossindex/ossindex.go
index 01cc62e..e996390 100644
--- a/ossindex/ossindex.go
+++ b/ossindex/ossindex.go
@@ -21,6 +21,7 @@ import (
 	"errors"
 	"fmt"
 	"github.com/dgraph-io/badger"
+	"github.com/sonatype-nexus-community/nancy/buildversion"
 	"github.com/sonatype-nexus-community/nancy/customerrors"
 	"github.com/sonatype-nexus-community/nancy/types"
 	"io/ioutil"
@@ -110,14 +111,10 @@ func AuditPackages(purls []string) ([]types.Coordinate, error) {
 		request.Coordinates = newPurls
 		var jsonStr, _ = json.Marshal(request)
 
-		var req *http.Request
-		if req, err = http.NewRequest(
-			"POST",
-			getOssIndexUrl(),
-			bytes.NewBuffer(jsonStr)); err != nil {
+		req, err := setupRequest(jsonStr)
+		if err != nil {
 			return nil, err
 		}
-		req.Header.Set("Content-Type", "application/json")
 
 		client := &http.Client{}
 		resp, err := client.Do(req)
@@ -170,3 +167,19 @@ func AuditPackages(purls []string) ([]types.Coordinate, error) {
 	}
 	return results, nil
 }
+
+func setupRequest(jsonStr []byte) (req *http.Request, err error) {
+	req, err = http.NewRequest(
+		"POST",
+		getOssIndexUrl(),
+		bytes.NewBuffer(jsonStr),
+	)
+	if err != nil {
+		return nil, err
+	}
+
+	req.Header.Set("User-Agent", fmt.Sprintf("nancy-client/%s", buildversion.BuildVersion))
+	req.Header.Set("Content-Type", "application/json")
+
+	return req, nil
+}


Test patch:
diff --git a/ossindex/ossindex_test.go b/ossindex/ossindex_test.go
index 037b7fb..6aba548 100644
--- a/ossindex/ossindex_test.go
+++ b/ossindex/ossindex_test.go
@@ -248,3 +248,23 @@ func TestAuditPackages_SinglePackage_Cached_WithExpiredTTL(t *testing.T) {
 	assert.Equal(t, []types.Coordinate{expectedCoordinate}, coordinates)
 	assert.Nil(t, err)
 }
+
+func TestSetupRequest(t *testing.T) {
+	coordJson, _ := setupJson(t)
+	req, err := setupRequest(coordJson)
+
+	assert.Equal(t, req.Header.Get("User-Agent"), "nancy-client/development")
+	assert.Equal(t, req.Header.Get("Content-Type"), "application/json")
+	assert.Equal(t, req.Method, "POST")
+	assert.Nil(t, err)
+}
+
+// TODO: Use this for more than just TestSetupRequest
+func setupJson(t *testing.T) (coordJson []byte, err error) {
+	coordJson, err = json.Marshal(expectedCoordinate)
+	if err != nil {
+		t.Errorf("Couldn't setup json")
+	}
+
+	return
+}
Repository: sonatype-nexus-community/nancy
Pull request #266 (2022-05-27 17:02:50)

Normalize version when using go install

This pull request makes the following changes:
* fixes issue with unnormalized version tags when installing via `go install` (e.g., v1.1.1 vs 1.1.1)

It relates to the following issue #s:
* Fixes issues introduced in https://github.com/sonatype-nexus-community/nancy/pull/265

cc @bhamail / @DarthHater



Patch:
diff --git a/buildversion/version.go b/buildversion/version.go
index eae7ebc..2b1b368 100644
--- a/buildversion/version.go
+++ b/buildversion/version.go
@@ -19,6 +19,8 @@ package buildversion
 import (
 	"fmt"
 	"runtime/debug"
+
+	"github.com/blang/semver"
 )
 
 const DefaultVersion = "0.0.0-dev"
@@ -39,13 +41,30 @@ func PackageManager() string {
 	return packageManager
 }
 
+func NormalizeVersion(version string) (string, error) {
+	if version[0] == 'v' {
+		// Normalize version tags in the form v1.1.1 to 1.1.1
+		version = version[1:]
+	}
+	// Ensure that version tag can be parsed correctly
+	_, err := semver.Parse(version)
+	if err != nil {
+		return version, err
+	}
+	return version, nil
+}
+
 func init() {
 	// Use build info from debug package if available, and if no build info is
 	// provided via build CLI.
 	info, available := debug.ReadBuildInfo()
 	// info.Main.Version will be "" when debugging, and "(devel)" when building with no arguments
 	if available && info.Main.Version != "" && info.Main.Version != "(devel)" && BuildTime == "" && BuildCommit == "" && BuildVersion == DefaultVersion {
-		BuildVersion = info.Main.Version
+		version, err := NormalizeVersion(info.Main.Version)
+		if err != nil {
+			return
+		}
+		BuildVersion = version
 		BuildCommit = fmt.Sprintf("(unknown, mod sum: %q)", info.Main.Sum)
 		BuildTime = "(unknown)"
 	}


Test patch:
diff --git a/buildversion/version_test.go b/buildversion/version_test.go
index eea98e6..bc7cc4c 100644
--- a/buildversion/version_test.go
+++ b/buildversion/version_test.go
@@ -33,3 +33,45 @@ func TestDefaultBuildTime(t *testing.T) {
 func TestDefaultBuildCommit(t *testing.T) {
 	assert.Equal(t, "", BuildCommit)
 }
+
+func TestNormalizeVersion(t *testing.T) {
+	tests := []struct {
+		expected   string
+		input      string
+		shouldFail bool
+	}{
+		{
+			input:    "1.1.1",
+			expected: "1.1.1",
+		},
+		{
+			input:    "v1.1.1",
+			expected: "1.1.1",
+		},
+		{
+			input:      "x1.1.1",
+			shouldFail: true,
+		},
+		{
+			input:      "vv1.1.1",
+			shouldFail: true,
+		},
+		{
+			input:      "1.1",
+			shouldFail: true,
+		},
+		{
+			input:      "foobar",
+			shouldFail: true,
+		},
+	}
+	for _, test := range tests {
+		actual, err := NormalizeVersion(test.input)
+		if test.shouldFail {
+			assert.Error(t, err)
+			continue
+		}
+		assert.NoError(t, err)
+		assert.Equal(t, test.expected, actual)
+	}
+}