def test_protos(self): self.assertEqual( giturlparse("https://bitbucket.org/org/repo.git").proto, "https") self.assertEqual( giturlparse("git://bitbucket.org/org/repo.git").proto, "git") self.assertEqual( giturlparse("ssh://[email protected]:org/repo.git").proto, "ssh") self.assertEqual( giturlparse("[email protected]:org/repo.git").proto, "ssh")
def test_gitlab_port(self): for u in [ "ssh://[email protected]:1234/group/subgrouptest/testproject.git"]: u = giturlparse(u) self.assertEqual(u.domain, "mygitlab.com") self.assertEqual(u.port, 1234) self.assertEqual(u.user, "buildbot") self.assertEqual(u.owner, "group/subgrouptest") self.assertEqual(u.repo, "testproject")
def test_gitlab_port(self): for u in [ "ssh://[email protected]:1234/group/subgrouptest/testproject.git" ]: u = giturlparse(u) self.assertEqual(u.domain, "mygitlab.com") self.assertEqual(u.port, 1234) self.assertEqual(u.user, "buildbot") self.assertEqual(u.owner, "group/subgrouptest") self.assertEqual(u.repo, "testproject")
def test_gitlab_user(self): for u in [ "ssh://[email protected]:group/subgrouptest/testproject.git", "https://[email protected]/group/subgrouptest/testproject.git"]: u = giturlparse(u) self.assertEqual(u.domain, "mygitlab.com") self.assertIsNone(u.port) self.assertEqual(u.user, "buildbot") self.assertEqual(u.owner, "group/subgrouptest") self.assertEqual(u.repo, "testproject")
def test_gitlab_subsubgroup(self): for u in [ "ssh://[email protected]/group/subgrouptest/subsubgroup/testproject.git", "https://mygitlab.com/group/subgrouptest/subsubgroup/testproject.git", "git://mygitlab.com/group/subgrouptest/subsubgroup/testproject.git"]: u = giturlparse(u) self.assertIn(u.user, (None, "git")) self.assertEqual(u.domain, "mygitlab.com") self.assertEqual(u.owner, "group/subgrouptest/subsubgroup") self.assertEqual(u.repo, "testproject")
def test_gitlab_subsubgroup(self): for u in [ "ssh://[email protected]/group/subgrouptest/subsubgroup/testproject.git", "https://mygitlab.com/group/subgrouptest/subsubgroup/testproject.git", "git://mygitlab.com/group/subgrouptest/subsubgroup/testproject.git" ]: u = giturlparse(u) self.assertIn(u.user, (None, "git")) self.assertEqual(u.domain, "mygitlab.com") self.assertEqual(u.owner, "group/subgrouptest/subsubgroup") self.assertEqual(u.repo, "testproject")
def test_gitlab_user(self): for u in [ "ssh://[email protected]:group/subgrouptest/testproject.git", "https://[email protected]/group/subgrouptest/testproject.git" ]: u = giturlparse(u) self.assertEqual(u.domain, "mygitlab.com") self.assertIsNone(u.port) self.assertEqual(u.user, "buildbot") self.assertEqual(u.owner, "group/subgrouptest") self.assertEqual(u.repo, "testproject")
def test_github(self): for u in [ "https://github.com/buildbot/buildbot", "https://github.com/buildbot/buildbot.git", "ssh://[email protected]:buildbot/buildbot.git", "git://github.com/buildbot/buildbot.git"]: u = giturlparse(u) self.assertIn(u.user, (None, "git")) self.assertEqual(u.domain, "github.com") self.assertEqual(u.owner, "buildbot") self.assertEqual(u.repo, "buildbot")
def test_bitbucket(self): for u in [ "https://bitbucket.org/org/repo.git", "ssh://[email protected]:org/repo.git", "[email protected]:org/repo.git", ]: u = giturlparse(u) self.assertIn(u.user, (None, "git")) self.assertEqual(u.domain, "bitbucket.org") self.assertEqual(u.owner, "org") self.assertEqual(u.repo, "repo")
def test_github(self): for u in [ "https://github.com/buildbot/buildbot", "https://github.com/buildbot/buildbot.git", "ssh://[email protected]:buildbot/buildbot.git", "git://github.com/buildbot/buildbot.git" ]: u = giturlparse(u) self.assertIn(u.user, (None, "git")) self.assertEqual(u.domain, "github.com") self.assertEqual(u.owner, "buildbot") self.assertEqual(u.repo, "buildbot")
def test_no_owner(self): for u in [ "https://example.org/repo.git", "ssh://example.org:repo.git", "ssh://[email protected]:repo.git", "[email protected]:repo.git", ]: u = giturlparse(u) self.assertIn(u.user, (None, "git")) self.assertEqual(u.domain, "example.org") self.assertIsNone(u.owner) self.assertEqual(u.repo, "repo")
def getProjectId(self, sourcestamp): # retrieve project id via cache url = giturlparse(sourcestamp['repository']) if url is None: return None project_full_name = f"{url.owner}/{url.repo}" # gitlab needs project name to be fully url quoted to get the project id project_full_name = urlquote_plus(project_full_name) if project_full_name not in self.project_ids: response = yield self._http.get( f'/api/v4/projects/{project_full_name}') proj = yield response.json() if response.code not in (200, ): log.msg('Unknown (or hidden) gitlab project' f'{project_full_name}: {proj.get("message")}') return None self.project_ids[project_full_name] = proj['id'] return self.project_ids[project_full_name]
def getProjectId(self, sourcestamp): # retrieve project id via cache url = giturlparse(sourcestamp['repository']) if url is None: return None project_full_name = "{}/{}".format(url.owner, url.repo) # gitlab needs project name to be fully url quoted to get the project id project_full_name = urlquote_plus(project_full_name) if project_full_name not in self.project_ids: response = yield self._http.get( '/api/v4/projects/{}'.format(project_full_name)) proj = yield response.json() if response.code not in (200, ): log.msg('Unknown (or hidden) gitlab project' '{repo}: {message}'.format(repo=project_full_name, **proj)) return None self.project_ids[project_full_name] = proj['id'] return self.project_ids[project_full_name]
def getProjectId(self, sourcestamp): # retrieve project id via cache url = giturlparse(sourcestamp['repository']) if url is None: return None project_full_name = "%s/%s" % (url.owner, url.repo) # gitlab needs project name to be fully url quoted to get the project id project_full_name = urlquote_plus(project_full_name) if project_full_name not in self.project_ids: response = yield self._http.get('/api/v4/projects/%s' % (project_full_name)) proj = yield response.json() if response.code not in (200, ): log.msg( 'Unknown (or hidden) gitlab project' '{repo}: {message}'.format( repo=project_full_name, **proj)) return None self.project_ids[project_full_name] = proj['id'] return self.project_ids[project_full_name]
def getProjectId(self, sourcestamp): # retrieve project id via cache url = giturlparse(sourcestamp['repository']) if url is None: defer.returnValue(None) project_full_name = u"%s/%s" % (url.owner, url.repo) project_full_name = unicode2NativeString(project_full_name) # gitlab needs project name to be fully url quoted to get the project id project_full_name = urlquote_plus(project_full_name) if project_full_name not in self.project_ids: response = yield self._http.get('/api/v3/projects/%s' % (project_full_name)) proj = yield response.json() if response.code not in (200, ): log.msg( 'Unknown (or hidden) gitlab project' '{repo}: {message}'.format( repo=project_full_name, **proj)) defer.returnValue(None) self.project_ids[project_full_name] = proj['id'] defer.returnValue(self.project_ids[project_full_name])
def generator(self, chdict): repourl = giturlparse(chdict['repository']) if repourl.owner == self.owner and repourl.repo in self.repos: return repourl.repo return None
def test_protos(self): self.assertEqual(giturlparse("https://bitbucket.org/org/repo.git").proto, "https") self.assertEqual(giturlparse("git://bitbucket.org/org/repo.git").proto, "git") self.assertEqual(giturlparse("ssh://[email protected]:org/repo.git").proto, "ssh") self.assertEqual(giturlparse("[email protected]:org/repo.git").proto, "ssh")