nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: uber-go/fx
Pull request #792 (2021-09-17 20:56:48)

app: Add internal option to override os.Exit
Add an option exposed only to tests in the go.uber.org/fx package that
allows overriding how `os.Exit` behaves.

The way the new option works is,

- `App` gets a new `osExit func(int)` field which defaults to `os.Exit`
- app_internal_test.go uses `package fx` and therefore, it can access
  internal fields of the `App`. We define a new exported option in this
  package that sets `osExit`. Because this option is defined in a test
  file, though, it is not made part of the public API of the package.
- app_test.go uses `package fx_test` so it's an external test--it cannot
  access unexported fields, but it can access the exported option
  defined in app_internal_test.go.

This will allow testing the `app.Run` function directly.



Patch:
diff --git a/app.go b/app.go
index 5c78270..2680e36 100644
--- a/app.go
+++ b/app.go
@@ -381,6 +381,8 @@ type App struct {
 	// Used to signal shutdowns.
 	donesMu sync.RWMutex
 	dones   []chan os.Signal
+
+	osExit func(code int) // os.Exit override; used for testing only
 }
 
 // provide is a single constructor provided to Fx.
@@ -640,6 +642,15 @@ func VisualizeError(err error) (string, error) {
 	return "", errors.New("unable to visualize error")
 }
 
+// Exits the application with the given exit code.
+func (app *App) exit(code int) {
+	osExit := os.Exit
+	if app.osExit != nil {
+		osExit = app.osExit
+	}
+	osExit(code)
+}
+
 // Run starts the application, blocks on the signals channel, and then
 // gracefully shuts the application down. It uses DefaultTimeout to set a
 // deadline for application startup and shutdown, unless the user has
@@ -654,7 +665,7 @@ func (app *App) Run() {
 	// cede control to Fx with they call app.Run. To avoid a breaking
 	// change, never os.Exit for success.
 	if code := app.run(app.Done()); code != 0 {
-		os.Exit(code)
+		app.exit(code)
 	}
 }
 


Test patch:
diff --git a/app_internal_test.go b/app_internal_test.go
index 78c40eb..b53c60b 100644
--- a/app_internal_test.go
+++ b/app_internal_test.go
@@ -30,6 +30,7 @@ import (
 	"github.com/stretchr/testify/require"
 	"go.uber.org/fx/fxevent"
 	"go.uber.org/fx/internal/fxlog"
+	"go.uber.org/fx/internal/fxreflect"
 )
 
 func TestAppRun(t *testing.T) {
@@ -70,3 +71,19 @@ func TestValidateString(t *testing.T) {
 	require.True(t, ok, "option must implement stringer")
 	assert.Equal(t, "fx.validate(true)", stringer.String())
 }
+
+// WithExit is an internal option available only to tests defined in this
+// package. It changes how os.Exit behaves for the application.
+func WithExit(f func(int)) Option {
+	return withExitOption(f)
+}
+
+type withExitOption func(int)
+
+func (o withExitOption) String() string {
+	return fmt.Sprintf("WithExit(%v)", fxreflect.FuncName(o))
+}
+
+func (o withExitOption) apply(app *App) {
+	app.osExit = o
+}
Repository: geoffrich/svelte-adapter-azure-swa
Pull request #160 (2023-11-20 00:01:48)

fix: do not throw on parsing client principal
Related https://github.com/geoffrich/svelte-adapter-azure-swa/issues/157

With this PR, we won't throw if the parsed client principal can't be decoded as JSON. We'll return undefined instead.

The underlying issue linked above still needs to be fixed, however.

github-actions[bot]: Azure Static Web Apps: Your stage site is ready! Visit it here: https://polite-desert-00b80111e-160.westus2.2.azurestaticapps.net

Patch:
diff --git a/files/headers.js b/files/headers.js
index df2a7f9..b606ab6 100644
--- a/files/headers.js
+++ b/files/headers.js
@@ -54,9 +54,14 @@ export function getClientPrincipalFromHeaders(headers) {
 		return undefined;
 	}
 
-	const encoded = Buffer.from(header, 'base64');
-	const decoded = encoded.toString('ascii');
-	const clientPrincipal = JSON.parse(decoded);
+	try {
+		const encoded = Buffer.from(header, 'base64');
+		const decoded = encoded.toString('ascii');
+		const clientPrincipal = JSON.parse(decoded);
 
-	return clientPrincipal;
+		return clientPrincipal;
+	} catch (e) {
+		console.log('Unable to parse client principal:', e);
+		return undefined;
+	}
 }


Test patch:
diff --git a/test/headers.test.js b/test/headers.test.js
index e63c5f0..37145bc 100644
--- a/test/headers.test.js
+++ b/test/headers.test.js
@@ -118,4 +118,12 @@ describe('client principal parsing', () => {
 	test('returns undefined when there is no client principal', () => {
 		expect(getClientPrincipalFromHeaders(new Headers())).toBeUndefined();
 	});
+
+	test('returns undefined if unable to parse', () => {
+		const headers = new Headers({
+			'x-ms-client-principal': 'boom'
+		});
+
+		expect(getClientPrincipalFromHeaders(headers)).toBeUndefined();
+	});
 });
Repository: bustlelabs/shep
Pull request #129 (2016-11-21 20:10:51)

Allow there to be no api.json file.


Patch:
diff --git a/src/util/load.js b/src/util/load.js
index 45fd035..9fff7d3 100644
--- a/src/util/load.js
+++ b/src/util/load.js
@@ -40,5 +40,9 @@ export function pkg () {
 }
 
 export function api () {
-  return readJSONSync('api.json')
+  try {
+    return readJSONSync('api.json')
+  } catch (e) {
+    return null
+  }
 }


Test patch:
diff --git a/test/util/load.js b/test/util/load.js
index 4bb2ebc..64fe648 100644
--- a/test/util/load.js
+++ b/test/util/load.js
@@ -25,3 +25,8 @@ test('Loads lambda config', (t) => {
   t.is(config.Role, 'admin')
   t.is(config.Memory, 5)
 })
+
+test('Is ok with no api config', (t) => {
+  const config = load.api()
+  t.is(config, null)
+})
Repository: busyorg/busy
Pull request #678 (2017-08-31 11:47:18)

Add primary Action button for post
This adds `primary` prop to `Action` component and uses it inside Editor.
![image](https://user-images.githubusercontent.com/1968722/29921694-e40dcf56-8e52-11e7-8aaa-cc78472ae92f.png)



Patch:
diff --git a/src/components/Button/Action.js b/src/components/Button/Action.js
index 8b6f587a..4eb21f68 100644
--- a/src/components/Button/Action.js
+++ b/src/components/Button/Action.js
@@ -4,8 +4,8 @@ import { Icon } from 'antd';
 import classNames from 'classnames';
 import './Action.less';
 
-const Action = ({ text, loading, disabled, style, small, onClick }) => (
-  <button disabled={disabled} style={style} className={classNames('Action', { 'ant-btn-lg': !small })} onClick={onClick}>
+const Action = ({ text, loading, disabled, primary, style, small, onClick }) => (
+  <button disabled={disabled} style={style} className={classNames('Action', { 'ant-btn-lg': !small, 'Action--primary': primary })} onClick={onClick}>
     {loading && <Icon type="loading" />}
     {text}
   </button>);
@@ -14,6 +14,7 @@ Action.propTypes = {
   text: PropTypes.string.isRequired,
   loading: PropTypes.bool,
   disabled: PropTypes.bool,
+  primary: PropTypes.bool,
   style: PropTypes.shape(),
   small: PropTypes.bool,
   onClick: PropTypes.func,
@@ -22,6 +23,7 @@ Action.propTypes = {
 Action.defaultProps = {
   loading: false,
   disabled: false,
+  primary: false,
   style: {},
   small: false,
   onClick: () => {},
diff --git a/src/components/Button/Action.less b/src/components/Button/Action.less
index 51e3ec29..ae237d0d 100644
--- a/src/components/Button/Action.less
+++ b/src/components/Button/Action.less
@@ -10,6 +10,20 @@
   color: @white;
   width: 100%;
 
+  &--primary {
+    .colorize-button(@purple, #2a3574);
+
+    color: @white-darker;
+
+    &:disabled,
+    &:hover,
+    &:focus,
+    &:active,
+    &.active {
+      color: @white-darker !important;
+    }
+  }
+
   &:hover,
   &:focus,
   &:active,
diff --git a/src/components/Editor/Editor.js b/src/components/Editor/Editor.js
index e0f145af..ee8606ac 100644
--- a/src/components/Editor/Editor.js
+++ b/src/components/Editor/Editor.js
@@ -441,6 +441,7 @@ class Editor extends React.Component {
           </span>
           <Form.Item className="Editor__bottom__submit">
             <Action
+              primary
               loading={loading}
               disabled={loading}
               text={intl.formatMessage({


Test patch:
diff --git a/src/stories/__snapshots__/stories.test.js.snap b/src/stories/__snapshots__/stories.test.js.snap
index ed73689e..f97a0dd6 100644
--- a/src/stories/__snapshots__/stories.test.js.snap
+++ b/src/stories/__snapshots__/stories.test.js.snap
@@ -582,7 +582,7 @@ exports[`Storyshots Editor Editor 1`] = `
             className="ant-form-item-control "
           >
             <button
-              className="Action ant-btn-lg"
+              className="Action ant-btn-lg Action--primary"
               disabled={false}
               onClick={[Function]}
               style={Object {}}
Repository: cli/cli
Pull request #772 (2020-04-10 05:26:31)

fix api.REST(DELETE, ...) failure with "unexpected end of JSON input" error
Fix for [issue](https://github.com/cli/cli/issues/769)

```
err := http.REST("DELETE", path, body, &resp)
```
results in (*json.SyntaxError)(0xc000708060)(unexpected end of JSON input)

Fix adds early return on status 204 combined with ContentLength == 0

```
	if resp.StatusCode == http.StatusNoContent && resp.ContentLength == 0 {
		return nil
	}
```

The added test demonstrates the failure without the fix and correct behavior with the fix.



Patch:
diff --git a/api/client.go b/api/client.go
index a0ed6a859..2fc72aaa6 100644
--- a/api/client.go
+++ b/api/client.go
@@ -146,6 +146,10 @@ func (c Client) REST(method string, p string, body io.Reader, data interface{})
 		return handleHTTPError(resp)
 	}
 
+	if resp.StatusCode == http.StatusNoContent {
+		return nil
+	}
+
 	b, err := ioutil.ReadAll(resp.Body)
 	if err != nil {
 		return err


Test patch:
diff --git a/api/client_test.go b/api/client_test.go
index 12bfbe408..492609e5c 100644
--- a/api/client_test.go
+++ b/api/client_test.go
@@ -50,3 +50,17 @@ func TestGraphQLError(t *testing.T) {
 		t.Fatalf("got %q", err.Error())
 	}
 }
+
+func TestRESTGetDelete(t *testing.T) {
+	http := &FakeHTTP{}
+
+	client := NewClient(
+		ReplaceTripper(http),
+	)
+
+	http.StubResponse(204, bytes.NewBuffer([]byte{}))
+
+	r := bytes.NewReader([]byte(`{}`))
+	err := client.REST("DELETE", "applications/CLIENTID/grant", r, nil)
+	eq(t, err, nil)
+}
Repository: cli/cli
Pull request #816 (2020-04-22 21:11:26)

missed a remote url
because of some commit reverts i ended up missing a place where we form a remote url ^_^()



Patch:
diff --git a/command/repo.go b/command/repo.go
index 5a278d612..b96a48164 100644
--- a/command/repo.go
+++ b/command/repo.go
@@ -459,7 +459,8 @@ func repoFork(cmd *cobra.Command, args []string) error {
 			}
 		}
 		if cloneDesired {
-			cloneDir, err := runClone(forkedRepo.CloneURL, []string{})
+			forkedRepoCloneURL := formatRemoteURL(cmd, ghrepo.FullName(forkedRepo))
+			cloneDir, err := runClone(forkedRepoCloneURL, []string{})
 			if err != nil {
 				return fmt.Errorf("failed to clone fork: %w", err)
 			}


Test patch:
diff --git a/command/repo_test.go b/command/repo_test.go
index f50eb0cac..118e365d5 100644
--- a/command/repo_test.go
+++ b/command/repo_test.go
@@ -185,8 +185,8 @@ func TestRepoFork_outside_yes(t *testing.T) {
 
 	eq(t, output.Stderr(), "")
 
-	eq(t, strings.Join(cs.Calls[0].Args, " "), "git clone https://github.com/someone/repo.git")
-	eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C repo remote add -f upstream https://github.com/OWNER/REPO.git")
+	eq(t, strings.Join(cs.Calls[0].Args, " "), "git clone https://github.com/someone/REPO.git")
+	eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C REPO remote add -f upstream https://github.com/OWNER/REPO.git")
 
 	test.ExpectLines(t, output.String(),
 		"Created fork someone/REPO",
@@ -218,8 +218,8 @@ func TestRepoFork_outside_survey_yes(t *testing.T) {
 
 	eq(t, output.Stderr(), "")
 
-	eq(t, strings.Join(cs.Calls[0].Args, " "), "git clone https://github.com/someone/repo.git")
-	eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C repo remote add -f upstream https://github.com/OWNER/REPO.git")
+	eq(t, strings.Join(cs.Calls[0].Args, " "), "git clone https://github.com/someone/REPO.git")
+	eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C REPO remote add -f upstream https://github.com/OWNER/REPO.git")
 
 	test.ExpectLines(t, output.String(),
 		"Created fork someone/REPO",
Repository: cli/cli
Pull request #1093 (2020-06-03 14:04:24)

gh api: fix passing file/stdin contents via field arguments
Reading from file via `-F foo=@myfile.txt` syntax would result in `[]byte` Go type, which by default gets serialized to JSON in base64 format, which we don't want here.

Traverse all parameters and convert any `[]byte` into `string` before JSON serialization.

Followup to https://github.com/cli/cli/pull/909


Patch:
diff --git a/pkg/cmd/api/http.go b/pkg/cmd/api/http.go
index 5f9ebc3ca..812b95af4 100644
--- a/pkg/cmd/api/http.go
+++ b/pkg/cmd/api/http.go
@@ -22,6 +22,12 @@ func httpRequest(client *http.Client, method string, p string, params interface{
 		if strings.EqualFold(method, "GET") {
 			url = addQuery(url, pp)
 		} else {
+			for key, value := range pp {
+				switch vv := value.(type) {
+				case []byte:
+					pp[key] = string(vv)
+				}
+			}
 			if isGraphQL {
 				pp = groupGraphQLVariables(pp)
 			}


Test patch:
diff --git a/pkg/cmd/api/http_test.go b/pkg/cmd/api/http_test.go
index e2ba8680b..0f9471111 100644
--- a/pkg/cmd/api/http_test.go
+++ b/pkg/cmd/api/http_test.go
@@ -157,7 +157,7 @@ func Test_httpRequest(t *testing.T) {
 				method: "POST",
 				p:      "graphql",
 				params: map[string]interface{}{
-					"a": "b",
+					"a": []byte("b"),
 				},
 				headers: []string{},
 			},