Add github system
guix.scm
4 | 4 | (guix download) | |
5 | 5 | (guix git-download) | |
6 | 6 | (guix packages) | |
7 | + | (guix utils) | |
7 | 8 | (gnu packages aspell) | |
8 | 9 | (gnu packages check) | |
9 | 10 | (gnu packages enchant) | |
… | |||
368 | 369 | ("python-polib" ,python-polib) | |
369 | 370 | ("python-pyenchant" ,python-pyenchant) | |
370 | 371 | ("python-pygit2" ,python-pygit2) | |
372 | + | ("python-pygithub" ,python-pygithub) | |
371 | 373 | ("python-pyqt" ,python-pyqt) | |
372 | 374 | ("python-requests" ,python-requests) | |
373 | 375 | ("python-ruamel.yaml" ,python-ruamel.yaml) |
offlate/manager.py
18 | 18 | from .systems.tp import TPProject | |
19 | 19 | from .systems.transifex import TransifexProject | |
20 | 20 | from .systems.gitlab import GitlabProject | |
21 | + | from .systems.github import GithubProject | |
21 | 22 | from .formats.formatException import UnsupportedFormatException | |
22 | 23 | from .systems.list import * | |
23 | 24 | ||
… | |||
127 | 128 | for s in self.settings.conf["Generic"].keys(): | |
128 | 129 | settings[s] = self.settings.conf["Generic"][s] | |
129 | 130 | proj = GitlabProject(settings, name, lang, data) | |
131 | + | if system == GITHUB: | |
132 | + | if not 'Github' in self.settings.conf: | |
133 | + | self.settings.conf['Github'] = {} | |
134 | + | settings = self.settings.conf['Github'] | |
135 | + | for s in self.settings.conf["Generic"].keys(): | |
136 | + | settings[s] = self.settings.conf["Generic"][s] | |
137 | + | proj = GithubProject(settings, name, lang, data) | |
130 | 138 | self.project_list[name] = proj | |
131 | 139 | return proj | |
132 | 140 | ||
… | |||
198 | 206 | self.settings.conf["Generic"][s] = None | |
199 | 207 | settings[s] = self.settings.conf["Generic"][s] | |
200 | 208 | return GitlabProject.isConfigured(settings) | |
209 | + | elif system == GITHUB: | |
210 | + | if not "Github" in self.settings.conf: | |
211 | + | self.settings.conf["Github"] = {} | |
212 | + | settings = self.settings.conf["Github"] | |
213 | + | for s in self.settings.conf["Generic"].keys(): | |
214 | + | if not s in self.settings.conf["Generic"]: | |
215 | + | self.settings.conf["Generic"][s] = None | |
216 | + | settings[s] = self.settings.conf["Generic"][s] | |
217 | + | return GithubProject.isConfigured(settings) | |
201 | 218 | else: | |
202 | 219 | return False |
offlate/systems/github.py unknown status 1
1 | + | # Copyright (c) 2018 Julien Lepiller <julien@lepiller.eu> | |
2 | + | # | |
3 | + | # This program is free software: you can redistribute it and/or modify | |
4 | + | # it under the terms of the GNU Affero General Public License as | |
5 | + | # published by the Free Software Foundation, either version 3 of the | |
6 | + | # License, or (at your option) any later version. | |
7 | + | # | |
8 | + | # This program is distributed in the hope that it will be useful, | |
9 | + | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | + | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | + | # GNU Affero General Public License for more details. | |
12 | + | # | |
13 | + | # You should have received a copy of the GNU Affero General Public License | |
14 | + | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
15 | + | #### | |
16 | + | """ The gitlab system connector. """ | |
17 | + | ||
18 | + | from .git import GitProject | |
19 | + | ||
20 | + | from urllib.parse import urlparse | |
21 | + | from github import Github | |
22 | + | from pathlib import Path | |
23 | + | ||
24 | + | class GithubProject(GitProject): | |
25 | + | def __init__(self, conf, name, lang, data = {}): | |
26 | + | GitProject.__init__(self, conf, name, lang, data) | |
27 | + | ||
28 | + | def updateURI(self): | |
29 | + | repo = self.data['repo'] | |
30 | + | if repo.startswith('https://github.com/'): | |
31 | + | self.uri = repo | |
32 | + | elif repo.startswith('github.com/'): | |
33 | + | self.uri = 'https://' + repo | |
34 | + | else: | |
35 | + | self.uri = 'https://github.com/' + repo | |
36 | + | self.branch = self.data['branch'] | |
37 | + | ||
38 | + | def send(self, interface): | |
39 | + | gh = Github(self.conf['token']) | |
40 | + | ||
41 | + | currentUser = gh.get_user().login | |
42 | + | projectname = self.uri.split('/')[-1] | |
43 | + | projectfullname = urlparse(self.uri).path[1:] | |
44 | + | ||
45 | + | originproject = gh.get_repo(projectfullname) | |
46 | + | try: | |
47 | + | project = gl.get_repo(currentUser + "/" + projectname) | |
48 | + | except: | |
49 | + | project = gh.get_user().create_fork(originproject) | |
50 | + | ||
51 | + | try: | |
52 | + | sha = project.get_git_ref('heads/' + self.data['branch']).object.sha | |
53 | + | project.create_git_ref('refs/heads/translation', sha) | |
54 | + | except: | |
55 | + | interface.githubBranchError('translation') | |
56 | + | return | |
57 | + | ||
58 | + | for mfile in self.translationfiles: | |
59 | + | mfile = mfile['filename'] | |
60 | + | try: | |
61 | + | # workaround a bug, where we cannot get the content hash of a single file, by looking | |
62 | + | # for every file in the parent directory. | |
63 | + | contents = project.get_dir_contents(str(Path(mfile).parent), ref='translation') | |
64 | + | for c in contents: | |
65 | + | if c.path == mfile: | |
66 | + | sha = c.sha | |
67 | + | break | |
68 | + | project.update_file(path=mfile, message='Update ' + self.lang + ' translation', | |
69 | + | content=open(self.basedir + '/current/' + mfile).read(), | |
70 | + | sha=sha, branch='translation') | |
71 | + | except: | |
72 | + | project.create_file(path=mfile, message='Add ' + self.lang + ' translation', | |
73 | + | content=open(self.basedir + '/current/' + mfile).read(), | |
74 | + | branch='translation') | |
75 | + | originproject.create_pull(title='Update ' + self.lang + ' translation', | |
76 | + | body='Automatically submitted using Offlate. Report translation issues to the submitter, and Offlate issues to @roptat, thanks!', | |
77 | + | head=currentUser+':translation', | |
78 | + | base=self.data['branch'], | |
79 | + | maintainer_can_modify=True) | |
80 | + | ||
81 | + | @staticmethod | |
82 | + | def isConfigured(conf): | |
83 | + | res = GitProject.isConfigured(conf) | |
84 | + | res = res and 'token' in conf and conf['token'] != '' | |
85 | + | return res |
offlate/systems/list.py
13 | 13 | # You should have received a copy of the GNU Affero General Public License | |
14 | 14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
15 | 15 | #### | |
16 | - | """ The listo of system connectors. """ | |
16 | + | """ The list of system connectors. """ | |
17 | 17 | ||
18 | 18 | TRANSLATION_PROJECT = 0 | |
19 | 19 | TRANSIFEX = 1 | |
20 | 20 | GITLAB = 2 | |
21 | + | GITHUB = 3 |
offlate/ui/editor.py
60 | 60 | self.qd.showMessage(self.qd.tr("Error while creating branch {}.").format(branch)) | |
61 | 61 | self.qd.exec_() | |
62 | 62 | ||
63 | + | def githubBranchError(self, branch): | |
64 | + | self.qd = QErrorMessage() | |
65 | + | self.qd.showMessage(self.qd.tr("Error while creating branch {}.").format(branch)) | |
66 | + | self.qd.exec_() | |
67 | + | ||
63 | 68 | class ProjectView(QWidget): | |
64 | 69 | translationModified = pyqtSignal() | |
65 | 70 |
offlate/ui/new.py
68 | 68 | self.combo.addItem(self.tr("The Translation Project")) | |
69 | 69 | self.combo.addItem(self.tr("Transifex")) | |
70 | 70 | self.combo.addItem(self.tr("Gitlab")) | |
71 | + | self.combo.addItem(self.tr("Github")) | |
71 | 72 | self.combo.setCurrentIndex(self.system) | |
72 | 73 | self.formLayout.addRow(self.combo) | |
73 | 74 | ||
… | |||
89 | 90 | self.additionalFields.append([]) | |
90 | 91 | self.additionalFields.append([]) | |
91 | 92 | self.additionalFields.append([]) | |
93 | + | self.additionalFields.append([]) | |
92 | 94 | ||
93 | 95 | # Transifex | |
94 | 96 | self.transifexOrganisation = QLineEdit() | |
… | |||
114 | 116 | self.gitlabRepo.setText(self.info['repo']) | |
115 | 117 | self.gitlabBranch.setText(self.info['branch']) | |
116 | 118 | ||
119 | + | # Github | |
120 | + | self.githubRepo = QLineEdit() | |
121 | + | self.githubRepo.textChanged.connect(self.modify) | |
122 | + | githubRepoLabel = QLabel(self.tr('repository')) | |
123 | + | self.additionalFields[GITHUB].append({'label': githubRepoLabel, | |
124 | + | 'widget': self.githubRepo}) | |
125 | + | self.githubBranch = QLineEdit() | |
126 | + | self.githubBranch.textChanged.connect(self.modify) | |
127 | + | githubBranchLabel = QLabel(self.tr('branch')) | |
128 | + | self.additionalFields[GITHUB].append({'label': githubBranchLabel, | |
129 | + | 'widget': self.githubBranch}) | |
130 | + | if self.system == GITHUB: | |
131 | + | self.githubRepo.setText(self.info['repo']) | |
132 | + | self.githubBranch.setText(self.info['branch']) | |
133 | + | ||
117 | 134 | self.setLayout(hbox) | |
118 | 135 | ||
119 | 136 | self.predefinedprojects.currentItemChanged.connect(self.fill) | |
… | |||
138 | 155 | if data['system'] == GITLAB: | |
139 | 156 | self.gitlabRepo.setText(data['repo']) | |
140 | 157 | self.gitlabBranch.setText(data['branch']) | |
158 | + | if data['system'] == GITHUB: | |
159 | + | self.githubRepo.setText(data['repo']) | |
160 | + | self.githubBranch.setText(data['branch']) | |
141 | 161 | ||
142 | 162 | def filter(self): | |
143 | 163 | search = self.searchfield.text() | |
… | |||
179 | 199 | if self.getProjectSystem() == GITLAB: | |
180 | 200 | return {'repo': self.additionalFields[GITLAB][0]['widget'].text(), | |
181 | 201 | 'branch': self.additionalFields[GITLAB][1]['widget'].text()} | |
202 | + | if self.getProjectSystem() == GITHUB: | |
203 | + | return {'repo': self.additionalFields[GITHUB][0]['widget'].text(), | |
204 | + | 'branch': self.additionalFields[GITHUB][1]['widget'].text()} | |
182 | 205 | return {} | |
183 | 206 | ||
184 | 207 | def othersystem(self): |
setup.py
13 | 13 | packages=find_packages(exclude=['.guix-profile*']), | |
14 | 14 | python_requires = '>=3', | |
15 | 15 | install_requires=['polib', 'ruamel.yaml', 'python-dateutil', 'PyQt5', 'pygit2', | |
16 | - | 'python-gitlab', 'translation-finder', 'android-stringslib', 'watchdog'], | |
16 | + | 'python-gitlab', 'translation-finder', 'android-stringslib', 'watchdog', | |
17 | + | 'PyGithub'], | |
17 | 18 | entry_points={ | |
18 | 19 | 'gui_scripts': [ | |
19 | 20 | 'offlate=offlate.ui.main:main', |