Exemple #1
0
def create_repo(full_name, branch, owner_pk):
	# assume it doesn't exist already TODO
	owner = User.objects.get(pk=owner_pk)
	repo = Repo(full_name=full_name, branch=branch, owner=owner)

	head_commit = api.get_head_commit_sha(full_name, branch)
	manifest = raw.get_raw_file(full_name, head_commit, 'chrome.manifest')

	parser = ChromeManifestParser(manifest)
	repo.locale_path = parser.locale_path
	repo.translations_list_set = parser.existing
	repo.head_commit = head_commit
	repo.save()

	for f in repo.find_files(head_commit):
		File(repo=repo, path=f).save()

	if not api.create_fork(repo.full_name):
		# returns True if a fork was created, and that takes time so we can't update now
		api.update_head_commit_sha(repo.fork_name, 'zoo2', head_commit, force=True)

	token = owner.profile.github_token
	api.add_webhook(repo.full_name, token)

	download_readme.delay(repo.pk, head_commit)

	for f in repo.file_set.all():
		if f.path == 'install.rdf':
			download_install_rdf.delay(repo.pk, head_commit)
			continue

		download_file.delay(f.pk, 'en-US', head_commit)
Exemple #2
0
	def save_to_github(self):
		parent_commit = self.repo.head_commit

		files = dict()
		for f in self.repo.file_set.all():
			# TODO stop assuming install.rdf is at the top level
			if f.path == 'install.rdf':
				name = f.string_set.get(locale=self.locale, key='name').value
				description = f.string_set.get(locale=self.locale, key='description').value
				rdf = raw.get_raw_file(self.repo.full_name, parent_commit, 'install.rdf')
				parser = InstallRDFParser(rdf)
				parser.add_locale(self.locale.code, name, description)
				files['install.rdf'] = parser.reconstruct()
				continue

			path = f.get_full_path(self.locale)
			content = f.reconstruct(self.locale)
			files[path] = content

		message = 'Update %s translation' % self.locale.name
		if self.locale.code not in self.repo.translations_list_set:
			message = 'Add %s translation' % self.locale.name
			translations_list_set = self.repo.translations_list_set
			translations_list_set.append(self.locale.code)
			self.repo.translations_list_set = translations_list_set
			self.repo.save(update_fields=['translations_list'])
			# TODO stop assuming chrome.manifest is at the top level
			manifest = raw.get_raw_file(self.repo.full_name, parent_commit, 'chrome.manifest')
			parser = ChromeManifestParser(manifest)
			parser.add_locale(self.locale.code)
			files['chrome.manifest'] = parser.reconstruct()

		tree_sha = api.get_commit_tree_sha(self.repo.fork_name, parent_commit)
		tree_sha = api.save_files(self.repo.fork_name, tree_sha, files)
		author = {
			'name': self.owner.username,
			'email': self.owner.email
		}
		head_commit = api.create_commit(
			self.repo.fork_name, message, tree_sha, parent_commit, author=author
		)

		api.update_head_commit_sha(self.repo.fork_name, self.branch_name, head_commit, force=True)

		self.dirty = False
		self.save(update_fields=['dirty'])
		self.set_strings_clean()
Exemple #3
0
	def update_fork(self, new_head_commit):
		api.update_head_commit_sha(self.fork_name, 'zoo2', new_head_commit, force=True)
		self.head_commit = new_head_commit
		self.save(update_fields=['head_commit'])