auto-semver/semver/__init__.py

83 lines
1.9 KiB
Python
Raw Permalink Normal View History

2018-06-01 20:28:30 +02:00
import argparse
import re
import subprocess
import sys
import traceback
2023-07-01 04:53:38 +02:00
from typing import List, Union
2023-07-01 04:53:38 +02:00
import toml
2023-07-01 04:53:38 +02:00
from semver.logger import logging, logger, console_logger
from semver.scm import SCM
from semver.scm.git import Git
2023-07-01 04:53:38 +02:00
from semver.semver import SemVer
from semver.utils import setting_to_array
2023-07-01 04:53:38 +02:00
from semver.exceptions import (
NoMergeFoundException,
NotMainBranchException,
NoGitFlowException,
)
2023-07-01 04:53:38 +02:00
version = "0.0.0"
2019-11-22 21:30:58 +01:00
2018-05-23 21:09:14 +02:00
def main():
2023-07-01 04:53:38 +02:00
"""Main entry point for the application"""
parser = argparse.ArgumentParser(description="Bump Semantic Version.")
parser.add_argument(
"-n", "--no-push", help="do not try to push", action="store_false", dest="push"
2023-07-01 04:53:38 +02:00
)
parser.add_argument(
"-g",
"--global-user",
help="set git user at a global level",
2023-07-01 04:53:38 +02:00
action="store_true",
dest="global_user",
)
parser.add_argument(
"-D",
"--debug",
help="sets logging level to DEBUG",
2023-07-01 04:53:38 +02:00
action="store_true",
dest="debug",
default=False,
)
args = parser.parse_args()
2020-02-21 23:44:15 +01:00
2023-07-01 04:53:38 +02:00
scm: SCM = Git(global_user=args.global_user)
app = SemVer(
scm=scm,
main_branches=setting_to_array("main_branches"),
major_branches=setting_to_array("major_branches"),
minor_branches=setting_to_array("minor_branches"),
patch_branches=setting_to_array("patch_branches"),
2023-07-01 04:53:38 +02:00
)
2020-02-21 23:44:15 +01:00
if args.debug:
console_logger.setLevel(logging.DEBUG)
try:
2023-07-01 04:53:38 +02:00
app.run(push=args.push)
except Exception as e:
2020-02-21 23:44:15 +01:00
logger.error(e)
if args.debug:
tb = sys.exc_info()[2]
traceback.print_tb(tb)
2023-07-01 04:53:38 +02:00
if e is NoMergeFoundException:
2018-06-04 23:56:15 +02:00
exit(1)
2023-07-01 04:53:38 +02:00
elif e == NotMainBranchException:
2018-06-04 23:56:15 +02:00
exit(2)
2023-07-01 04:53:38 +02:00
elif e == NoGitFlowException:
2018-06-04 23:56:15 +02:00
exit(3)
else:
exit(128)
2018-05-23 21:09:14 +02:00
2023-07-01 04:53:38 +02:00
if __name__ == "__main__":
try:
main()
except Exception:
raise