Skip to content

Commit 7c93ed4

Browse files
authored
Merge pull request openSUSE#1941 from dmach/git-obs-quiet
Implement 'git-obs --quiet' option (that mutes printing gitea settings now)
2 parents e83f375 + 7507953 commit 7c93ed4

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

behave/features/git-login.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Scenario: Remove a credentials login entry
9797

9898

9999
Scenario: Update a credentials login entry
100-
When I execute git-obs with args "login update alice --new-name=NEW_NAME --new-url=NEW_URL --new-user=NEW_USER --new-token=1234567890123456789012345678901234567890 --new-ssh-key= --set-as-default"
100+
When I execute git-obs with args "login update alice --new-name=NEW_NAME --new-url=NEW_URL --new-user=NEW_USER --new-token=1234567890123456789012345678901234567890 --new-ssh-key= --new-quiet=1 --set-as-default"
101101
Then the exit code is 0
102102
And stderr is
103103
"""
@@ -117,6 +117,7 @@ Scenario: Update a credentials login entry
117117
Default : true
118118
URL : NEW_URL
119119
User : NEW_USER
120+
Quiet : yes
120121
"""
121122
When I execute git-obs with args "login list"
122123
Then stdout is
@@ -130,6 +131,7 @@ Scenario: Update a credentials login entry
130131
Default : true
131132
URL : NEW_URL
132133
User : NEW_USER
134+
Quiet : yes
133135
134136
Name : bob
135137
URL : http://localhost:{context.podman.container.ports[gitea_http]}

osc/commandline_git.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,17 @@ def gitea_conn(self):
7777
def gitea_conn(self, value):
7878
self.main_command.gitea_conn = value
7979

80+
@property
81+
def quiet(self):
82+
if self.main_command._args.quiet:
83+
return True
84+
if self.gitea_login and self.gitea_login.quiet:
85+
return True
86+
return False
87+
8088
def print_gitea_settings(self):
89+
if self.quiet:
90+
return
8191
print(f"Using the following Gitea settings:", file=sys.stderr)
8292
print(f" * Config path: {self.gitea_conf.path}", file=sys.stderr)
8393
print(f" * Login (name of the entry in the config file): {self.gitea_login.name}", file=sys.stderr)
@@ -176,6 +186,13 @@ def __init__(self, *args, **kwargs):
176186
self._gitea_conn = None
177187

178188
def init_arguments(self):
189+
self.add_argument(
190+
"-q",
191+
"--quiet",
192+
action="store_true",
193+
help="Mute unnecessary output",
194+
)
195+
179196
self.add_argument(
180197
"--gitea-config",
181198
help="Path to gitea config. Default: $GIT_OBS_CONFIG or ~/.config/tea/config.yml.",

osc/commands/fork.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ class ForkCommand(osc.commandline.OscCommand):
1919
post_parse_args = osc.commandline_git.GitObsMainCommand.post_parse_args
2020
print_gitea_settings = osc.commandline_git.GitObsCommand.print_gitea_settings
2121

22+
def quiet(self):
23+
if self.main_command.args.quiet:
24+
return True
25+
if self.gitea_login and self.gitea_login.quiet:
26+
return True
27+
return False
28+
2229
def init_arguments(self):
2330
# inherit global options from the main git-obs command
2431
osc.commandline_git.GitObsMainCommand.init_arguments(self)

osc/commands_git/login_add.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def init_arguments(self):
2222
self.parser.add_argument("--token", help="Gitea access token; omit or set to '-' to invoke a secure interactive prompt")
2323
self.parser.add_argument("--ssh-key", metavar="PATH", help="Path to a private SSH key").completer = complete_ssh_key_path
2424
self.parser.add_argument("--git-uses-http", action="store_true", help="Git uses http(s) instead of SSH", default=None)
25+
self.parser.add_argument("--quiet", action="store_true", help="Mute unnecessary output when using this login entry")
2526
self.parser.add_argument("--set-as-default", help="Set the new login entry as default", action="store_true", default=None)
2627

2728
def run(self, args):

osc/commands_git/login_update.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def init_arguments(self):
2323
self.parser.add_argument("--new-token", metavar="TOKEN", help="Gitea access token; set to '-' to invoke a secure interactive prompt")
2424
self.parser.add_argument("--new-ssh-key", metavar="PATH", help="Path to a private SSH key").completer = complete_ssh_key_path
2525
self.parser.add_argument("--new-git-uses-http", help="Git uses http(s) instead of SSH", choices=["0", "1", "yes", "no"], default=None)
26+
self.parser.add_argument("--new-quiet", help="Mute unnecessary output when using this login entry", choices=["0", "1", "yes", "no"], default=None)
2627
self.parser.add_argument("--set-as-default", action="store_true", help="Set the login entry as default")
2728

2829
def run(self, args):
@@ -51,6 +52,13 @@ def run(self, args):
5152
else:
5253
new_git_uses_http = None
5354

55+
if args.new_quiet in ("0", "no"):
56+
new_quiet = False
57+
elif args.new_quiet in ("1", "yes"):
58+
new_quiet = True
59+
else:
60+
new_quiet = None
61+
5462
updated_login_obj = self.gitea_conf.update_login(
5563
args.name,
5664
new_name=args.new_name,
@@ -59,6 +67,7 @@ def run(self, args):
5967
new_token=args.new_token,
6068
new_ssh_key=args.new_ssh_key,
6169
new_git_uses_http=new_git_uses_http,
70+
new_quiet=new_quiet,
6271
set_as_default=args.set_as_default,
6372
)
6473
print("")

osc/gitea_api/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Login(BaseModel):
2121
token: str = Field() # type: ignore[assignment]
2222
ssh_key: Optional[str] = Field() # type: ignore[assignment]
2323
git_uses_http: Optional[bool] = Field() # type: ignore[assignment]
24+
quiet: Optional[bool] = Field() # type: ignore[assignment]
2425
default: Optional[bool] = Field() # type: ignore[assignment]
2526

2627
class AlreadyExists(oscerr.OscBaseError):
@@ -69,6 +70,8 @@ def to_human_readable_string(self, *, show_token: bool = False):
6970
table.add("Private SSH key path", self.ssh_key)
7071
if self.git_uses_http:
7172
table.add("Git uses http(s)", "yes" if self.git_uses_http else "no")
73+
if self.quiet:
74+
table.add("Quiet", "yes" if self.quiet else "no")
7275
if show_token:
7376
# tokens are stored in the plain text, there's not reason to protect them too much
7477
# let's only hide them from the output by default
@@ -212,6 +215,7 @@ def update_login(
212215
new_token: Optional[str] = None,
213216
new_ssh_key: Optional[str] = None,
214217
new_git_uses_http: Optional[bool] = None,
218+
new_quiet: Optional[bool] = None,
215219
set_as_default: Optional[bool] = None,
216220
) -> Login:
217221
login = self.get_login(name)
@@ -236,6 +240,9 @@ def update_login(
236240
# remove from the config instead of setting to False
237241
login.git_uses_http = None
238242

243+
if new_quiet is not None:
244+
login.quiet = new_quiet
245+
239246
if set_as_default:
240247
login.default = True
241248

0 commit comments

Comments
 (0)