From 6866c32f7ff18f98493cefbcc57cbdc7e1ed3dbe Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 4 Mar 2017 20:58:36 +0200 Subject: Add branching and pushing to bugfix scenrio --- 000.yarn | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- yarnhelper.py | 8 ++++---- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/000.yarn b/000.yarn index 93270b1..008cba4 100644 --- a/000.yarn +++ b/000.yarn @@ -204,9 +204,11 @@ groups, and respositories. AND admin creates repository qvarn AND admin sets qvarn config writers to qvarndevs THEN ian can clone qvarn - WHEN ian create qvarn branch bugfix + WHEN ian creates qvarn branch bugfix AND ian changes qvarn branch bugfix - THEN ian can push qvarn branch bugfix + THEN ian can push qvarn + WHEN ian merges qvarn branch bugfix to master + THEN ian can push qvarn FINALLY admin removes things that were created SCENARIO everyone can clone a public repository @@ -240,7 +242,22 @@ groups, and respositories. repo = helper.get_next_match() # FIXME: Create first, this is temporary helper.append_to_list('repositories', repo) - output = helper.gitano(None, 'create {}'.format(repo)) + helper.gitano(None, 'create {}'.format(repo)) + + user = 'admin' + url = helper.repo_ssh_url(repo) + dirname = helper.local_checkout_dirname(user, repo) + helper.git_as(None, ['clone', url, dirname]) + env = dict(os.environ) + env['GIT_SSH_COMMAND'] = helper.env_ssh_command(None) + cliapp.runcmd(['git', 'config', 'user.email', user], cwd=dirname, env=env) + cliapp.runcmd(['git', 'config', 'user.name', user], cwd=dirname, env=env) + with open(os.path.join(dirname, 'foo.txt'), 'a') as f: + f.write('') + cliapp.runcmd(['git', 'add', 'foo.txt'], cwd=dirname, env=env) + cliapp.runcmd(['git', 'commit', '-mfoo'], cwd=dirname, env=env) + cliapp.runcmd(['git', 'push', 'origin', 'HEAD'], cwd=dirname, env=env) + IMPLEMENTS WHEN admin sets (\S+) config (\S+) to (\S+) repo = helper.get_next_match() @@ -252,16 +269,50 @@ groups, and respositories. user = helper.get_next_match() repo = helper.get_next_match() url = helper.repo_ssh_url(repo) - dirname = '{}_{}'.format(user, repo) + dirname = helper.local_checkout_dirname(user, repo) helper.git_as(user, ['clone', url, dirname]) + cliapp.runcmd(['git', 'config', 'user.email', user], cwd=dirname) + cliapp.runcmd(['git', 'config', 'user.name', user], cwd=dirname) IMPLEMENTS THEN we can clone (\S+) via the git protocol repo = helper.get_next_match() server = os.environ['GITANO_SERVER'] url = 'git://{}/{}'.format(server, repo) - dirname = 'anonymouse_{}'.format(repo) + dirname = helper.local_checkout_dirname('anonymous', repo) cliapp.runcmd(['git', 'clone', url, dirname]) + IMPLEMENTS WHEN (\S+) creates (\S+) branch (\S+) + user = helper.get_next_match() + repo = helper.get_next_match() + branch = helper.get_next_match() + dirname = helper.local_checkout_dirname(user, repo) + cliapp.runcmd(['git', 'checkout', '-b', branch], cwd=dirname) + + IMPLEMENTS WHEN (\S+) changes (\S+) branch (\S+) + user = helper.get_next_match() + repo = helper.get_next_match() + branch = helper.get_next_match() + dirname = helper.local_checkout_dirname(user, repo) + with open(os.path.join(dirname, 'foo.txt'), 'a') as f: + f.write('foo\n') + cliapp.runcmd(['git', 'add', 'foo.txt'], cwd=dirname) + cliapp.runcmd(['git', 'commit', '-mfoo'], cwd=dirname) + + IMPLEMENTS THEN (\S+) can push (\S+) + user = helper.get_next_match() + repo = helper.get_next_match() + dirname = helper.local_checkout_dirname(user, repo) + cliapp.runcmd(['git', 'push', '--all', 'origin'], cwd=dirname) + + IMPLEMENTS WHEN (\S+) merges (\S+) branch (\S+) to (\S+) + user = helper.get_next_match() + repo = helper.get_next_match() + branch_from = helper.get_next_match() + branch_to = helper.get_next_match() + dirname = helper.local_checkout_dirname(user, repo) + cliapp.runcmd(['git', 'checkout', branch_to], cwd=dirname) + cliapp.runcmd(['git', 'merge', branch_from], cwd=dirname) + IMPLEMENTS FINALLY admin removes things that were created def iter(var, prefix): items = helper.get_variable(var, []) diff --git a/yarnhelper.py b/yarnhelper.py index 8af9cf5..7192b06 100644 --- a/yarnhelper.py +++ b/yarnhelper.py @@ -147,11 +147,13 @@ class YarnHelper(object): def repo_ssh_url(self, repo): # pragma: no cover return 'ssh://git@{}/{}'.format(os.environ['GITANO_SERVER'], repo) + def local_checkout_dirname(self, user, repo): # pragma: no cover + return '{}_{}'.format(user, repo) + def git_as(self, user, args): # pragma: no cover server = os.environ['GITANO_SERVER'] env = dict(os.environ) env['GIT_SSH_COMMAND'] = self.env_ssh_command(user) - print 'g_s_c:', env['GIT_SSH_COMMAND'] return cliapp.runcmd( ['git'] + args, stderr=subprocess.STDOUT, @@ -162,10 +164,8 @@ class YarnHelper(object): 'ssh', '-o', 'PasswordAuthentication=no', '-o', 'IdentitiesOnly=yes', + '-i', self.get_user_ssh_key(user), ] - if user is not None: - key = self.ssh_key_file_for_user(user) - argv.extend(['-i', key]) return ' '.join(argv) def get_admin_ssh_key(self): # pragma: no cover -- cgit v1.2.1