mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
(Chore): Rename GitHub instances to Git (#7625)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
parent
8e61f8e688
commit
a2e9e23569
@ -1,7 +1,7 @@
|
||||
import { screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { renderWithProviders } from "test-utils";
|
||||
import { GitRepositorySelector } from "#/components/features/github/github-repo-selector";
|
||||
import { GitRepositorySelector } from "#/components/features/git/git-repo-selector";
|
||||
import OpenHands from "#/api/open-hands";
|
||||
import { Provider } from "#/types/settings";
|
||||
|
||||
@ -67,7 +67,7 @@ describe("GitRepositorySelector", () => {
|
||||
|
||||
const searchPublicRepositoriesSpy = vi.spyOn(
|
||||
OpenHands,
|
||||
"searchGitHubRepositories",
|
||||
"searchGitRepositories",
|
||||
);
|
||||
searchPublicRepositoriesSpy.mockResolvedValue(mockSearchedRepos);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { GitRepository } from "#/types/github";
|
||||
import { GitRepository } from "#/types/git";
|
||||
import { extractNextPageFromLink } from "#/utils/extract-next-page-from-link";
|
||||
import { openHands } from "./open-hands-axios";
|
||||
|
||||
@ -3,22 +3,3 @@ import axios from "axios";
|
||||
export const openHands = axios.create({
|
||||
baseURL: `${window.location.protocol}//${import.meta.env.VITE_BACKEND_BASE_URL || window?.location.host}`,
|
||||
});
|
||||
export const setAuthTokenHeader = (token: string) => {
|
||||
openHands.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||
};
|
||||
|
||||
export const setGitHubTokenHeader = (token: string) => {
|
||||
openHands.defaults.headers.common["X-GitHub-Token"] = token;
|
||||
};
|
||||
|
||||
export const removeAuthTokenHeader = () => {
|
||||
if (openHands.defaults.headers.common.Authorization) {
|
||||
delete openHands.defaults.headers.common.Authorization;
|
||||
}
|
||||
};
|
||||
|
||||
export const removeGitHubTokenHeader = () => {
|
||||
if (openHands.defaults.headers.common["X-GitHub-Token"]) {
|
||||
delete openHands.defaults.headers.common["X-GitHub-Token"];
|
||||
}
|
||||
};
|
||||
|
||||
@ -14,7 +14,7 @@ import {
|
||||
} from "./open-hands.types";
|
||||
import { openHands } from "./open-hands-axios";
|
||||
import { ApiSettings, PostApiSettings } from "#/types/settings";
|
||||
import { GitHubUser, GitRepository } from "#/types/github";
|
||||
import { GitUser, GitRepository } from "#/types/git";
|
||||
|
||||
class OpenHands {
|
||||
/**
|
||||
@ -306,12 +306,12 @@ class OpenHands {
|
||||
return data.credits;
|
||||
}
|
||||
|
||||
static async getGitHubUser(): Promise<GitHubUser> {
|
||||
const response = await openHands.get<GitHubUser>("/api/user/info");
|
||||
static async getGitUser(): Promise<GitUser> {
|
||||
const response = await openHands.get<GitUser>("/api/user/info");
|
||||
|
||||
const { data } = response;
|
||||
|
||||
const user: GitHubUser = {
|
||||
const user: GitUser = {
|
||||
id: data.id,
|
||||
login: data.login,
|
||||
avatar_url: data.avatar_url,
|
||||
@ -328,7 +328,7 @@ class OpenHands {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
static async searchGitHubRepositories(
|
||||
static async searchGitRepositories(
|
||||
query: string,
|
||||
per_page = 5,
|
||||
): Promise<GitRepository[]> {
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
import { ErrorResponse, FileUploadSuccessResponse } from "./open-hands.types";
|
||||
|
||||
export const isOpenHandsErrorResponse = (
|
||||
data: ErrorResponse | FileUploadSuccessResponse,
|
||||
): data is ErrorResponse =>
|
||||
typeof data === "object" && data !== null && "error" in data;
|
||||
@ -5,7 +5,7 @@ import { setInitialPrompt } from "#/state/initial-query-slice";
|
||||
|
||||
const INITIAL_PROMPT = "";
|
||||
|
||||
export function CodeNotInGitHubLink() {
|
||||
export function CodeNotInGitLink() {
|
||||
const dispatch = useDispatch();
|
||||
const { mutate: createConversation } = useCreateConversation();
|
||||
|
||||
@ -17,7 +17,7 @@ export function CodeNotInGitHubLink() {
|
||||
|
||||
return (
|
||||
<div className="text-xs text-neutral-400">
|
||||
Code not in GitHub?{" "}
|
||||
Code not in Git?{" "}
|
||||
<span
|
||||
onClick={handleStartFromScratch}
|
||||
className="underline cursor-pointer"
|
||||
@ -12,7 +12,7 @@ import { I18nKey } from "#/i18n/declaration";
|
||||
import { setSelectedRepository } from "#/state/initial-query-slice";
|
||||
import { useConfig } from "#/hooks/query/use-config";
|
||||
import { sanitizeQuery } from "#/utils/sanitize-query";
|
||||
import { GitRepository } from "#/types/github";
|
||||
import { GitRepository } from "#/types/git";
|
||||
import { Provider, ProviderOptions } from "#/types/settings";
|
||||
|
||||
interface GitRepositorySelectorProps {
|
||||
@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router";
|
||||
import { I18nKey } from "#/i18n/declaration";
|
||||
import { SuggestionBox } from "#/components/features/suggestions/suggestion-box";
|
||||
import { GitRepositorySelector } from "./github-repo-selector";
|
||||
import { GitRepositorySelector } from "./git-repo-selector";
|
||||
import { useAppRepositories } from "#/hooks/query/use-app-repositories";
|
||||
import { useSearchRepositories } from "#/hooks/query/use-search-repositories";
|
||||
import { useUserRepositories } from "#/hooks/query/use-user-repositories";
|
||||
@ -11,12 +11,12 @@ import { sanitizeQuery } from "#/utils/sanitize-query";
|
||||
import { useDebounce } from "#/hooks/use-debounce";
|
||||
import { BrandButton } from "../settings/brand-button";
|
||||
import GitHubLogo from "#/assets/branding/github-logo.svg?react";
|
||||
import { GitHubErrorReponse, GitHubUser } from "#/types/github";
|
||||
import { GitHubErrorReponse, GitUser } from "#/types/git";
|
||||
|
||||
interface GitRepositoriesSuggestionBoxProps {
|
||||
handleSubmit: () => void;
|
||||
gitHubAuthUrl: string | null;
|
||||
user: GitHubErrorReponse | GitHubUser | null;
|
||||
user: GitHubErrorReponse | GitUser | null;
|
||||
}
|
||||
|
||||
export function GitRepositoriesSuggestionBox({
|
||||
@ -3,7 +3,7 @@ import { FaListUl } from "react-icons/fa";
|
||||
import { useDispatch } from "react-redux";
|
||||
import posthog from "posthog-js";
|
||||
import { NavLink, useLocation } from "react-router";
|
||||
import { useGitHubUser } from "#/hooks/query/use-github-user";
|
||||
import { useGitUser } from "#/hooks/query/use-git-user";
|
||||
import { UserActions } from "./user-actions";
|
||||
import { AllHandsLogoButton } from "#/components/shared/buttons/all-hands-logo-button";
|
||||
import { DocsButton } from "#/components/shared/buttons/docs-button";
|
||||
@ -26,7 +26,7 @@ export function Sidebar() {
|
||||
const location = useLocation();
|
||||
const dispatch = useDispatch();
|
||||
const endSession = useEndSession();
|
||||
const user = useGitHubUser();
|
||||
const user = useGitUser();
|
||||
const { data: config } = useConfig();
|
||||
const {
|
||||
data: settings,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { useInfiniteQuery } from "@tanstack/react-query";
|
||||
import React from "react";
|
||||
import { retrieveGitHubAppRepositories } from "#/api/github";
|
||||
import { retrieveGitHubAppRepositories } from "#/api/git";
|
||||
import { useAppInstallations } from "./use-app-installations";
|
||||
import { useConfig } from "./use-config";
|
||||
import { useAuth } from "#/context/auth-context";
|
||||
|
||||
@ -6,7 +6,7 @@ import OpenHands from "#/api/open-hands";
|
||||
import { useAuth } from "#/context/auth-context";
|
||||
import { useLogout } from "../mutation/use-logout";
|
||||
|
||||
export const useGitHubUser = () => {
|
||||
export const useGitUser = () => {
|
||||
const { providersAreSet, providerTokensSet } = useAuth();
|
||||
const { mutateAsync: logout } = useLogout();
|
||||
|
||||
@ -14,7 +14,7 @@ export const useGitHubUser = () => {
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user", providerTokensSet],
|
||||
queryFn: OpenHands.getGitHubUser,
|
||||
queryFn: OpenHands.getGitUser,
|
||||
enabled: providersAreSet && !!config?.APP_MODE,
|
||||
retry: false,
|
||||
staleTime: 1000 * 60 * 5, // 5 minutes
|
||||
@ -4,7 +4,7 @@ import OpenHands from "#/api/open-hands";
|
||||
export function useSearchRepositories(query: string) {
|
||||
return useQuery({
|
||||
queryKey: ["repositories", query],
|
||||
queryFn: () => OpenHands.searchGitHubRepositories(query, 3),
|
||||
queryFn: () => OpenHands.searchGitRepositories(query, 3),
|
||||
enabled: !!query,
|
||||
select: (data) => data.map((repo) => ({ ...repo, is_public: true })),
|
||||
staleTime: 1000 * 60 * 5, // 5 minutes
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { useInfiniteQuery } from "@tanstack/react-query";
|
||||
import React from "react";
|
||||
import { retrieveUserGitRepositories } from "#/api/github";
|
||||
import { retrieveUserGitRepositories } from "#/api/git";
|
||||
import { useConfig } from "./use-config";
|
||||
import { useAuth } from "#/context/auth-context";
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
import { DEFAULT_SETTINGS } from "#/services/settings";
|
||||
import { STRIPE_BILLING_HANDLERS } from "./billing-handlers";
|
||||
import { ApiSettings, PostApiSettings } from "#/types/settings";
|
||||
import { GitHubUser } from "#/types/github";
|
||||
import { GitUser } from "#/types/git";
|
||||
|
||||
export const MOCK_DEFAULT_USER_SETTINGS: ApiSettings | PostApiSettings = {
|
||||
llm_model: DEFAULT_SETTINGS.LLM_MODEL,
|
||||
@ -156,7 +156,7 @@ export const handlers = [
|
||||
]),
|
||||
),
|
||||
http.get("/api/user/info", () => {
|
||||
const user: GitHubUser = {
|
||||
const user: GitUser = {
|
||||
id: 1,
|
||||
login: "octocat",
|
||||
avatar_url: "https://avatars.githubusercontent.com/u/583231?v=4",
|
||||
|
||||
@ -2,12 +2,12 @@ import React from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import posthog from "posthog-js";
|
||||
import { setReplayJson } from "#/state/initial-query-slice";
|
||||
import { useGitHubUser } from "#/hooks/query/use-github-user";
|
||||
import { useGitUser } from "#/hooks/query/use-git-user";
|
||||
import { useGitHubAuthUrl } from "#/hooks/use-github-auth-url";
|
||||
import { useConfig } from "#/hooks/query/use-config";
|
||||
import { GitRepositoriesSuggestionBox } from "#/components/features/github/github-repositories-suggestion-box";
|
||||
import { GitRepositoriesSuggestionBox } from "#/components/features/git/git-repositories-suggestion-box";
|
||||
import { ReplaySuggestionBox } from "../../components/features/suggestions/replay-suggestion-box";
|
||||
import { CodeNotInGitHubLink } from "#/components/features/github/code-not-in-github-link";
|
||||
import { CodeNotInGitLink } from "#/components/features/git/code-not-in-github-link";
|
||||
import { HeroHeading } from "#/components/shared/hero-heading";
|
||||
import { TaskForm } from "#/components/shared/task-form";
|
||||
import { convertFileToText } from "#/utils/convert-file-to-text";
|
||||
@ -18,7 +18,7 @@ function Home() {
|
||||
const formRef = React.useRef<HTMLFormElement>(null);
|
||||
|
||||
const { data: config } = useConfig();
|
||||
const { data: user } = useGitHubUser();
|
||||
const { data: user } = useGitUser();
|
||||
|
||||
const gitHubAuthUrl = useGitHubAuthUrl({
|
||||
appMode: config?.APP_MODE || null,
|
||||
@ -58,7 +58,7 @@ function Home() {
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full flex justify-start mt-2 ml-2">
|
||||
<CodeNotInGitHubLink />
|
||||
<CodeNotInGitLink />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { Provider } from "#/types/settings";
|
||||
import { GitRepository } from "#/types/github";
|
||||
import { GitRepository } from "#/types/git";
|
||||
|
||||
type SliceState = {
|
||||
files: string[]; // base64 encoded images
|
||||
|
||||
@ -6,7 +6,7 @@ interface GitHubErrorReponse {
|
||||
status: number;
|
||||
}
|
||||
|
||||
interface GitHubUser {
|
||||
interface GitUser {
|
||||
id: number;
|
||||
login: string;
|
||||
avatar_url: string;
|
||||
@ -13,7 +13,7 @@ from openhands import __version__
|
||||
from openhands.server.routes.conversation import app as conversation_api_router
|
||||
from openhands.server.routes.feedback import app as feedback_api_router
|
||||
from openhands.server.routes.files import app as files_api_router
|
||||
from openhands.server.routes.github import app as github_api_router
|
||||
from openhands.server.routes.git import app as git_api_router
|
||||
from openhands.server.routes.manage_conversations import (
|
||||
app as manage_conversation_api_router,
|
||||
)
|
||||
@ -50,5 +50,5 @@ app.include_router(feedback_api_router)
|
||||
app.include_router(conversation_api_router)
|
||||
app.include_router(manage_conversation_api_router)
|
||||
app.include_router(settings_router)
|
||||
app.include_router(github_api_router)
|
||||
app.include_router(git_api_router)
|
||||
app.include_router(trajectory_router)
|
||||
|
||||
@ -5,9 +5,9 @@ from openhands.server.listen_socket import sio
|
||||
from openhands.server.middleware import (
|
||||
AttachConversationMiddleware,
|
||||
CacheControlMiddleware,
|
||||
GitHubTokenMiddleware,
|
||||
InMemoryRateLimiter,
|
||||
LocalhostCORSMiddleware,
|
||||
ProviderTokenMiddleware,
|
||||
RateLimitMiddleware,
|
||||
)
|
||||
from openhands.server.static import SPAStaticFiles
|
||||
@ -29,6 +29,6 @@ base_app.add_middleware(
|
||||
rate_limiter=InMemoryRateLimiter(requests=10, seconds=1),
|
||||
)
|
||||
base_app.middleware('http')(AttachConversationMiddleware(base_app))
|
||||
base_app.middleware('http')(GitHubTokenMiddleware(base_app))
|
||||
base_app.middleware('http')(ProviderTokenMiddleware(base_app))
|
||||
|
||||
app = socketio.ASGIApp(sio, other_asgi_app=base_app)
|
||||
|
||||
@ -185,7 +185,7 @@ class AttachConversationMiddleware(SessionMiddlewareInterface):
|
||||
return response
|
||||
|
||||
|
||||
class GitHubTokenMiddleware(SessionMiddlewareInterface):
|
||||
class ProviderTokenMiddleware(SessionMiddlewareInterface):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user