From 7bbcf5454756b715ad2d2fe7f18901a04123d4a7 Mon Sep 17 00:00:00 2001 From: Ondřej Nosek Date: Mar 05 2025 00:39:55 +0000 Subject: Fork a package using anonymous auth When the repo is cloned anonymously (`fedpkg clone -a`), `fork` should work in the 'anonymous' mode as well. Fork API call is the same, but the added remote has a different address = https protocol instead of ssh. Fedpkg detects whether `fork` is executed upon an anonymous repo. The User can force anonymous mode using (`fedpkg fork -a`) parameter. Fixes: #574 JIRA: RHELCMP-14205 Signed-off-by: Ondřej Nosek --- diff --git a/fedpkg/cli.py b/fedpkg/cli.py index 33dbd91..461c085 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -531,6 +531,11 @@ class fedpkgClient(cliClient): formatter_class=argparse.RawDescriptionHelpFormatter, help=help_msg, description=description) + fork_parser.add_argument( + '--anonymous', '-a', action='store_true', + help='In this mode, it is possible to fork the repository which was cloned ' + '"anonymously" (fedpkg clone -a). The forked repository uses https ' + 'protocol instead ssh.') fork_parser.set_defaults(command=self.do_distgit_fork) def register_releases_info(self): @@ -1300,11 +1305,16 @@ class fedpkgClient(cliClient): That includes creating fork itself using API call and then adding remote tracked repository """ + anon = self.args.anonymous + if self.cmd.push_url.startswith('https://'): + anon = True + self.log.info('Detected anonymously cloned repo (`fedpkg clone -a`) ' + '- forking in the anonymous mode.') distgit_section = '{0}.distgit'.format(self.name) distgit_api_base_url = config_get_safely(self.config, distgit_section, "apibaseurl") distgit_remote_base_url = self.config.get( '{0}'.format(self.name), - "gitbaseurl", + 'anongiturl' if anon else 'gitbaseurl', vars={'user': self.cmd.user, 'repo': self.cmd.repo_name}, ) distgit_token = config_get_safely(self.config, distgit_section, 'token')