Mercurial > code > home > repos > reposync
comparison sync.py @ 14:f83b7426b97c
fix makeGithubRepo; use ssh_url for almost no benefit
author | drewp@bigasterisk.com <drewp@bigasterisk.com> |
---|---|
date | Sat, 17 Jul 2021 00:14:27 -0700 |
parents | 19a699305c29 |
children | d653e1b558ce |
comparison
equal
deleted
inserted
replaced
13:e6ab74a37291 | 14:f83b7426b97c |
---|---|
10 class Project: | 10 class Project: |
11 def __init__(self, projRoot: Path): | 11 def __init__(self, projRoot: Path): |
12 self.config = json.load(open(Path(__file__).parent / "config.json")) | 12 self.config = json.load(open(Path(__file__).parent / "config.json")) |
13 self.config['SSH_AUTH_SOCK'] = getSshAuthSock() | 13 self.config['SSH_AUTH_SOCK'] = getSshAuthSock() |
14 | 14 |
15 self.gh = Github(self.config['githubToken']).get_user() | 15 self.gh = Github(self.config['githubToken']) |
16 self.projRoot = projRoot | 16 self.projRoot = projRoot |
17 self.name = projRoot.name | 17 self.name = projRoot.name |
18 | 18 |
19 def darcsTime(self): | 19 def darcsTime(self): |
20 j = os.path.join | 20 j = os.path.join |
48 log.error("in %s" % self.gitDir()) | 48 log.error("in %s" % self.gitDir()) |
49 raise | 49 raise |
50 | 50 |
51 def makeGithubRepo(self): | 51 def makeGithubRepo(self): |
52 try: | 52 try: |
53 self.gh.create_repo(self.name) | 53 self.gh.get_user().create_repo(self.name) |
54 except GithubException as e: | 54 except GithubException as e: |
55 assert e.data['errors'][0]['message'].startswith('name already exists'), (e, self.name) | 55 assert e.data['errors'][0]['message'].startswith('name already exists'), (e, self.name) |
56 return | 56 return |
57 self.runGitCommand(['git', 'remote', 'add', 'origin', | 57 |
58 'git@github.com:%s/%s.git' % (self.gh.login, | |
59 self.name)]) | |
60 | |
61 def pushToGithub(self): | 58 def pushToGithub(self): |
62 self.runGitCommand(['git', 'push', 'origin', 'master']) | 59 self.runGitCommand(['git', 'push', 'origin', 'master']) |
63 | 60 |
64 def hgToGithub(self): | 61 def hgToGithub(self): |
65 subprocess.check_call(['hg', 'bookmark', '-r', 'default', 'main'], | 62 subprocess.check_call(['hg', 'bookmark', '-r', 'default', 'main'], |
66 cwd=self.projRoot) | 63 cwd=self.projRoot) |
64 repo = self.gh.get_user().get_repo(self.name) | |
67 push = subprocess.run(['hg', 'push', | 65 push = subprocess.run(['hg', 'push', |
68 f'git+ssh://git@github.com/{self.gh.login}/{self.name}' | 66 f'git+ssh://'+repo.ssh_url.replace(':', '/'), |
69 ], | 67 ], |
70 check=False, | 68 check=False, |
71 capture_output=True, | 69 capture_output=True, |
72 cwd=self.projRoot, | 70 cwd=self.projRoot, |
73 env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK']}) | 71 env={'SSH_AUTH_SOCK': self.config['SSH_AUTH_SOCK']}) |