Skip to content

Commit

Permalink
chore: git branches IT (appsmithorg#38805)
Browse files Browse the repository at this point in the history
## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

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

### 🔍 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/12983176503>
> Commit: 9462078
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12983176503&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git, @tag.ImportExport`
> Spec:
> <hr>Mon, 27 Jan 2025 07:09:02 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**
	- Added file format versioning for Git-related artifacts
	- Enhanced Git reference management with new methods and constants
	- Improved logging for Git operations

- **Bug Fixes**
	- Refined file path matching and handling in Git operations
	- Improved error handling during artifact and metadata processing

- **Refactor**
	- Centralized file and constant management across Git-related services
	- Updated method signatures to support more comprehensive Git workflows
	- Simplified code by removing hardcoded string literals

- **Tests**
- Added new integration test suite for Git branch and repository
operations
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
sondermanish authored Jan 27, 2025
1 parent 9b0a1ee commit 4ae9ce5
Show file tree
Hide file tree
Showing 12 changed files with 873 additions and 191 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public Integer getFileFormatVersion(Object metadata) {
if (metadata == null) {
return 1;
}

JsonNode json = objectMapper.valueToTree(metadata);
int fileFormatVersion = json.get(CommonConstants.FILE_FORMAT_VERSION).asInt();
return fileFormatVersion;
return json.get(CommonConstants.FILE_FORMAT_VERSION).asInt();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,13 @@ public Mono<Boolean> checkoutToBranch(Path repoSuffix, String branchName) {
return Mono.using(
() -> Git.open(createRepoPath(repoSuffix).toFile()),
git -> Mono.fromCallable(() -> {
log.debug(Thread.currentThread().getName() + ": Switching to the branch "
+ branchName);
log.info(
"{}: Switching to the branch {}",
Thread.currentThread().getName(),
branchName);

// We can safely assume that repo has been already initialised either in commit or
// clone flow and
// can directly
// open the repo
// clone flow and can directly open the repo
if (StringUtils.equalsIgnoreCase(
branchName, git.getRepository().getBranch())) {
return TRUE;
Expand Down Expand Up @@ -611,8 +612,12 @@ public Mono<GitStatusDTO> getStatus(Path repoPath, String branchName) {
return Mono.using(
() -> Git.open(repoPath.toFile()),
git -> Mono.fromCallable(() -> {
log.debug(Thread.currentThread().getName() + ": Get status for repo " + repoPath
+ ", branch " + branchName);
log.info(
"{}: Get status for repo {}, {}",
Thread.currentThread().getName(),
repoPath,
branchName);

Status status = git.status().call();
GitStatusDTO response = new GitStatusDTO();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class GitConstantsCE {
public static final String ACTION_LIST = "actionList";
public static final String ACTION_COLLECTION_LIST = "actionCollectionList";

public static final String README_FILE_NAME = "README.md";

public static final String DEFAULT_COMMIT_MESSAGE = "System generated commit, ";
public static final String EMPTY_COMMIT_ERROR_MESSAGE = "On current branch nothing to commit, working tree clean";
public static final String MERGE_CONFLICT_BRANCH_NAME = "_mergeConflict";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
import static com.appsmith.external.helpers.AppsmithBeanUtils.copyNestedNonNullProperties;
import static com.appsmith.external.helpers.AppsmithBeanUtils.copyProperties;
import static com.appsmith.git.constants.CommonConstants.DELIMITER_PATH;
import static com.appsmith.git.constants.CommonConstants.FILE_FORMAT_VERSION;
import static com.appsmith.git.constants.CommonConstants.JSON_EXTENSION;
import static com.appsmith.git.constants.CommonConstants.MAIN_CONTAINER;
import static com.appsmith.git.constants.CommonConstants.WIDGETS;
import static com.appsmith.git.constants.ce.GitDirectoriesCE.PAGE_DIRECTORY;
import static com.appsmith.git.constants.CommonConstants.fileFormatVersion;
import static com.appsmith.git.constants.GitDirectories.PAGE_DIRECTORY;
import static com.appsmith.server.constants.FieldName.ACTION_COLLECTION_LIST;
import static com.appsmith.server.constants.FieldName.ACTION_LIST;
import static com.appsmith.server.constants.FieldName.CHILDREN;
Expand Down Expand Up @@ -189,6 +191,10 @@ public void setArtifactDependentResources(
copyProperties(applicationJson, applicationMetadata, keys);
final String metadataFilePath = CommonConstants.METADATA + JSON_EXTENSION;
ObjectNode metadata = objectMapper.valueToTree(applicationMetadata);

// put file format version;
metadata.put(FILE_FORMAT_VERSION, fileFormatVersion);

GitResourceIdentity metadataIdentity =
new GitResourceIdentity(GitResourceType.ROOT_CONFIG, metadataFilePath, metadataFilePath);
resourceMap.put(metadataIdentity, metadata);
Expand Down Expand Up @@ -717,7 +723,6 @@ public void setArtifactDependentPropertiesInJson(
artifactExchangeJson.setContextList(pageList);

// widgets

pageList.parallelStream().forEach(newPage -> {
Map<String, org.json.JSONObject> widgetsData = resourceMap.entrySet().stream()
.filter(entry -> {
Expand All @@ -730,13 +735,23 @@ public void setArtifactDependentPropertiesInJson(
.getFilePath()
.replaceFirst(
PAGE_DIRECTORY
+ DELIMITER_PATH
+ newPage.getUnpublishedPage()
.getName()
+ DELIMITER_PATH
+ WIDGETS
+ DELIMITER_PATH,
MAIN_CONTAINER + DELIMITER_PATH),
entry -> (org.json.JSONObject) entry.getValue()));
entry -> {
try {
return new org.json.JSONObject(objectMapper.writeValueAsString(entry.getValue()));
} catch (JsonProcessingException jsonProcessingException) {
log.error(
"Error while deserializing widget with file path {}",
entry.getKey().getFilePath());
throw new RuntimeException(jsonProcessingException);
}
}));

Layout layout = newPage.getUnpublishedPage().getLayouts().get(0);
org.json.JSONObject mainContainer;
Expand Down
Loading

0 comments on commit 4ae9ce5

Please sign in to comment.