PromucFlow_constructor/app/client/src/git/sagas/connectSaga.ts
Rudraprasad Das 704e4735ad
chore: git api - adding new apis (#38681)
## Description
- Introduces new api contracts for git
- Adds feature flag `release_git_api_contracts_enabled`


Fixes https://github.com/appsmithorg/appsmith/issues/38500

## 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/12810595516>
> Commit: 8f05bbfb0b9259c3ee40464099416b75688a4bd1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12810595516&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Thu, 16 Jan 2025 15:05:20 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

## Release Notes

- **New Features**
    - Introduced a new feature flag `release_git_api_contracts_enabled`
    - Added support for enhanced Git API contract handling

- **Improvements**
    - Updated type definitions for Git-related operations
    - Refined request and response handling for Git artifacts
    - Improved type safety for Git references and branches

- **Changes**
- Modified several Git-related request and saga functions to support new
API contracts
    - Updated artifact type enum values to use lowercase representations
    - Introduced new interfaces for Git references and branches

- **Technical Updates**
    - Added conditional logic for feature flag-based request processing
    - Restructured type definitions across multiple Git-related modules
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-01-21 11:19:18 +01:00

130 lines
3.8 KiB
TypeScript

import { gitArtifactActions } from "../store/gitArtifactSlice";
import connectRequest from "../requests/connectRequest";
import type {
ConnectRequestParams,
ConnectResponse,
} from "../requests/connectRequest.types";
import { GitArtifactType, GitErrorCodes } from "../constants/enums";
import type { GitArtifactPayloadAction } from "../store/types";
import type { ConnectInitPayload } from "../store/actions/connectActions";
import { call, put, select } from "redux-saga/effects";
// Internal dependencies
import { validateResponse } from "sagas/ErrorSagas";
import { fetchPageAction } from "actions/pageActions";
import history from "utils/history";
import { addBranchParam } from "constants/routes";
import log from "loglevel";
import { captureException } from "@sentry/react";
import { getCurrentPageId } from "selectors/editorSelectors";
import { gitGlobalActions } from "git/store/gitGlobalSlice";
import { getCurrentApplication } from "ee/selectors/applicationSelectors";
import type { ApplicationPayload } from "entities/Application";
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
import { selectGitApiContractsEnabled } from "git/store/selectors/gitFeatureFlagSelectors";
export default function* connectSaga(
action: GitArtifactPayloadAction<ConnectInitPayload>,
) {
const { artifactDef } = action.payload;
let response: ConnectResponse | undefined;
try {
const params: ConnectRequestParams = {
remoteUrl: action.payload.remoteUrl,
gitProfile: action.payload.gitProfile,
};
const isGitApiContractsEnabled: boolean = yield select(
selectGitApiContractsEnabled,
);
response = yield call(
connectRequest,
artifactDef.artifactType,
artifactDef.baseArtifactId,
params,
isGitApiContractsEnabled,
);
const isValidResponse: boolean = yield validateResponse(response, false);
if (response && isValidResponse) {
yield put(
gitArtifactActions.connectSuccess({
artifactDef,
responseData: response.data,
}),
);
// needs to happen only when artifactType is application
if (artifactDef.artifactType === GitArtifactType.Application) {
const pageId: string = yield select(getCurrentPageId);
yield put(fetchPageAction(pageId));
const branch = response.data?.gitApplicationMetadata?.branchName;
if (branch) {
const newUrl = addBranchParam(branch);
history.replace(newUrl);
}
const currentApplication: ApplicationPayload = yield select(
getCurrentApplication,
);
if (currentApplication) {
currentApplication.lastDeployedAt = new Date().toISOString();
yield put({
type: ReduxActionTypes.FETCH_APPLICATION_SUCCESS,
payload: currentApplication,
});
}
}
yield put(
gitArtifactActions.initGitForEditor({
artifactDef,
artifact: response.data,
}),
);
yield put(
gitArtifactActions.toggleConnectModal({ artifactDef, open: false }),
);
yield put(
gitArtifactActions.toggleConnectSuccessModal({
artifactDef,
open: true,
}),
);
}
} catch (e) {
if (response && response.responseMeta.error) {
const { error } = response.responseMeta;
if (GitErrorCodes.REPO_LIMIT_REACHED === error.code) {
yield put(
gitArtifactActions.toggleConnectModal({
artifactDef,
open: false,
}),
);
yield put(
gitGlobalActions.toggleRepoLimitErrorModal({
open: true,
}),
);
}
yield put(gitArtifactActions.connectError({ artifactDef, error }));
} else {
log.error(e);
captureException(e);
}
}
}