Ejemplo n.º 1
0
    def loadStoreData(self):
        installers = dict()
        updateSource = self.ConfigManager.getModulesUpdateSource()
        req = requests.get(
            url=
            'https://api.github.com/search/code?q=extension:install+repo:project-alice-powered-by-snips/ProjectAliceModules/',
            auth=GithubCloner.getGithubAuth())
        results = req.json()
        if results:
            for module in results['items']:
                try:
                    req = requests.get(
                        url=f"{module['url'].split('?')[0]}?ref={updateSource}",
                        headers={
                            'Accept': 'application/vnd.github.VERSION.raw'
                        },
                        auth=GithubCloner.getGithubAuth())
                    installer = req.json()
                    if installer:
                        installers[installer['name']] = installer

                except Exception:
                    continue

        actualVersion = Version(constants.VERSION)
        return {
            moduleName: moduleInfo
            for moduleName, moduleInfo in installers.items()
            if self.ModuleManager.getModuleInstance(moduleName=moduleName,
                                                    silent=True) is None
            and actualVersion >= Version(moduleInfo['aliceMinVersion'])
        }
Ejemplo n.º 2
0
    def getModulesUpdateSource(self) -> str:
        updateSource = 'master'
        if self.getAliceConfigByName('updateChannel') == 'master':
            return updateSource

        req = requests.get(
            'https://api.github.com/repos/project-alice-powered-by-snips/ProjectAliceModules/branches',
            auth=GithubCloner.getGithubAuth())
        result = req.json()
        if result:
            userUpdatePref = self.getAliceConfigByName('updateChannel')
            versions = list()
            for branch in result:
                repoVersion = Version(branch['name'])
                if not repoVersion.isVersionNumber:
                    continue

                if userUpdatePref == 'alpha' and repoVersion.infos[
                        'releaseType'] in ('master', 'rc', 'b', 'a'):
                    versions.append(repoVersion)
                elif userUpdatePref == 'beta' and repoVersion.infos[
                        'releaseType'] in ('master', 'rc', 'b'):
                    versions.append(repoVersion)
                elif userUpdatePref == 'rc' and repoVersion.infos[
                        'releaseType'] in ('master', 'rc'):
                    versions.append(repoVersion)

            if len(versions) > 0:
                versions.sort(reverse=True)
                updateSource = versions[0]

        return updateSource
Ejemplo n.º 3
0
    def uploadToGithub(self):
        try:
            skillName = request.form.get('skillName', '')
            skillDesc = request.form.get('skillDesc', '')

            if not skillName:
                raise Exception

            skillName = skillName[0].upper() + skillName[1:]
            data = {
                'name': skillName,
                'description': skillDesc,
                'has-issues': True,
                'has-wiki': False
            }
            req = requests.post('https://api.github.com/user/repos',
                                data=json.dumps(data),
                                auth=GithubCloner.getGithubAuth())

            if req.status_code == 201:
                return jsonify(success=True)
            else:
                raise Exception

        except Exception as e:
            self.logError(f'Failed uploading to github: {e}')
            return jsonify(success=False)
Ejemplo n.º 4
0
	def uploadSkillToGithub(self, skillName: str, skillDesc: str) -> bool:
		try:
			self.logInfo(f'Uploading {skillName} to Github')

			skillName = skillName[0].upper() + skillName[1:]

			localDirectory = Path('/home', getpass.getuser(), f'ProjectAlice/skills/{skillName}')
			if not localDirectory.exists():
				raise Exception("Local skill doesn't exist")

			data = {
				'name'       : f'skill_{skillName}',
				'description': skillDesc,
				'has-issues' : True,
				'has-wiki'   : False
			}
			req = requests.post('https://api.github.com/user/repos', data=json.dumps(data), auth=GithubCloner.getGithubAuth())

			if req.status_code != 201:
				raise Exception("Couldn't create the repository on Github")

			self.Commons.runSystemCommand(['rm', '-rf', f'{str(localDirectory)}/.git'])
			self.Commons.runSystemCommand(['git', '-C', str(localDirectory), 'init'])

			self.Commons.runSystemCommand(['git', 'config', '--global', 'user.email', '*****@*****.**'])
			self.Commons.runSystemCommand(['git', 'config', '--global', 'user.name', '*****@*****.**'])

			remote = f'https://{self.ConfigManager.getAliceConfigByName("githubUsername")}:{self.ConfigManager.getAliceConfigByName("githubToken")}@github.com/{self.ConfigManager.getAliceConfigByName("githubUsername")}/skill_{skillName}.git'
			self.Commons.runSystemCommand(['git', '-C', str(localDirectory), 'remote', 'add', 'origin', remote])

			self.Commons.runSystemCommand(['git', '-C', str(localDirectory), 'add', '--all'])
			self.Commons.runSystemCommand(['git', '-C', str(localDirectory), 'commit', '-m', '"Initial upload"'])
			self.Commons.runSystemCommand(['git', '-C', str(localDirectory), 'push', '--set-upstream', 'origin', 'master'])

			url = f'https://github.com/{self.ConfigManager.getAliceConfigByName("githubUsername")}/skill_{skillName}.git'
			self.logInfo(f'Skill uploaded! You can find it on {url}')
			return True
		except Exception as e:
			self.logWarning(f'Something went wrong uploading skill to Github: {e}')
			return False