Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #5179: [frontend]: Push to Github button should only push branch, but not creating a PR #5181

Merged
merged 15 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions frontend/__tests__/components/chat/chat-interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,31 @@ describe.skip("ChatInterface", () => {
expect(within(error).getByText("Something went wrong")).toBeInTheDocument();
});

it("should render both GitHub buttons when ghToken is available", () => {
vi.mock("@remix-run/react", async (importActual) => ({
...(await importActual<typeof import("@remix-run/react")>()),
useRouteLoaderData: vi.fn(() => ({ ghToken: "test-token" })),
}));

const messages: Message[] = [
{
sender: "assistant",
content: "Hello",
imageUrls: [],
timestamp: new Date().toISOString(),
},
];
renderChatInterface(messages);

const pushButton = screen.getByRole("button", { name: "Push to GitHub" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name this Push to Branch

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const prButton = screen.getByRole("button", { name: "Push & Create PR" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think once the Push & Create PR button has been clicked once, we should only show one button after that. The agent (and user) will get v confused if you push and create PR, and then click "push to branch", since the PR is already opened.

Once you click "Push & Create PR" we should just have one button that says "Push changes to PR"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done the most recent commit


expect(pushButton).toBeInTheDocument();
expect(prButton).toBeInTheDocument();
expect(pushButton).toHaveTextContent("Push to GitHub");
expect(prButton).toHaveTextContent("Push & Create PR");
});

it("should render feedback actions if there are more than 3 messages", () => {
const messages: Message[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"APP_MODE": "oss",
"GITHUB_CLIENT_ID": "",
"POSTHOG_CLIENT_KEY": "phc_3ESMmY9SgqEAGBB6sMGK5ayYHkeUuknH2vP6FmWH9RA"
}
}
36 changes: 26 additions & 10 deletions frontend/src/components/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
);
});
} catch (e) {
console.warn("Runtime ID not available in this environment");

Check warning on line 68 in frontend/src/components/chat-interface.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Unexpected console statement
}
}
}, [status]);
Expand Down Expand Up @@ -175,16 +175,32 @@
curAgentState === AgentState.FINISHED) && (
<div className="flex flex-col gap-2 mb-2">
{gitHubToken ? (
<SuggestionItem
suggestion={{
label: "Push to GitHub",
value:
"Please push the changes to GitHub and open a pull request.",
}}
onClick={(value) => {
handleSendMessage(value, []);
}}
/>
<div className="flex flex-row gap-2">
<div className="flex-1">
<SuggestionItem
suggestion={{
label: "Push to GitHub",
value:
"Please push the changes to a remote branch on GitHub, but do NOT create a pull request.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the microagent instructions to send the user a compare link?

e.g.

If the user asks you to push your changes, but not create a PR, send them a message with a link to compare the files on the remote branch against the main branch.

}}
onClick={(value) => {
handleSendMessage(value, []);
}}
/>
</div>
<div className="flex-1">
<SuggestionItem
suggestion={{
label: "Push & Create PR",
value:
"Please push the changes to GitHub and open a pull request.",
}}
onClick={(value) => {
handleSendMessage(value, []);
}}
/>
</div>
</div>
) : (
<SuggestionItem
suggestion={{
Expand Down
4 changes: 3 additions & 1 deletion openhands/agenthub/codeact_agent/codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def get_action_message(
)
]
elif isinstance(action, CmdRunAction) and action.source == 'user':
content = [TextContent(text=f'User executed the command:\n{action.command}')]
content = [
TextContent(text=f'User executed the command:\n{action.command}')
]
return [
Message(
role='user',
Expand Down
1 change: 1 addition & 0 deletions openhands/events/action/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def images_urls(self):
@images_urls.setter
def images_urls(self, value):
self.image_urls = value

def __str__(self) -> str:
ret = f'**MessageAction** (source={self.source})\n'
ret += f'CONTENT: {self.content}'
Expand Down
2 changes: 1 addition & 1 deletion openhands/events/serialization/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def action_from_dict(action: dict) -> Action:
# images_urls has been renamed to image_urls
if 'images_urls' in args:
args['image_urls'] = args.pop('images_urls')

try:
decoded_action = action_class(**args)
if 'timeout' in action:
Expand Down
4 changes: 2 additions & 2 deletions openhands/resolver/patching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from .patch import parse_patch
from .apply import apply_diff
from .patch import parse_patch

__all__ = ["parse_patch", "apply_diff"]
__all__ = ['parse_patch', 'apply_diff']
34 changes: 17 additions & 17 deletions openhands/resolver/patching/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@

def _apply_diff_with_subprocess(diff, lines, reverse=False):
# call out to patch program
patchexec = which("patch")
patchexec = which('patch')
if not patchexec:
raise SubprocessException("cannot find patch program", code=-1)
raise SubprocessException('cannot find patch program', code=-1)

tempdir = tempfile.gettempdir()

filepath = os.path.join(tempdir, "wtp-" + str(hash(diff.header)))
oldfilepath = filepath + ".old"
newfilepath = filepath + ".new"
rejfilepath = filepath + ".rej"
patchfilepath = filepath + ".patch"
with open(oldfilepath, "w") as f:
f.write("\n".join(lines) + "\n")
filepath = os.path.join(tempdir, 'wtp-' + str(hash(diff.header)))
oldfilepath = filepath + '.old'
newfilepath = filepath + '.new'
rejfilepath = filepath + '.rej'
patchfilepath = filepath + '.patch'
with open(oldfilepath, 'w') as f:
f.write('\n'.join(lines) + '\n')

with open(patchfilepath, "w") as f:
with open(patchfilepath, 'w') as f:
f.write(diff.text)

args = [
patchexec,
"--reverse" if reverse else "--forward",
"--quiet",
"--no-backup-if-mismatch",
"-o",
'--reverse' if reverse else '--forward',
'--quiet',
'--no-backup-if-mismatch',
'-o',
newfilepath,
"-i",
'-i',
patchfilepath,
"-r",
'-r',
rejfilepath,
oldfilepath,
]
Expand All @@ -58,7 +58,7 @@ def _apply_diff_with_subprocess(diff, lines, reverse=False):

# do this last to ensure files get cleaned up
if ret != 0:
raise SubprocessException("patch program failed", code=ret)
raise SubprocessException('patch program failed', code=ret)

return lines, rejlines

Expand Down
2 changes: 1 addition & 1 deletion openhands/resolver/patching/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, msg, hunk=None):
self.hunk = hunk
if hunk is not None:
super(HunkException, self).__init__(
"{msg}, in hunk #{n}".format(msg=msg, n=hunk)
'{msg}, in hunk #{n}'.format(msg=msg, n=hunk)
)
else:
super(HunkException, self).__init__(msg)
Expand Down
Loading
Loading