Skip to content

Commit

Permalink
chore: git mod - migrating apis for git (#37984)
Browse files Browse the repository at this point in the history
## Description
- Add application apis for git package

Fixes #37823


## Automation

/ok-to-test tags="@tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12194637717>
> Commit: e72e02f
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12194637717&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Fri, 06 Dec 2024 08:23:16 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced various asynchronous functions for Git operations,
including:
		- `checkoutBranchRequest`
		- `commitRequest`
		- `connectRequest`
		- `createBranchRequest`
		- `deleteBranchRequest`
		- `fetchBranchesRequest`
		- `fetchGitMetadataRequest`
		- `fetchProtectedBranchesRequest`
		- `mergeRequest`
		- `pullRequest`
		- `toggleAutocommitRequest`
		- `triggerAutocommitRequest`
		- `updateGlobalConfigRequest`
		- `updateLocalConfigRequest`
		- `updateProtectedBranchesRequest`
- Added new enumeration `AutocommitStatus` and interfaces to enhance
type safety for Git operations.
- **Bug Fixes**
- Updated import paths for consistency and clarity across multiple
files.
- **Documentation**
- Enhanced type definitions for various request and response structures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
brayn003 authored Dec 6, 2024
1 parent a450226 commit fd9efb8
Show file tree
Hide file tree
Showing 55 changed files with 587 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
GitImportStep,
GitOpsTab,
GitSettingsTab,
} from "../../enums";
} from "../../constants/enums";
import type {
GitSingleArtifactAPIResponsesReduxState,
GitSingleArtifactUIReduxState,
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/git/components/QuickActions/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { render, screen, fireEvent } from "@testing-library/react";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import QuickActions from ".";
import { GitSettingsTab } from "git/enums";
import { GitSettingsTab } from "../../constants/enums";
import { GitSyncModalTab } from "entities/GitSync";
import { theme } from "constants/DefaultTheme";
import { ThemeProvider } from "styled-components";
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/git/components/QuickActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { GitSyncModalTab } from "entities/GitSync";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import type { GitMetadata, GitStatus } from "../../types";
import { getPullBtnStatus } from "./helpers";
import { GitSettingsTab } from "../../enums";
import { GitSettingsTab } from "../../constants/enums";
import ConnectButton from "./ConnectButton";
import QuickActionButton from "./QuickActionButton";
import AutocommitStatusbar from "./AutocommitStatusbar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ export enum GitSettingsTab {
General = "General",
Branch = "Branch",
}

export enum AutocommitStatus {
IN_PROGRESS = "IN_PROGRESS",
LOCKED = "LOCKED",
PUBLISHED = "PUBLISHED",
IDLE = "IDLE",
NOT_REQUIRED = "NOT_REQUIRED",
NON_GIT_APP = "NON_GIT_APP",
}
17 changes: 17 additions & 0 deletions app/client/src/git/requests/checkoutBranchRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { AxiosResponse } from "axios";
import type {
CheckoutBranchRequestParams,
CheckoutBranchResponse,
} from "./checkoutBranchRequest.types";
import { GIT_BASE_URL } from "./constants";
import Api from "api/Api";

export default async function checkoutBranchRequest(
branchedApplicationId: string,
params: CheckoutBranchRequestParams,
): Promise<AxiosResponse<CheckoutBranchResponse>> {
return Api.get(
`${GIT_BASE_URL}/checkout-branch/app/${branchedApplicationId}`,
params,
);
}
8 changes: 8 additions & 0 deletions app/client/src/git/requests/checkoutBranchRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface CheckoutBranchRequestParams {
branchName: string;
}

export interface CheckoutBranchResponse {
id: string; // applicationId
baseId: string; // baseApplicationId
}
17 changes: 17 additions & 0 deletions app/client/src/git/requests/commitRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Api from "api/Api";
import type {
CommitRequestParams,
CommitResponse,
} from "./commitRequest.types";
import { GIT_BASE_URL } from "./constants";
import type { AxiosResponse } from "axios";

export default async function commitRequest(
branchedApplicationId: string,
params: CommitRequestParams,
): Promise<AxiosResponse<CommitResponse>> {
return Api.post(
`${GIT_BASE_URL}/commit/app/${branchedApplicationId}`,
params,
);
}
6 changes: 6 additions & 0 deletions app/client/src/git/requests/commitRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface CommitRequestParams {
commitMessage: string;
doPush: boolean;
}

export type CommitResponse = string;
14 changes: 14 additions & 0 deletions app/client/src/git/requests/connectRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";
import type {
ConnectRequestParams,
ConnectResponse,
} from "./connectRequest.types";
import type { AxiosResponse } from "axios";

export default async function connectRequest(
baseApplicationId: string,
params: ConnectRequestParams,
): Promise<AxiosResponse<ConnectResponse>> {
return Api.post(`${GIT_BASE_URL}/connect/app/${baseApplicationId}`, params);
}
24 changes: 24 additions & 0 deletions app/client/src/git/requests/connectRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export interface ConnectRequestParams {
remoteUrl: string;
gitProfile?: {
authorName: string;
authorEmail: string;
useDefaultProfile?: boolean;
};
}

export interface ConnectResponse {
id: string;
baseId: string;
gitApplicationMetadata: {
branchName: string;
browserSupportedRemoteUrl: string;
defaultApplicationId: string;
defaultArtifactId: string;
defaultBranchName: string;
isRepoPrivate: boolean;
lastCommitedAt: string;
remoteUrl: string;
repoName: string;
};
}
2 changes: 2 additions & 0 deletions app/client/src/git/requests/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const GIT_BASE_URL = "/v1/git";
export const APPLICATION_BASE_URL = "/v1/applications";
17 changes: 17 additions & 0 deletions app/client/src/git/requests/createBranchRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { AxiosResponse } from "axios";
import type {
CreateBranchRequestParams,
CreateBranchResponse,
} from "./createBranchRequest.types";
import { GIT_BASE_URL } from "./constants";
import Api from "api/Api";

export default async function createBranchRequest(
branchedApplicationId: string,
params: CreateBranchRequestParams,
): Promise<AxiosResponse<CreateBranchResponse>> {
return Api.post(
`${GIT_BASE_URL}/create-branch/app/${branchedApplicationId}`,
params,
);
}
8 changes: 8 additions & 0 deletions app/client/src/git/requests/createBranchRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface CreateBranchRequestParams {
branchName: string;
}

export interface CreateBranchResponse {
id: string; // applicationId
baseId: string; // baseApplicationId
}
14 changes: 14 additions & 0 deletions app/client/src/git/requests/deleteBranchRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { AxiosResponse } from "axios";
import type {
DeleteBranchRequestParams,
DeleteBranchResponse,
} from "./deleteBranchRequest.types";
import { GIT_BASE_URL } from "./constants";
import Api from "api/Api";

export default async function deleteBranchRequest(
baseApplicationId: string,
params: DeleteBranchRequestParams,
): Promise<AxiosResponse<DeleteBranchResponse>> {
return Api.delete(`${GIT_BASE_URL}/branch/app/${baseApplicationId}`, params);
}
8 changes: 8 additions & 0 deletions app/client/src/git/requests/deleteBranchRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface DeleteBranchRequestParams {
branchName: string;
}

export interface DeleteBranchResponse {
id: string; // applicationId
baseId: string; // baseApplicationId
}
9 changes: 9 additions & 0 deletions app/client/src/git/requests/discardRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";
import type { AxiosResponse } from "axios";

export default async function discardRequest(
branchedApplicationId: string,
): Promise<AxiosResponse<void>> {
return Api.put(`${GIT_BASE_URL}/discard/app/${branchedApplicationId}`);
}
10 changes: 10 additions & 0 deletions app/client/src/git/requests/disconnectRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { AxiosResponse } from "axios";
import { GIT_BASE_URL } from "./constants";
import type { DisconnectResponse } from "./disconnectRequest.types";
import Api from "api/Api";

export default async function disconnectRequest(
baseApplicationId: string,
): Promise<AxiosResponse<DisconnectResponse>> {
return Api.post(`${GIT_BASE_URL}/disconnect/app/${baseApplicationId}`);
}
3 changes: 3 additions & 0 deletions app/client/src/git/requests/disconnectRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface DisconnectResponse {
[key: string]: string;
}
12 changes: 12 additions & 0 deletions app/client/src/git/requests/fetchAutocommitProgressRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";
import type { AxiosResponse } from "axios";
import type { FetchAutocommitProgressResponse } from "./fetchAutocommitProgressRequest.types";

export default async function fetchAutocommitProgressRequest(
baseApplicationId: string,
): Promise<AxiosResponse<FetchAutocommitProgressResponse>> {
return Api.get(
`${GIT_BASE_URL}/auto-commit/progress/app/${baseApplicationId}`,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { AutocommitStatus } from "../constants/enums";

export interface FetchAutocommitProgressResponse {
autoCommitResponse: AutocommitStatus;
progress: number;
branchName: string;
}
21 changes: 21 additions & 0 deletions app/client/src/git/requests/fetchBranchesRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";
import type {
FetchBranchesRequestParams,
FetchBranchesResponse,
} from "./fetchBranchesRequest.types";
import type { AxiosResponse } from "axios";

export default async function fetchBranchesRequest(
branchedApplicationId: string,
params?: FetchBranchesRequestParams,
): Promise<AxiosResponse<FetchBranchesResponse>> {
const queryParams = {} as FetchBranchesRequestParams;

if (params?.pruneBranches) queryParams.pruneBranches = true;

return Api.get(
`${GIT_BASE_URL}/branch/app/${branchedApplicationId}`,
queryParams,
);
}
11 changes: 11 additions & 0 deletions app/client/src/git/requests/fetchBranchesRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface FetchBranchesRequestParams {
pruneBranches: boolean;
}

interface SingleBranch {
branchName: string;
createdFromLocal: string;
default: boolean;
}

export type FetchBranchesResponse = SingleBranch[];
10 changes: 10 additions & 0 deletions app/client/src/git/requests/fetchGitMetadataRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";
import type { AxiosResponse } from "axios";
import type { FetchGitMetadataResponse } from "./fetchGitMetadataRequest.types";

export default async function fetchGitMetadataRequest(
baseApplicationId: string,
): Promise<AxiosResponse<FetchGitMetadataResponse>> {
return Api.get(`${GIT_BASE_URL}/metadata/app/${baseApplicationId}`);
}
15 changes: 15 additions & 0 deletions app/client/src/git/requests/fetchGitMetadataRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface FetchGitMetadataResponse {
branchName: string;
defaultBranchName: string;
remoteUrl: string;
repoName: string;
browserSupportedUrl?: string;
isRepoPrivate?: boolean;
browserSupportedRemoteUrl: string;
defaultApplicationId: string;
isProtectedBranch: boolean;
autoCommitConfig: {
enabled: boolean;
};
isAutoDeploymentEnabled?: boolean;
}
10 changes: 10 additions & 0 deletions app/client/src/git/requests/fetchGlobalConfigRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";
import type { AxiosResponse } from "axios";
import type { FetchGlobalConfigResponse } from "./fetchGlobalConfigRequest.types";

export default async function fetchGlobalConfigRequest(): Promise<
AxiosResponse<FetchGlobalConfigResponse>
> {
return Api.get(`${GIT_BASE_URL}/profile/default`);
}
4 changes: 4 additions & 0 deletions app/client/src/git/requests/fetchGlobalConfigRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface FetchGlobalConfigResponse {
authorName: string;
authorEmail: string;
}
10 changes: 10 additions & 0 deletions app/client/src/git/requests/fetchLocalConfigRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Api from "api/Api";
import type { AxiosResponse } from "axios";
import { GIT_BASE_URL } from "./constants";
import type { FetchLocalConfigResponse } from "./fetchLocalConfigRequest.types";

export default async function fetchLocalConfigRequest(
baseApplicationId: string,
): Promise<AxiosResponse<FetchLocalConfigResponse>> {
return Api.get(`${GIT_BASE_URL}/profile/app/${baseApplicationId}`);
}
5 changes: 5 additions & 0 deletions app/client/src/git/requests/fetchLocalConfigRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface FetchLocalConfigResponse {
authorName: string;
authorEmail: string;
useGlobalProfile: boolean;
}
17 changes: 17 additions & 0 deletions app/client/src/git/requests/fetchMergeStatusRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { AxiosResponse } from "axios";
import type {
FetchMergeStatusRequestParams,
FetchMergeStatusResponse,
} from "./fetchMergeStatusRequest.types";
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";

export default async function fetchMergeStatusRequest(
branchedApplicationId: string,
params: FetchMergeStatusRequestParams,
): Promise<AxiosResponse<FetchMergeStatusResponse>> {
return Api.post(
`${GIT_BASE_URL}/merge/status/app/${branchedApplicationId}`,
params,
);
}
10 changes: 10 additions & 0 deletions app/client/src/git/requests/fetchMergeStatusRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface FetchMergeStatusRequestParams {
sourceBranch: string;
destinationBranch: string;
}

export interface FetchMergeStatusResponse {
isMergeAble: boolean;
status: string; // merge status
message: string;
}
10 changes: 10 additions & 0 deletions app/client/src/git/requests/fetchProtectedBranchesRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Api from "api/Api";
import { GIT_BASE_URL } from "./constants";
import type { AxiosResponse } from "axios";
import type { FetchProtectedBranches } from "./fetchProtectedBranchesRequest.types";

export default async function fetchProtectedBranchesRequest(
baseApplicationId: string,
): Promise<AxiosResponse<FetchProtectedBranches>> {
return Api.get(`${GIT_BASE_URL}/branch/app/${baseApplicationId}/protected`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type FetchProtectedBranches = string[];
10 changes: 10 additions & 0 deletions app/client/src/git/requests/fetchSSHKeyRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { AxiosResponse } from "axios";
import type { FetchSSHKeyResponse } from "./fetchSSHKeyRequest.types";
import Api from "api/Api";
import { APPLICATION_BASE_URL } from "./constants";

export default async function fetchSSHKeyRequest(
baseApplicationId: string,
): Promise<AxiosResponse<FetchSSHKeyResponse>> {
return Api.get(`${APPLICATION_BASE_URL}/ssh-keypair/${baseApplicationId}`);
}
6 changes: 6 additions & 0 deletions app/client/src/git/requests/fetchSSHKeyRequest.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface FetchSSHKeyResponse {
publicKey: string;
docUrl: string;
isRegeneratedKey: boolean;
regeneratedKey: boolean;
}
Loading

0 comments on commit fd9efb8

Please sign in to comment.