forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
46 lines (33 loc) · 1.15 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
import uuid
from pathlib import Path
from typing import Optional
from commitizen import cmd, exceptions, git
class FakeCommand:
def __init__(self, out=None, err=None, return_code=0):
self.out = out
self.err = err
self.return_code = return_code
def create_file_and_commit(message: str, filename: Optional[str] = None):
if not filename:
filename = str(uuid.uuid4())
Path(f"./{filename}").touch()
c = cmd.run("git add .")
if c.return_code != 0:
raise exceptions.CommitError(c.err)
c = git.commit(message)
if c.return_code != 0:
raise exceptions.CommitError(c.err)
def create_tag(tag: str):
c = git.tag(tag)
if c.return_code != 0:
raise exceptions.CommitError(c.err)
def wait_for_tag():
"""Wait for tag.
The resolution of timestamps is 1 second, so we need to wait
to create another tag unfortunately.
This means:
If we create 2 tags under the same second, they might be returned in the wrong order
See https://stackoverflow.com/questions/28237043/what-is-the-resolution-of-gits-commit-date-or-author-date-timestamps
"""
time.sleep(1.1)