1
1
import functools
2
- import json
3
2
import os
4
3
import pprint
5
4
import sys
@@ -71,10 +70,10 @@ async def _set_branch_protection(self, owner, reponame, branch, status):
71
70
Given a branch on a repository, sets the branch protection status to
72
71
status. Status must be a dictionary.
73
72
"""
74
- encoded_status = json .dumps (status )
75
73
return await self ._gh .put (
76
74
f"/repos/{ owner } /{ reponame } /branches/{ branch } /protection" ,
77
- accept = accept_format (version = "loki-preview" )
75
+ data = status ,
76
+ accept = accept_format (version = "loki-preview" ),
78
77
)
79
78
80
79
async def branch_requires_review (self , owner , reponame , branch ):
@@ -96,7 +95,7 @@ async def protect_branch(self, owner, reponame, branch):
96
95
Protects a given branch.
97
96
"""
98
97
protection_status = protection_data ()
99
- self ._set_branch_protection (owner , reponame , branch , protection_status )
98
+ await self ._set_branch_protection (owner , reponame , branch , protection_status )
100
99
101
100
102
101
@click .group ()
@@ -105,17 +104,33 @@ def cli():
105
104
106
105
107
106
@cli .command ()
107
+ @click .argument ('organisation' )
108
108
@click .argument ('repo' )
109
109
@click .argument ('branch' )
110
110
@synchronize
111
- async def protection (repo , branch ):
111
+ async def protection (organisation , repo , branch ):
112
112
"""
113
113
Query the protection status of a branch.
114
114
"""
115
115
client = APIClient ()
116
- organisation , reponame = repo .split ('/' , 1 )
117
116
118
- if await client .branch_requires_review (organisation , reponame , branch ):
119
- print (f"{ organisation } /{ reponame } @{ branch } requires review" )
117
+ if await client .branch_requires_review (organisation , repo , branch ):
118
+ print (f"{ organisation } /{ repo } @{ branch } requires review" )
120
119
else :
121
- print (f"{ organisation } /{ reponame } @{ branch } does not require review" )
120
+ print (f"{ organisation } /{ repo } @{ branch } does not require review" )
121
+
122
+
123
+ @cli .command ()
124
+ @click .argument ('organisation' )
125
+ @click .argument ('repo' )
126
+ @click .argument ('branch' )
127
+ @synchronize
128
+ async def protect (organisation , repo , branch ):
129
+ """
130
+ Protect a branch.
131
+
132
+ This command sets a branch as protected using the default settings that
133
+ branchmgr provides.
134
+ """
135
+ client = APIClient ()
136
+ await client .protect_branch (organisation , repo , branch )
0 commit comments