Skip to content

Commit 276e3c4

Browse files
update rit github create branch
Signed-off-by: GuillaumeFalourd <[email protected]>
1 parent 73df30c commit 276e3c4

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

github/create/branch/src/formula/formula.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,24 @@ def run(token, owner, repository, branch, default):
2525
for d in datas:
2626
branch_name = re.search("(?<=refs\/heads\/).*", d["ref"]).group()
2727
shas[branch_name] = d["object"]["sha"]
28+
29+
if len(shas.keys()) == 1:
30+
reference = [*shas][0]
31+
print(f"⚙️ There is only one branch available on the repository.")
32+
print(f"⚙️ Therefore, branch \033[36m{reference}\033[0m will be used as reference.")
33+
34+
# If more than one branch on the repo, ask which one to use as reference
35+
else:
36+
questions = [
37+
inquirer.List("reference",
38+
message = "\033[1mReference branch\033[0m",
39+
choices = shas.keys(),
40+
),
41+
]
42+
answers = inquirer.prompt(questions)
43+
reference = answers["reference"]
2844

29-
questions = [
30-
inquirer.List("reference",
31-
message = "\033[1mReference branch\033[0m",
32-
choices = shas.keys(),
33-
),
34-
]
35-
answers = inquirer.prompt(questions)
36-
reference = answers["reference"]
37-
print("⚙️ Creating new branch...")
45+
print(f"⚙️ Creating new \033[36m{branch}\033[0m branch based on \033[36m{reference}\033[0m branch...")
3846

3947
data = {}
4048
data["ref"] = f"refs/heads/{branch}"
@@ -57,5 +65,5 @@ def run(token, owner, repository, branch, default):
5765
os.system(f"{input_flag_cmd}")
5866

5967
else:
60-
print("❌ Couldn't create the branch on the repository")
68+
print("❌ Couldn't create the \033[36m{branch}\033[0m branch on the repository")
6169
print (r2.status_code, r2.reason)

0 commit comments

Comments
 (0)