Skip to content

Commit

Permalink
create_rpm_git_repo: add --local flag
Browse files Browse the repository at this point in the history
In some conditions we may not want to create the GH project:
- when experimenting while not yet sure we will adopt the package
- when an initial run of the script did create the project but not the
  local repo

Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson committed Jan 24, 2025
1 parent 12b2907 commit eaac32f
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions scripts/create_rpm_git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
def main():
parser = argparse.ArgumentParser(description='Creates a git repository in current directory for RPM spec file and sources')
parser.add_argument('name', help='name of repository')
parser.add_argument('--local',
help='do not create github repository',
action='store_true')
parser.add_argument('token_file',
help='file containing github authentication token',
nargs='?',
default=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'github.txt'))
args = parser.parse_args()

# authenticate to Github
token = open(args.token_file).read().strip()
g = Github(token)
if not args.local:
# authenticate to Github
token = open(args.token_file).read().strip()
g = Github(token)

# create repository
org = g.get_organization('xcp-ng-rpms')
org.create_repo(args.name, "RPM sources for %s" % args.name)
# create repository
org = g.get_organization('xcp-ng-rpms')
org.create_repo(args.name, "RPM sources for %s" % args.name)

# initial commit to master
gitignore = """BUILD
Expand All @@ -39,7 +43,13 @@ def main():
Built RPMs and source RPMs are available on https://updates.xcp-ng.org.
""" % args.name
subprocess.check_call(['git', 'clone', 'https://github.com/xcp-ng-rpms/%s.git' % args.name])
if args.local:
subprocess.check_call(['git', 'init', args.name])
subprocess.check_call(['git', '-C', args.name,
'remote', 'add', 'origin',
'https://github.com/xcp-ng-rpms/%s.git' % args.name])
else:
subprocess.check_call(['git', 'clone', 'https://github.com/xcp-ng-rpms/%s.git' % args.name])
os.chdir(args.name)
if "[email protected]" not in subprocess.check_output(
['git', 'remote', 'get-url', '--push', 'origin'],
Expand All @@ -61,7 +71,8 @@ def main():
subprocess.check_call(['git', 'lfs', 'track', '*.tbz'])
subprocess.check_call(['git', 'add', '.gitattributes'])
subprocess.check_call(['git', 'commit', '-s', '-m', 'Initial commit'])
subprocess.check_call(['git', 'push'])
if not args.local:
subprocess.check_call(['git', 'push'])

if __name__ == "__main__":
main()

0 comments on commit eaac32f

Please sign in to comment.