55from click import Path as PathType
66from click import command , option , secho
77
8- from .. dtos import Tree
9- from .. local import extract_repo_name , read_commit , read_repo
10- from .. remote import authenticate_app , write_commit
8+ from .dtos import Tree
9+ from .local import extract_repo_name , read_commit , read_repo
10+ from .remote import authenticate_app , write_commit
1111
1212
1313def print_tree (tree : Tree , parent : Path , depth : int = 0 ) -> None :
@@ -29,6 +29,7 @@ def print_tree(tree: Tree, parent: Path, depth: int = 0) -> None:
2929@option (
3030 "--repo-path" ,
3131 "--repo" ,
32+ help = "The path to the local git repository." ,
3233 type = PathType (
3334 exists = True ,
3435 file_okay = False ,
@@ -39,37 +40,26 @@ def print_tree(tree: Tree, parent: Path, depth: int = 0) -> None:
3940)
4041@option (
4142 "--ref" ,
43+ help = "The local ref to read." ,
4244 required = True ,
4345)
4446def read (
4547 * ,
4648 repo_path : Path ,
47- ref : str ,
49+ sha : str ,
4850) -> None :
4951 repo = read_repo (repo_path )
50- commit = read_commit (repo , ref )
52+ commit = read_commit (repo , sha )
5153
5254 secho (f"Commit: { commit .message } " , fg = "green" )
5355 print_tree (commit .tree , Path ())
5456
5557
5658@command ()
57- @option (
58- "--application-id" ,
59- "--app-id" ,
60- envvar = "GITHUB_APP_ID" ,
61- required = True ,
62- type = int ,
63- )
64- @option (
65- "--private-key" ,
66- hidden = True ,
67- envvar = "GITHUB_APP_PRIVATE_KEY" ,
68- required = True ,
69- )
7059@option (
7160 "--repo-path" ,
7261 "--repo" ,
62+ help = "The path to the local git repository." ,
7363 type = PathType (
7464 exists = True ,
7565 file_okay = False ,
@@ -78,13 +68,34 @@ def read(
7868 ),
7969 required = True ,
8070)
71+ @option (
72+ "--branch" ,
73+ help = "The remote branch on which to add the generated commit." ,
74+ required = True ,
75+ )
8176@option (
8277 "--ref" ,
78+ help = "The local ref to recreate remotely." ,
79+ required = True ,
80+ )
81+ @option (
82+ "--app-id" ,
83+ envvar = "GITHUB_APP_ID" ,
84+ help = "The GitHub App's app id." ,
85+ required = True ,
86+ type = int ,
87+ )
88+ @option (
89+ "--private-key" ,
90+ hidden = True ,
91+ help = "The GitHub App's private key" ,
92+ envvar = "GITHUB_APP_PRIVATE_KEY" ,
8393 required = True ,
8494)
8595def write (
8696 * ,
87- application_id : int ,
97+ app_id : int ,
98+ branch : str ,
8899 private_key : str ,
89100 repo_path : Path ,
90101 ref : str ,
@@ -94,10 +105,10 @@ def write(
94105 repo = read_repo (repo_path )
95106 repo_name = extract_repo_name (repo )
96107
97- github = authenticate_app (application_id , private_key )
108+ github = authenticate_app (app_id , private_key )
98109 repository = github .get_repo (repo_name )
110+ git_ref = repository .get_git_ref (f"heads/{ branch } " )
99111
100112 commit = read_commit (repo , ref )
101113 git_commit = write_commit (repository , commit )
102-
103- secho (f"Created git commit: { git_commit .sha } " , fg = "green" )
114+ git_ref .edit (git_commit .sha )
0 commit comments