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 #5112: [Bug]: "Push to GitHub" shows up even if there's no repo connected #5118

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions frontend/__tests__/components/chat/chat-interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe("Empty state", () => {
const { store } = renderWithProviders(<ChatInterface />, {
preloadedState: {
chat: { messages: [] },
initialQuery: { selectedRepository: null, files: [], initialQuery: null, importedProjectZip: null },
},
});

Expand All @@ -62,6 +63,7 @@ describe("Empty state", () => {
renderWithProviders(<ChatInterface />, {
preloadedState: {
chat: { messages: [] },
initialQuery: { selectedRepository: null, files: [], initialQuery: null, importedProjectZip: null },
},
});

Expand Down Expand Up @@ -91,6 +93,7 @@ describe("Empty state", () => {
const { store } = renderWithProviders(<ChatInterface />, {
preloadedState: {
chat: { messages: [] },
initialQuery: { selectedRepository: null, files: [], initialQuery: null, importedProjectZip: null },
},
});

Expand Down Expand Up @@ -119,6 +122,7 @@ describe("Empty state", () => {
const { rerender } = renderWithProviders(<ChatInterface />, {
preloadedState: {
chat: { messages: [] },
initialQuery: { selectedRepository: null, files: [], initialQuery: null, importedProjectZip: null },
},
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/__tests__/initial-query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ describe("Initial Query Behavior", () => {
it("should clear initial query when clearInitialQuery is dispatched", () => {
// Set up initial query in the store
store.dispatch(setInitialQuery("test query"));
expect(store.getState().initalQuery.initialQuery).toBe("test query");
expect(store.getState().initialQuery.initialQuery).toBe("test query");

// Clear the initial query
store.dispatch(clearInitialQuery());

// Verify initial query is cleared
expect(store.getState().initalQuery.initialQuery).toBeNull();
expect(store.getState().initialQuery.initialQuery).toBeNull();
});
});
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"
}
}
3 changes: 2 additions & 1 deletion frontend/src/components/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

const { messages } = useSelector((state: RootState) => state.chat);
const { curAgentState } = useSelector((state: RootState) => state.agent);
const { selectedRepository } = useSelector((state: RootState) => state.initialQuery);

Check failure on line 49 in frontend/src/components/chat-interface.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Replace `(state:·RootState)·=>·state.initialQuery` with `⏎····(state:·RootState)·=>·state.initialQuery,⏎··`

const [feedbackPolarity, setFeedbackPolarity] = React.useState<
"positive" | "negative"
Expand All @@ -66,7 +67,7 @@
);
});
} catch (e) {
console.warn("Runtime ID not available in this environment");

Check warning on line 70 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,7 +176,7 @@
{(curAgentState === AgentState.AWAITING_USER_INPUT ||
curAgentState === AgentState.FINISHED) && (
<div className="flex flex-col gap-2 mb-2">
{rootLoaderData?.ghToken ? (
{rootLoaderData?.ghToken && selectedRepository ? (
<SuggestionItem
suggestion={{
label: "Push to GitHub",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/event-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function EventHandler({ children }: React.PropsWithChildren) {
const fetcher = useFetcher();
const dispatch = useDispatch();
const { files, importedProjectZip, initialQuery } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);
const { ghToken, repo } = useLoaderData<typeof appClientLoader>();

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/project-menu/ProjectMenuCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Please push the changes to GitHub and open a pull request.
{!working && contextMenuIsOpen && (
<ProjectMenuCardContextMenu
isConnectedToGitHub={isConnectedToGitHub}
githubData={githubData}
onConnectToGitHub={() => setConnectToGitHubModalOpen(true)}
onPushToGitHub={handlePushToGitHub}
onDownloadWorkspace={handleDownloadWorkspace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { I18nKey } from "#/i18n/declaration";

interface ProjectMenuCardContextMenuProps {
isConnectedToGitHub: boolean;
githubData: {
avatar: string;
repoName: string;
lastCommit: GitHubCommit;
} | null;
onConnectToGitHub: () => void;
onPushToGitHub: () => void;
onDownloadWorkspace: () => void;
Expand All @@ -14,6 +19,7 @@ interface ProjectMenuCardContextMenuProps {

export function ProjectMenuCardContextMenu({
isConnectedToGitHub,
githubData,
onConnectToGitHub,
onPushToGitHub,
onDownloadWorkspace,
Expand All @@ -31,7 +37,7 @@ export function ProjectMenuCardContextMenu({
{t(I18nKey.PROJECT_MENU_CARD_CONTEXT_MENU$CONNECT_TO_GITHUB_LABEL)}
</ContextMenuListItem>
)}
{isConnectedToGitHub && (
{isConnectedToGitHub && githubData && (
<ContextMenuListItem onClick={onPushToGitHub}>
{t(I18nKey.PROJECT_MENU_CARD_CONTEXT_MENU$PUSH_TO_GITHUB_LABEL)}
</ContextMenuListItem>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/_oh._index/task-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const TaskForm = React.forwardRef<HTMLFormElement>((_, ref) => {
const navigation = useNavigation();

const { selectedRepository, files } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const [text, setText] = React.useState("");
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/_oh.app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
export const clientLoader = async () => {
const ghToken = localStorage.getItem("ghToken");
const repo =
store.getState().initalQuery.selectedRepository ||
store.getState().initialQuery.selectedRepository ||
localStorage.getItem("repo");

const settings = getSettings();
Expand All @@ -41,7 +41,7 @@
const data = await retrieveLatestGitHubCommit(ghToken, repo);
if (isGitHubErrorReponse(data)) {
// TODO: Handle error
console.error("Failed to retrieve latest commit", data);

Check warning on line 44 in frontend/src/routes/_oh.app.tsx

View workflow job for this annotation

GitHub Actions / Lint frontend

Unexpected console statement
} else {
[lastCommit] = data;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import statusReducer from "./state/statusSlice";

export const rootReducer = combineReducers({
fileState: fileStateReducer,
initalQuery: initialQueryReducer,
initialQuery: initialQueryReducer,
browser: browserReducer,
chat: chatReducer,
code: codeReducer,
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