Commit 66233ec5acba574c8c9b81cc3a7f9d83ef14c9ab
0 parents
Exists in
master
and in
1 other branch
Initial commit
Showing
19 changed files
with
353 additions
and
0 deletions
Show diff stats
1 | +++ a/MANIFEST.in | ||
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +include DESCRIPTION.rst | ||
2 | + | ||
3 | +# Include the test suite (FIXME: does not work yet) | ||
4 | +# recursive-include tests * | ||
5 | + | ||
6 | +# If using Python 2.6 or less, then have to include package data, even though | ||
7 | +# it's already declared in setup.py | ||
8 | +include requirements.txt |
1 | +++ a/README.rst | ||
@@ -0,0 +1,84 @@ | @@ -0,0 +1,84 @@ | ||
1 | +.. -*- coding: utf-8 -*- | ||
2 | + | ||
3 | +.. highlight:: rest | ||
4 | + | ||
5 | +.. _colab_software: | ||
6 | + | ||
7 | +================================= | ||
8 | +Colab-Gitlab - Gitlab proxy Plugin | ||
9 | +================================= | ||
10 | + | ||
11 | + | ||
12 | + | ||
13 | +What is Colab? | ||
14 | +============== | ||
15 | + | ||
16 | +Application that integrates existing systems to represent the contributions of the members through: | ||
17 | + | ||
18 | +* The amendments to the Wiki trac system. | ||
19 | + | ||
20 | +* Changes to the trac system code. | ||
21 | + | ||
22 | +* Discussions at the mailman list. | ||
23 | + | ||
24 | +* And other systems in the community. | ||
25 | + | ||
26 | + | ||
27 | + | ||
28 | +Features | ||
29 | +======== | ||
30 | + | ||
31 | +* Developed by Interlegis Communities http://colab.interlegis.leg.br/ | ||
32 | + | ||
33 | +* Written in Python http://python.org/ | ||
34 | + | ||
35 | +* Built with Django Web Framework https://www.djangoproject.com/ | ||
36 | + | ||
37 | +* Search engine with Solr https://lucene.apache.org/solr/ | ||
38 | + | ||
39 | + | ||
40 | + | ||
41 | +Installation | ||
42 | +============ | ||
43 | + | ||
44 | +After installing the colab-gitlab | ||
45 | + | ||
46 | +.. code-block:: | ||
47 | + | ||
48 | + pip install colab-gitlab | ||
49 | + | ||
50 | +Alter the colab configuration file and uncomment the lines for the gitlab configuration, | ||
51 | +set your upstream(gitlab) address and private_token for the gitlab api: | ||
52 | + | ||
53 | +.. code-block:: | ||
54 | + | ||
55 | + vim /etc/colab/settings.yaml | ||
56 | + | ||
57 | + PROXIED_APPS: | ||
58 | + gitlab: | ||
59 | + upstream: 'http://localhost:8090/gitlab/' | ||
60 | + private_token: '' | ||
61 | + | ||
62 | + | ||
63 | +Running Colab | ||
64 | +============= | ||
65 | + | ||
66 | +To run Colab with development server you will have to: | ||
67 | + | ||
68 | +1- Create the example configuration file: | ||
69 | + | ||
70 | +.. code-block:: | ||
71 | + | ||
72 | + colab-init-config > /etc/colab/settings.yaml | ||
73 | + | ||
74 | +2- Edit the configuration file. Make sure you set everything you need including **database** credentials. | ||
75 | + | ||
76 | +3- Run the development server: | ||
77 | + | ||
78 | +.. code-block:: | ||
79 | + | ||
80 | + colab-admin runserver 0.0.0.0:8000 | ||
81 | + | ||
82 | + | ||
83 | +**NOTE**: In case you want to keep the configuration file else where just set the | ||
84 | +desired location in environment variable **COLAB_SETTINGS**. |
1 | +++ a/colab/proxy/gitlab/__init__.py |
1 | +++ a/colab/proxy/gitlab/data_api.py | ||
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +from colab.proxy.gitlab.models import * | ||
2 | +from colab.proxy.proxybase.proxy_data_api import ProxyDataAPI | ||
3 | +from django.db.models.fields import DateTimeField | ||
4 | +from dateutil.parser import parse | ||
5 | +import urllib2 | ||
6 | +import json | ||
7 | +from django.conf import settings | ||
8 | + | ||
9 | +class GitlabDataAPI(ProxyDataAPI): | ||
10 | + | ||
11 | + | ||
12 | + def fetchProjects(self): | ||
13 | + page = 1 | ||
14 | + projects = [] | ||
15 | + | ||
16 | + proxy_config = settings.PROXIED_APPS.get(self.app_label, {}) | ||
17 | + admin_token = proxy_config.get('auth_token') | ||
18 | + | ||
19 | + # Iterates throughout all projects pages | ||
20 | + while(True): | ||
21 | + data = urllib2.urlopen('https://beta.softwarepublico.gov.br/gitlab/api/v3/projects/all?private_token={}&per_page=100&page={}'.format(admin_token, page)) | ||
22 | + json_data = json.load(data) | ||
23 | + | ||
24 | + if len(json_data) == 0: | ||
25 | + break | ||
26 | + | ||
27 | + page = page + 1 | ||
28 | + | ||
29 | + for element in json_data: | ||
30 | + project = GitlabProject() | ||
31 | + | ||
32 | + for field in GitlabProject._meta.fields: | ||
33 | + value = element[field.name] | ||
34 | + value = parse(element[field.name]) if isinstance(field, DateTimeField) else value | ||
35 | + setattr(project, field.name, value) | ||
36 | + | ||
37 | + projects.append(project) | ||
38 | + | ||
39 | + return projects | ||
40 | + | ||
41 | + | ||
42 | + def fetchData(self): | ||
43 | + data = self.fetchProjects() | ||
44 | + | ||
45 | + for datum in data: | ||
46 | + datum.save() | ||
47 | + | ||
48 | + @property | ||
49 | + def app_label(self): | ||
50 | + return 'gitlab' | ||
51 | + |
1 | +++ a/colab/proxy/gitlab/diazo.xml | ||
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +<rules | ||
2 | + xmlns="http://namespaces.plone.org/diazo" | ||
3 | + xmlns:css="http://namespaces.plone.org/diazo/css" | ||
4 | + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
5 | + | ||
6 | + <before theme-children="/html/head" content-children="/html/head" /> | ||
7 | + <before css:theme-children="#main-content" css:content-children="body" /> | ||
8 | + | ||
9 | + <merge attributes="class" css:theme="body" css:content="body" /> | ||
10 | + | ||
11 | + <!-- Add gitlab properties --> | ||
12 | + <merge attributes="data-page" css:theme="body" css:content="body" /> | ||
13 | + <merge attributes="data-project-id" css:theme="body" css:content="body" /> | ||
14 | + | ||
15 | + <drop css:content="#top-panel" /> | ||
16 | + <drop css:content=".navbar-gitlab" /> | ||
17 | + <drop css:content=".git-clone-holder .btn:contains('HTTPS')" /> | ||
18 | +</rules> |
1 | +++ a/colab/proxy/gitlab/migrations/0001_initial.py | ||
@@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
1 | +# -*- coding: utf-8 -*- | ||
2 | +from __future__ import unicode_literals | ||
3 | + | ||
4 | +from django.db import models, migrations | ||
5 | + | ||
6 | + | ||
7 | +class Migration(migrations.Migration): | ||
8 | + | ||
9 | + dependencies = [ | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.CreateModel( | ||
14 | + name='GitlabProject', | ||
15 | + fields=[ | ||
16 | + ('id', models.IntegerField(serialize=False, primary_key=True)), | ||
17 | + ('description', models.TextField()), | ||
18 | + ('public', models.BooleanField(default=True)), | ||
19 | + ('name', models.TextField()), | ||
20 | + ('name_with_namespace', models.TextField()), | ||
21 | + ('created_at', models.DateTimeField(blank=True)), | ||
22 | + ('last_activity_at', models.DateTimeField(blank=True)), | ||
23 | + ], | ||
24 | + options={ | ||
25 | + }, | ||
26 | + bases=(models.Model,), | ||
27 | + ), | ||
28 | + ] |
1 | +++ a/colab/proxy/gitlab/migrations/__init__.py |
1 | +++ a/colab/proxy/gitlab/models.py | ||
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +from django.db import models | ||
2 | +from django.conf import settings | ||
3 | +from colab.accounts.models import User | ||
4 | + | ||
5 | +class GitlabProject(models.Model): | ||
6 | + | ||
7 | + id = models.IntegerField(primary_key=True) | ||
8 | + description = models.TextField() | ||
9 | + public = models.BooleanField(default=True) | ||
10 | + name = models.TextField() | ||
11 | + name_with_namespace = models.TextField() | ||
12 | + created_at = models.DateTimeField(blank=True) | ||
13 | + last_activity_at = models.DateTimeField(blank=True) |
1 | +++ a/colab/proxy/gitlab/templates/proxy/gitlab.html | ||
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +{% extends 'base.html' %} | ||
2 | +{% load static from staticfiles %} | ||
3 | + | ||
4 | +{% block head_css %} | ||
5 | +<style> | ||
6 | + /* Reset left and with for .modal-dialog style (like gitlab does), | ||
7 | + the bootstrap.css one makes it small */ | ||
8 | + @media screen and (min-width: 768px) { | ||
9 | + .modal-dialog { | ||
10 | + left: auto; | ||
11 | + width: auto; | ||
12 | + } | ||
13 | + } | ||
14 | + div#main-content { | ||
15 | + margin-top: 65px; | ||
16 | + } | ||
17 | + | ||
18 | + div#main-content div.container { | ||
19 | + width: 1110px; | ||
20 | + } | ||
21 | + div#main-content div.flash-container{ | ||
22 | + width: 85%; | ||
23 | + } | ||
24 | + #breadcrumbs { | ||
25 | + border: 0 !important; | ||
26 | + } | ||
27 | + | ||
28 | + #right-top-nav { | ||
29 | + margin-right: 5em !important; | ||
30 | + } | ||
31 | +</style> | ||
32 | +{% endblock %} | ||
33 | + | ||
34 | +{% block head_js %} | ||
35 | +<script type="text/javascript"> | ||
36 | + $(function(){ | ||
37 | + // bootstrap.css forces .hide {display:none!important}, and this makes | ||
38 | + // gitlab .hide elements NEVER have a display:block, so | ||
39 | + // instead of editing bootstrap.css, we just removed '.hide' css class and | ||
40 | + // toggled | ||
41 | + $('.hide').removeClass('hide').css('display', 'none'); | ||
42 | + | ||
43 | + // Hit the SSH clone button to select it by default | ||
44 | + jQuery(".git-clone-holder .btn:contains('SSH')").click() | ||
45 | + | ||
46 | + }); | ||
47 | +</script> | ||
48 | +<script type="text/javascript" src="{% static 'third-party/bootstrap/js/bootstrap.min.js' %}"></script> | ||
49 | +<script type="text/javascript" src="{% static 'third-party/jquery.cookie.js' %}"></script> | ||
50 | +<script>jQuery.noConflict();</script> | ||
51 | +{% endblock %} |
1 | +++ a/setup.py | ||
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | + | ||
2 | +from setuptools import setup, find_packages | ||
3 | +from pip.download import PipSession | ||
4 | +from pip.req import parse_requirements | ||
5 | + | ||
6 | +import os | ||
7 | +# if you are not using vagrant, just delete os.link directly, | ||
8 | +# The hard link only saves a little disk space, so you should not care | ||
9 | +if os.environ.get('USER', '') == 'vagrant': | ||
10 | + del os.link | ||
11 | + | ||
12 | +session = PipSession() | ||
13 | +reqs = [str(req.req) for req in parse_requirements('requirements.txt', | ||
14 | + session=session) if req.req] | ||
15 | + | ||
16 | +EXCLUDE_FROM_PACKAGES = [] | ||
17 | + | ||
18 | + | ||
19 | +setup( | ||
20 | + name='colab-gitlab', | ||
21 | + version='0.1.0', | ||
22 | + url='https://github.com/colab-community/colab_gitlab', | ||
23 | + author='Sergio Oliveira', | ||
24 | + author_email='sergio@tracy.com.br', | ||
25 | + description= | ||
26 | + 'Gitlab plugin for Colab, a colaboration platform for communities', | ||
27 | + license='LICENSE.txt', | ||
28 | + packages=find_packages(exclude="EXCLUDE_FROM_PACKAGES"), | ||
29 | + include_package_data=True, | ||
30 | + namespace_packages=['colab', 'colab.proxy'], | ||
31 | + zip_safe=False, | ||
32 | + long_description=open('README.rst').read(), | ||
33 | + install_requires=reqs, | ||
34 | + classifiers=[ | ||
35 | + 'Development Status :: 3 - Alpha', | ||
36 | + 'Environment :: Web Environment', | ||
37 | + 'Framework :: Django', | ||
38 | + 'Intended Audience :: Developers', | ||
39 | + 'Operating System :: OS Independent', | ||
40 | + 'Programming Language :: Python', | ||
41 | + 'Programming Language :: Python :: 2', | ||
42 | + 'Programming Language :: Python :: 2.7', | ||
43 | + 'Topic :: Internet :: WWW/HTTP', | ||
44 | + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', | ||
45 | + 'Topic :: Internet :: WWW/HTTP :: WSGI', | ||
46 | + ], | ||
47 | +) |