Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions git_platforms_synchro.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def repo_tags_sync(args, clone_url_from: str, git_from: GitClient, git_to: GitCl

tags_commits_from = git_from.get_tags(args.from_org, repo)
tags_commits_to = git_to.get_tags(args.to_org, repo)
if branches_updated > 0 or len(tags_commits_from) == len(tags_commits_to):
if branches_updated > 0 or set(tags_commits_from.keys()).issubset(set(tags_commits_to.keys())):
return False

logger.info(' All branches already synchronized, do tags only...')
Expand Down Expand Up @@ -212,7 +212,7 @@ def main() -> int:
branches_scanned, branches_updated = repo_branches_sync(args, branches_commits_from, branches_commits_to, clone_url_from, repo, git_to)
total_branches_scanned += branches_scanned

# Sync tags if no branches updated and needed (nbr tags diff between "from" and "to")
# Sync tags if no branches updated and needed (tags different between "from" and "to")
tag_updated = repo_tags_sync(args, clone_url_from, git_from, git_to, repo, branches_updated)

# Items updated calculation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "1.5.2",
"message": "Use leading / in app URL\n\nFixes gh-267",
"id": "c36452a2c34443ae26b4ecbba4f149906af14717",
"commit": {
"url": "http://localhost:3000/api/v1/repos/MyOrg/spring-petclinic/git/commits/c36452a2c34443ae26b4ecbba4f149906af14717",
"sha": "c36452a2c34443ae26b4ecbba4f149906af14717",
"created": "2017-11-03T14:17:56Z"
},
"zipball_url": "http://localhost:3000/MyOrg/spring-petclinic/archive/1.5.2.zip",
"tarball_url": "http://localhost:3000/MyOrg/spring-petclinic/archive/1.5.2.tar.gz"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"name": "1.5.1",
"zipball_url": "https://api.github.com/repos/spring-projects/spring-petclinic/zipball/refs/tags/1.5.1",
"tarball_url": "https://api.github.com/repos/spring-projects/spring-petclinic/tarball/refs/tags/1.5.1",
"commit": {
"sha": "c36452a2c34443ae26b4ecbba4f149906af14717",
"url": "https://api.github.com/repos/spring-projects/spring-petclinic/commits/c36452a2c34443ae26b4ecbba4f149906af14717"
},
"node_id": "MDM6UmVmNzUxNzkxODpyZWZzL3RhZ3MvMS41Lng="
}
]
25 changes: 24 additions & 1 deletion tests/test_git_platforms_synchro.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from unittest.mock import patch
from pytest_httpserver import HTTPServer
from pytest import LogCaptureFixture, raises
from tests.test_utils import get_url_root, expect_request, mock_cloned_repo
from tests.test_utils import get_url_root, expect_request, mock_cloned_repo, load_json


def get_test_args_github_to_gitea(httpserver: HTTPServer):
Expand Down Expand Up @@ -327,3 +327,26 @@ def test_from_github_to_gitea_all_already_sync(httpserver: HTTPServer, caplog: L
assert 'Synchronize branch...' not in caplog.text
assert 'All branches already synchronized, do tags only...' not in caplog.text
assert 'Git Platforms Synchronization finished sucessfully. Repos updated: 0/1. Branches updated: 0/2' in caplog.text


def test_from_github_to_gitea_tags_diff_sync(httpserver: HTTPServer, caplog: LogCaptureFixture):
# GitHub with spring-projects
prepare_github_with_spring_projects(httpserver, prepare_tags=False)
httpserver.expect_request('/repos/spring-projects/spring-petclinic/tags').respond_with_json(
load_json('tests/http_mocks/github/repos/spring-projects/spring-petclinic/tags-changed.json'))

# Gitea with same repo
prepare_gitea_with_spring_projects(httpserver, prepare_tags=False)
httpserver.expect_request(
'/api/v1/repos/MyOrg/spring-petclinic/tags',
query_string='page=1').respond_with_json(load_json('tests/http_mocks/gitea/api/v1/repos/MyOrg/spring-petclinic/tags-changed.json'))
httpserver.expect_request('/api/v1/repos/MyOrg/spring-petclinic/tags', query_string='page=2').respond_with_json([])

# Clone will be engaged for tags sync
with raises(GitCommandError):
with patch.object(sys, 'argv', get_test_args_github_to_gitea(httpserver)):
git_platforms_synchro.main()

assert 'Already synchronized.' in caplog.text
assert 'Synchronize branch...' not in caplog.text
assert 'All branches already synchronized, do tags only...' in caplog.text
7 changes: 5 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ def get_url_root(httpserver: HTTPServer) -> str:
return httpserver.url_for('/').rstrip('/')


def load_json(file: str, url_to_mock: str, url_replacement: str):
def load_json(file: str, url_to_mock: str = None, url_replacement: str = None):
with open(file) as f:
return json.loads(f.read().replace(url_to_mock, url_replacement))
content = f.read()
if url_to_mock and url_replacement:
content = content.replace(url_to_mock, url_replacement)
return json.loads(content)


def mock_cloned_repo(httpserver: HTTPServer, bare: bool = False):
Expand Down