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

feat: create ref from commit id #262

Merged
merged 9 commits into from
Feb 28, 2024
Merged

feat: create ref from commit id #262

merged 9 commits into from
Feb 28, 2024

Conversation

borozcod
Copy link
Contributor

What changed?

Added functionality to be able to make a ref from a commit.

While developing this feature I identified #261. I've added a test case for checking elements at a specific commit, as well as checking elements made under a branch created from a commit. Both of these tests are currently failing. Fixing #261 should resolve both of these tests.

With this feature, you'll be able to create a ref from a commit like this:

POST http://{{host}}/projects/{{projectId}}/refs
Authorization: Basic {{username}} {{password}}
Content-Type: application/json

{
  "refs": [
    {
      "name": "new_branch_from_commit",
      "type": "Branch", // or Tag
      "parentCommitId": "5d374742-52ba-4f01-b225-7af28dfbab33",
      "id": "new_branch_from_commit_id"
    }
  ]
}

Fixes #237

@borozcod borozcod marked this pull request as draft February 16, 2024 20:19
@borozcod borozcod changed the title Feat: Create ref from commit id feat: create ref from commit id Feb 16, 2024
b.setParentCommit(parent.getId());
branch.setParentCommitId(parent.getCommitId());
});
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was updated so that if a RefJson has a parentCommitId, we don't set the new branch's parentCommitId to the the latest from the parent ref.

@borozcod borozcod marked this pull request as ready for review February 16, 2024 20:55
@borozcod borozcod self-assigned this Feb 16, 2024
@borozcod borozcod requested a review from dlamoris February 16, 2024 20:58
@dlamoris
Copy link
Collaborator

dlamoris commented Feb 16, 2024

i would suggest leaving the current crud test collection as is and make a new collection just for testing elements at commit, otherwise crud gets increasingly hard to follow on what element is supposed to be where - I think I'll just make a new collection as part of #261, then this can add to that collection by branching from the tests for getElements at commitId

for (Node node : nodes) {
if(nodeCommitData.containsKey(node.getNodeId())){
node.setDocId(nodeCommitData.get(node.getNodeId()).getDocId());
node.setDeleted(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also set node lastCommitId to be the element json's commitId

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to do what line 189 is doing also - and not do line 189 if it wasn't branch from latest

" var jsonData = pm.response.json();",
" pm.expect(jsonData.commitId).to.eql(pm.environment.get(\"commitXYRef\"))",
"",
" pm.environment.set(\"commitXYRefElements\", pm.response.json());",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the entire json here to compare with later won't work since the return elements' _refId should reflect the context they're gotten in - getting the elements from a branch will have slightly different json even if they're the same elements (the _refId will be different)

Set<String> docIds = new HashSet<>();
for (Node n: nodeRepository.findAllByDeleted(false)) {
docIds.add(n.getDocId());
if(branch.getParentCommitId() == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parent commitId would never be null here since it's set at line 172, should add a boolean to keep track above

nodeRepository.updateAll(nodes);

Set<String> docIds = new HashSet<>();
for (Node n: nodeRepository.findAllByDeleted(false)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add to docIds as you're looping through the nodes so you don't have to call nodeRepository again

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@borozcod
Copy link
Contributor Author

Thank you for the feedback @dlamoris. I've gone ahead and committed my changes.

@dlamoris dlamoris merged commit 8ffec34 into develop Feb 28, 2024
4 of 5 checks passed
@dlamoris dlamoris deleted the feat/copy-from-commit branch February 28, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot branch from point in time (specific commit)
2 participants