git-tide 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: git-tide
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: CLI for automated gitflow-style branching
5
5
  Author: Chad Dombrova
6
6
  Classifier: Programming Language :: Python :: 2
@@ -100,6 +100,12 @@ In order for `tide` to work its magic, the Gitlab repo needs to be properly conf
100
100
  branches.rc = "staging"
101
101
  branches.stable = "master"
102
102
  ```
103
+ - For each project within your repo that you want to manage tagged releases, add a `project` entry:
104
+ ```toml
105
+ [tool.tide]
106
+ project = "project_name"
107
+ ```
108
+ If there is only one, then combine be sure to put all of your options under a single `[tool.tide]` section.
103
109
  - Create a [Project Access Token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html) with the appropriate scope for being able to push tags, changes and create cicd variables.
104
110
  - Run `tide init --access-token='YOUR_ACCESS_TOKEN'`
105
111
  - Copy and modify the `.gitlab-ci.yml` file ensuring the branch variables match the ones in the `pyproject.toml` (TODO: automated generation of `.gitlab-ci.yml` in `tide init`)
@@ -76,6 +76,12 @@ In order for `tide` to work its magic, the Gitlab repo needs to be properly conf
76
76
  branches.rc = "staging"
77
77
  branches.stable = "master"
78
78
  ```
79
+ - For each project within your repo that you want to manage tagged releases, add a `project` entry:
80
+ ```toml
81
+ [tool.tide]
82
+ project = "project_name"
83
+ ```
84
+ If there is only one, then combine be sure to put all of your options under a single `[tool.tide]` section.
79
85
  - Create a [Project Access Token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html) with the appropriate scope for being able to push tags, changes and create cicd variables.
80
86
  - Run `tide init --access-token='YOUR_ACCESS_TOKEN'`
81
87
  - Copy and modify the `.gitlab-ci.yml` file ensuring the branch variables match the ones in the `pyproject.toml` (TODO: automated generation of `.gitlab-ci.yml` in `tide init`)
@@ -6,7 +6,7 @@ name = "git-tide"
6
6
  packages = [
7
7
  { include = "tide", from = "src" },
8
8
  ]
9
- version = "0.1.2"
9
+ version = "0.1.3"
10
10
  description = "CLI for automated gitflow-style branching"
11
11
  authors = ["Chad Dombrova", "Matt Collie"]
12
12
  readme = "README.md"
@@ -44,10 +44,3 @@ markers = [
44
44
  branches.beta = "develop"
45
45
  branches.rc = "staging"
46
46
  branches.stable = "master"
47
-
48
- [tool.commitizen]
49
- name = "cz_conventional_commits"
50
- tag_format = "$version"
51
- version_scheme = "pep440"
52
- version_provider = "scm"
53
- major_version_zero = false
@@ -54,7 +54,6 @@ def get_runtime() -> Runtime:
54
54
  """
55
55
  Return a Runtime corresponding to where the current python process is *running*
56
56
  """
57
- print(os.environ.get("GITLAB_CI"))
58
57
  if os.environ.get("GITLAB_CI", "false") == "true":
59
58
  return GitlabRuntime(CONFIG)
60
59
  # gitlab-ci-local and our unittests set this to false as an inidicator that
@@ -179,9 +178,11 @@ def autotag(annotation: str, base_rev: str | None) -> None:
179
178
 
180
179
  projects = get_modified_projects(base_rev, verbose=CONFIG.verbose)
181
180
  if projects:
182
- for project_folder, _ in projects:
181
+ for project_folder, project_name in projects:
183
182
  # Auto-tag
184
- tag = get_tag_for_branch(CONFIG, remote, branch, project_folder)
183
+ tag = get_tag_for_branch(
184
+ CONFIG, remote, branch, project_name, project_folder
185
+ )
185
186
 
186
187
  # NOTE: this delay is necessary to create stable sorting of tags
187
188
  # because git's time resolution is 1s (same as unix timestamp).
@@ -317,7 +318,16 @@ def get_tag(path: str, branch: str | None, remote: str, next: bool) -> None:
317
318
  if branch is None:
318
319
  runtime = get_runtime()
319
320
  branch = runtime.current_branch()
320
- click.echo(get_tag_for_branch(CONFIG, remote, branch, Path(path)))
321
+ projects = dict(get_projects())
322
+ folder = Path(path)
323
+ try:
324
+ project_name = projects[folder]
325
+ except KeyError:
326
+ raise click.ClickException(
327
+ f"There is not a project at path={folder}. "
328
+ "Ensure there is a pyproject.toml file with a [tool.tide] section and a `project` entry"
329
+ )
330
+ click.echo(get_tag_for_branch(CONFIG, remote, branch, project_name, folder))
321
331
  else:
322
332
  click.echo(cz("version", "--project", folder=path))
323
333
 
@@ -1,7 +1,6 @@
1
1
  from __future__ import absolute_import, print_function, annotations
2
2
 
3
3
  import os
4
- import re
5
4
  import subprocess
6
5
  import json
7
6
 
@@ -23,6 +22,7 @@ from .gitutils import git, checkout, get_tags, branch_exists, join, current_rev,
23
22
 
24
23
  if TYPE_CHECKING:
25
24
  import gitlab.v4.objects
25
+ import commitizen.providers
26
26
 
27
27
 
28
28
  TOOL_NAME = "tide"
@@ -477,7 +477,13 @@ def cz(*args: str, folder: str | Path | None = None) -> str:
477
477
  return output.strip()
478
478
 
479
479
 
480
- def is_pending_bump(config: Config, remote: str, branch: str, folder: Path) -> bool:
480
+ def is_pending_bump(
481
+ config: Config,
482
+ provider: commitizen.providers.ScmProvider,
483
+ remote: str,
484
+ branch: str,
485
+ folder: Path,
486
+ ) -> bool:
481
487
  """
482
488
  Return whether the given branch and folder combination are awaiting a minor bump.
483
489
 
@@ -489,9 +495,6 @@ def is_pending_bump(config: Config, remote: str, branch: str, folder: Path) -> b
489
495
  Returns:
490
496
  whether it is pending or not
491
497
  """
492
- from commitizen.config import read_cfg
493
- from commitizen.providers import ScmProvider
494
-
495
498
  if branch != config.most_experimental_branch():
496
499
  return False
497
500
 
@@ -505,9 +508,6 @@ def is_pending_bump(config: Config, remote: str, branch: str, folder: Path) -> b
505
508
  cwd = os.getcwd()
506
509
  os.chdir(folder)
507
510
  try:
508
- # Use the matching logic from commitizen, which will read the commitizen
509
- # config file for us (note: it supports more than just pyproject.toml).
510
- provider = ScmProvider(read_cfg())
511
511
  matcher = provider._tag_format_matcher()
512
512
  if config.verbose:
513
513
  click.echo(f"Found promotion base rev: {promotion_rev}")
@@ -559,7 +559,9 @@ def set_promotion_marker(remote: str, branch: str) -> None:
559
559
  git("push", remote, "refs/notes/*")
560
560
 
561
561
 
562
- def get_tag_for_branch(config: Config, remote: str, branch: str, folder: Path) -> str:
562
+ def get_tag_for_branch(
563
+ config: Config, remote: str, branch: str, project_name: str, folder: Path
564
+ ) -> str:
563
565
  """
564
566
  Determine the appropriate new tag for a given branch based on the latest changes.
565
567
 
@@ -577,6 +579,24 @@ def get_tag_for_branch(config: Config, remote: str, branch: str, folder: Path) -
577
579
  Raises:
578
580
  RuntimeError: If the command does not generate an output or fails to determine the tag.
579
581
  """
582
+ from commitizen.providers import ScmProvider
583
+ from commitizen.version_schemes import get_version_scheme, Increment
584
+ from commitizen.config.base_config import BaseConfig
585
+ from commitizen.defaults import Settings
586
+ from commitizen import bump
587
+
588
+ tag_format = f"{project_name}-$version"
589
+ cz_config = BaseConfig()
590
+ cz_config.update(
591
+ Settings(
592
+ name="cz_conventional_commits",
593
+ tag_format=tag_format,
594
+ version_scheme="pep440",
595
+ version_provider="scm",
596
+ major_version_zero=False,
597
+ )
598
+ )
599
+
580
600
  try:
581
601
  release_id = config.branch_to_release_id[branch]
582
602
  except KeyError:
@@ -585,35 +605,43 @@ def get_tag_for_branch(config: Config, remote: str, branch: str, folder: Path) -
585
605
  f"Must be one of {', '.join(config.branches)}"
586
606
  )
587
607
 
588
- increment = "patch"
608
+ provider = ScmProvider(cz_config)
609
+ scheme = get_version_scheme(cz_config)
610
+ current_version = scheme(provider.get_version())
589
611
 
590
612
  # Only apply minor increment the most experimental branch
591
- if is_pending_bump(config, remote, branch, folder):
592
- increment = "minor"
613
+ if is_pending_bump(config, provider, remote, branch, folder):
614
+ increment: Increment = "MINOR"
615
+ exact_increment = True
616
+ else:
617
+ increment = "PATCH"
618
+ exact_increment = False
593
619
 
594
- args = [f"--increment={increment}"]
595
620
  if release_id != ReleaseID.stable:
596
- args += ["--prerelease", release_id.value]
597
-
598
- if increment == "minor":
599
- args += ["--increment-mode=exact"]
600
-
601
- # run this in the project directory so that the pyproject.toml is accessible.
602
- output = cz(*(["bump"] + list(args) + ["--dry-run", "--yes"]), folder=folder)
603
- match = re.search("tag to create: (.*)", output)
604
-
605
- if not match:
606
- raise click.ClickException(output)
621
+ prerelease = release_id.value
622
+ else:
623
+ prerelease = None
624
+
625
+ new_version = current_version.bump(
626
+ increment,
627
+ prerelease=prerelease,
628
+ exact_increment=exact_increment,
629
+ )
607
630
 
608
- tag = match.group(1).strip()
631
+ new_tag_version = bump.normalize_tag(
632
+ new_version,
633
+ tag_format=tag_format,
634
+ scheme=scheme,
635
+ )
609
636
 
610
- return tag
637
+ return new_tag_version
611
638
 
612
639
 
613
- def get_projects() -> list[tuple[Path, str | None]]:
640
+ def get_projects() -> list[tuple[Path, str]]:
614
641
  """Get the list of projects within the repo.
615
642
 
616
- A project is a folder with a pyproject.toml file with a `tool.commitizen` section.
643
+ A project is a folder with a pyproject.toml file with a `tool.tide` section
644
+ and a `tool.tide.project`.
617
645
  """
618
646
  results = []
619
647
  repo = GitRepo(".")
@@ -621,24 +649,20 @@ def get_projects() -> list[tuple[Path, str | None]]:
621
649
  with open(path, "rb") as f:
622
650
  data = tomllib.load(f)
623
651
  try:
624
- data["tool"]["commitizen"]
652
+ name = data["tool"][TOOL_NAME]["project"]
625
653
  except KeyError:
626
654
  pass
627
655
  else:
628
- try:
629
- name = data["project"]["name"]
630
- except KeyError:
631
- name = None
632
656
  results.append((Path(path).parent, name))
633
657
  return sorted(results)
634
658
 
635
659
 
636
660
  def get_modified_projects(
637
661
  base_rev: str, verbose: bool = False
638
- ) -> list[tuple[Path, str | None]]:
662
+ ) -> list[tuple[Path, str]]:
639
663
  """Get the list of projects with changes files.
640
664
 
641
- A project is defined as a folder with a pyproject.toml file with a `tool.commitizen` section.
665
+ A project is defined as a folder with a pyproject.toml file with a `tool.tide` section.
642
666
 
643
667
  Args:
644
668
  base_rev: The Git revision to compare against when identifying changed files
File without changes
File without changes
File without changes