Commit 41733eb8 authored by Stenio Araujo's avatar Stenio Araujo
Browse files

First commit, top

parents
# Created by https://www.gitignore.io/api/python,visualstudiocode
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
### Python Patch ###
.venv/
### VisualStudioCode ###
.vscode/*
# End of https://www.gitignore.io/api/python,visualstudiocode
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[dev-packages]
pylint = "*"
[packages]
flask-api = "*"
requests = "*"
{
"_meta": {
"hash": {
"sha256": "505aadd8035031a693152fea307139f3a8db86312130df84e9fc1b8c2a9858ff"
},
"host-environment-markers": {
"implementation_name": "cpython",
"implementation_version": "0",
"os_name": "posix",
"platform_machine": "x86_64",
"platform_python_implementation": "CPython",
"platform_release": "4.4.0-130-generic",
"platform_system": "Linux",
"platform_version": "#156-Ubuntu SMP Thu Jun 14 08:53:28 UTC 2018",
"python_full_version": "2.7.12",
"python_version": "2.7",
"sys_platform": "linux2"
},
"pipfile-spec": 6,
"requires": {},
"sources": [
{
"name": "pypi",
"url": "https://pypi.python.org/simple",
"verify_ssl": true
}
]
},
"default": {
"certifi": {
"hashes": [
"sha256:9fa520c1bacfb634fa7af20a76bcbd3d5fb390481724c597da32c719a7dca4b0",
"sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7"
],
"version": "==2018.4.16"
},
"chardet": {
"hashes": [
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691",
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"
],
"version": "==3.0.4"
},
"click": {
"hashes": [
"sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d",
"sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b"
],
"version": "==6.7"
},
"flask": {
"hashes": [
"sha256:a080b744b7e345ccfcbc77954861cb05b3c63786e93f2b3875e0913d44b43f05",
"sha256:2271c0070dbcb5275fad4a82e29f23ab92682dc45f9dfbc22c02ba9b9322ce48"
],
"version": "==1.0.2"
},
"flask-api": {
"hashes": [
"sha256:6f9dc56d55fd82ffb1c5c9fd794cd6c50873ac10cf662e26817c179a655d1e22",
"sha256:fc10a80a13ea6fcf04acc2b1835aea05ec44aa6ae94f2ee85e52cd068567ce35"
],
"version": "==1.0"
},
"idna": {
"hashes": [
"sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e",
"sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16"
],
"version": "==2.7"
},
"itsdangerous": {
"hashes": [
"sha256:cbb3fcf8d3e33df861709ecaf89d9e6629cff0a217bc2848f1b41cd30d360519"
],
"version": "==0.24"
},
"jinja2": {
"hashes": [
"sha256:74c935a1b8bb9a3947c50a54766a969d4846290e1e788ea44c1392163723c3bd",
"sha256:f84be1bb0040caca4cea721fcbbbbd61f9be9464ca236387158b0feea01914a4"
],
"version": "==2.10"
},
"markupsafe": {
"hashes": [
"sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665"
],
"version": "==1.0"
},
"requests": {
"hashes": [
"sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1",
"sha256:ec22d826a36ed72a7358ff3fe56cbd4ba69dd7a6718ffd450ff0e9df7a47ce6a"
],
"version": "==2.19.1"
},
"urllib3": {
"hashes": [
"sha256:b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5",
"sha256:a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf"
],
"version": "==1.23"
},
"werkzeug": {
"hashes": [
"sha256:d5da73735293558eb1651ee2fddc4d0dedcfa06538b8813a2e20011583c9e49b",
"sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c"
],
"version": "==0.14.1"
}
},
"develop": {
"astroid": {
"hashes": [
"sha256:0ef2bf9f07c3150929b25e8e61b5198c27b0dca195e156f0e4d5bdd89185ca1a",
"sha256:fc9b582dba0366e63540982c3944a9230cbc6f303641c51483fa547dcc22393a"
],
"version": "==1.6.5"
},
"backports.functools-lru-cache": {
"hashes": [
"sha256:f0b0e4eba956de51238e17573b7087e852dfe9854afd2e9c873f73fc0ca0a6dd",
"sha256:9d98697f088eb1b0fa451391f91afb5e3ebde16bbdb272819fd091151fda4f1a"
],
"markers": "python_version == '2.7'",
"version": "==1.5"
},
"configparser": {
"hashes": [
"sha256:5308b47021bc2340965c371f0f058cc6971a04502638d4244225c49d80db273a"
],
"markers": "python_version == '2.7'",
"version": "==3.5.0"
},
"enum34": {
"hashes": [
"sha256:6bd0f6ad48ec2aa117d3d141940d484deccda84d4fcd884f5c3d93c23ecd8c79",
"sha256:644837f692e5f550741432dd3f223bbb9852018674981b1664e5dc339387588a",
"sha256:8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1",
"sha256:2d81cbbe0e73112bdfe6ef8576f2238f2ba27dd0d55752a776c41d38b7da2850"
],
"markers": "python_version < '3.4'",
"version": "==1.1.6"
},
"futures": {
"hashes": [
"sha256:ec0a6cb848cc212002b9828c3e34c675e0c9ff6741dc445cab6fdd4e1085d1f1",
"sha256:9ec02aa7d674acb8618afb127e27fde7fc68994c0437ad759fa094a574adb265"
],
"version": "==3.2.0"
},
"isort": {
"hashes": [
"sha256:ec9ef8f4a9bc6f71eec99e1806bfa2de401650d996c59330782b89a5555c1497",
"sha256:1153601da39a25b14ddc54955dbbacbb6b2d19135386699e2ad58517953b34af",
"sha256:b9c40e9750f3d77e6e4d441d8b0266cf555e7cdabdcff33c4fd06366ca761ef8"
],
"version": "==4.3.4"
},
"lazy-object-proxy": {
"hashes": [
"sha256:209615b0fe4624d79e50220ce3310ca1a9445fd8e6d3572a896e7f9146bbf019",
"sha256:1b668120716eb7ee21d8a38815e5eb3bb8211117d9a90b0f8e21722c0758cc39",
"sha256:cb924aa3e4a3fb644d0c463cad5bc2572649a6a3f68a7f8e4fbe44aaa6d77e4c",
"sha256:2c1b21b44ac9beb0fc848d3993924147ba45c4ebc24be19825e57aabbe74a99e",
"sha256:320ffd3de9699d3892048baee45ebfbbf9388a7d65d832d7e580243ade426d2b",
"sha256:2df72ab12046a3496a92476020a1a0abf78b2a7db9ff4dc2036b8dd980203ae6",
"sha256:27ea6fd1c02dcc78172a82fc37fcc0992a94e4cecf53cb6d73f11749825bd98b",
"sha256:e5b9e8f6bda48460b7b143c3821b21b452cb3a835e6bbd5dd33aa0c8d3f5137d",
"sha256:7661d401d60d8bf15bb5da39e4dd72f5d764c5aff5a86ef52a042506e3e970ff",
"sha256:61a6cf00dcb1a7f0c773ed4acc509cb636af2d6337a08f362413c76b2b47a8dd",
"sha256:bd6292f565ca46dee4e737ebcc20742e3b5be2b01556dafe169f6c65d088875f",
"sha256:933947e8b4fbe617a51528b09851685138b49d511af0b6c0da2539115d6d4514",
"sha256:d0fc7a286feac9077ec52a927fc9fe8fe2fabab95426722be4c953c9a8bede92",
"sha256:7f3a2d740291f7f2c111d86a1c4851b70fb000a6c8883a59660d95ad57b9df35",
"sha256:5276db7ff62bb7b52f77f1f51ed58850e315154249aceb42e7f4c611f0f847ff",
"sha256:94223d7f060301b3a8c09c9b3bc3294b56b2188e7d8179c762a1cda72c979252",
"sha256:6ae6c4cb59f199d8827c5a07546b2ab7e85d262acaccaacd49b62f53f7c456f7",
"sha256:f460d1ceb0e4a5dcb2a652db0904224f367c9b3c1470d5a7683c0480e582468b",
"sha256:e81ebf6c5ee9684be8f2c87563880f93eedd56dd2b6146d8a725b50b7e5adb0f",
"sha256:81304b7d8e9c824d058087dcb89144842c8e0dea6d281c031f59f0acf66963d4",
"sha256:ddc34786490a6e4ec0a855d401034cbd1242ef186c20d79d2166d6a4bd449577",
"sha256:7bd527f36a605c914efca5d3d014170b2cb184723e423d26b1fb2fd9108e264d",
"sha256:ab3ca49afcb47058393b0122428358d2fbe0408cf99f1b58b295cfeb4ed39109",
"sha256:7cb54db3535c8686ea12e9535eb087d32421184eacc6939ef15ef50f83a5e7e2",
"sha256:0ce34342b419bd8f018e6666bfef729aec3edf62345a53b537a4dcc115746a33",
"sha256:e34b155e36fa9da7e1b7c738ed7767fc9491a62ec6af70fe9da4a057759edc2d",
"sha256:50e3b9a464d5d08cc5227413db0d1c4707b6172e4d4d915c1c70e4de0bbff1f5",
"sha256:27bf62cb2b1a2068d443ff7097ee33393f8483b570b475db8ebf7e1cba64f088",
"sha256:eb91be369f945f10d3a49f5f9be8b3d0b93a4c2be8f8a5b83b0571b8123e0a7a"
],
"version": "==1.3.1"
},
"mccabe": {
"hashes": [
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
],
"version": "==0.6.1"
},
"pylint": {
"hashes": [
"sha256:a48070545c12430cfc4e865bf62f5ad367784765681b3db442d8230f0960aa3c",
"sha256:fff220bcb996b4f7e2b0f6812fd81507b72ca4d8c4d05daf2655c333800cb9b3"
],
"version": "==1.9.2"
},
"singledispatch": {
"hashes": [
"sha256:833b46966687b3de7f438c761ac475213e53b306740f1abfaa86e1d1aae56aa8",
"sha256:5b06af87df13818d14f08a028e42f566640aef80805c3b50c5056b086e3c2b9c"
],
"markers": "python_version < '3.4'",
"version": "==3.4.0.3"
},
"six": {
"hashes": [
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb",
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"
],
"version": "==1.11.0"
},
"wrapt": {
"hashes": [
"sha256:d4d560d479f2c21e1b5443bbd15fe7ec4b37fe7e53d335d3b9b0a7b1226fe3c6"
],
"version": "==1.10.11"
}
}
}
"""API to use with slack slash commands
Use the GitLab API
https://git.lsd.ufcg.edu.br/help/api/README.md
https://git.lsd.ufcg.edu.br/help/api/groups.md#list-a-groups-projects
https://git.lsd.ufcg.edu.br/help/api/merge_requests.md#list-project-merge-requests
https://git.lsd.ufcg.edu.br/help/api/groups.md#search-for-group -- search=ztp will match ztp and ztp-interno
"""
import os
import sys
from flask import request
from flask_api import FlaskAPI, status
import requests
app = FlaskAPI(__name__)
SECRET_ACCESS_KEY = os.environ.get('SECRET_ACCESS_KEY')
GITLAB_PERSONAL_TOKEN = os.environ.get('GITLAB_PERSONAL_TOKEN')
GROUPS_PATH = "https://git.lsd.ufcg.edu.br/api/v4/groups"
PROJECTS_PATH = "https://git.lsd.ufcg.edu.br/api/v4/projects"
GROUP_PROJECTS = GROUPS_PATH + "/{}/projects"
PROJECT_OPENED_MERGE_REQUESTS = (
PROJECTS_PATH + "/{}/merge_requests?state=opened")
PROJECT_OPENED_ISSUES = PROJECTS_PATH + "/{}/issues?state=opened"
groups_name_to_id = {}
@app.route("/")
def index():
return {"o":"k"}
@app.route("/slash", methods=['GET', 'POST'])
def slash():
accept_mr_keywords = ["merges", "merge_requests", "mergerequests",
"merge requests" "merge-requests"]
accept_issues_keywords = ["issue", "issues"]
msg = """Hello
World! :smile:
"""
return msg
@app.route("/issues")
def open_issues():
# 216: ztp, 241: ztp-interno
try:
groups_names_param = request.args.get('groups_names')
groups_ids = _get_groups_ids_for_names(groups_names_param.split(','))
except:
groups_ids = []
issues = {}
for group_id in groups_ids:
projects_ids = (project['id'] for project in _get_projects([group_id]))
issues[_groups_id_to_name(group_id)] = _get_opened_issues(projects_ids)
return issues
@app.route("/merge_requests")
def open_merge_requests():
# 216: ztp, 241: ztp-interno
try:
groups_names_param = request.args.get('groups_names')
groups_ids = _get_groups_ids_for_names(groups_names_param.split(','))
except:
groups_ids = []
merge_requests = {}
for group_id in groups_ids:
projects_ids = (project['id'] for project in _get_projects([group_id]))
merge_requests[_groups_id_to_name(group_id)] = (
_get_opened_merge_requests(projects_ids))
return merge_requests
def _groups_id_to_name(target_group_id):
for group_name, group_id in groups_name_to_id.items():
if group_id == target_group_id:
return group_name
def _get_groups_ids_for_names(names):
groups_ids = set()
all_cached = True
for name in names:
group_id = groups_name_to_id.get(name)
if group_id:
groups_ids.add(str(group_id))
else:
all_cached = False
break
skip_groups = ""
if groups_ids:
skip_groups = "&skip_groups[]=" + '&skip_groups[]='.join(groups_ids)
if not all_cached:
for name in names:
path = GROUPS_PATH + "?search={}".format(name) + skip_groups
groups = _get(path)
for group in groups:
group_name = group.get('name')
group_id = str(group.get('id'))
for name in names:
if group_name == name:
groups_name_to_id[name] = group_id
groups_ids.add(group_id)
break
return groups_ids
def _get_projects(groups_ids):
projects = []
for group_id in groups_ids:
projects_for_group = _get(GROUP_PROJECTS.format(group_id))
projects += projects_for_group
return projects
def _get_opened_merge_requests(projects_ids):
return _get_open(projects_ids, PROJECT_OPENED_MERGE_REQUESTS)
def _get_opened_issues(projects_ids):
return _get_open(projects_ids, PROJECT_OPENED_ISSUES)
def _get_open(projects_ids, path):
things = []
for project_id in projects_ids:
things_for_project = _get(path.format(project_id))
things += things_for_project
return things
def _get(url):
token = request.args.get("token")
token = token or request.headers.get("Private-Token")
# The thing bellow is really bad programming
# At least it only allows a user to get information about the Merge
# Requests and Issues
gitlab_personal_token = None
if token == SECRET_ACCESS_KEY:
gitlab_personal_token = GITLAB_PERSONAL_TOKEN
headers = {
"Content-Type": "application/json",
"Private-Token": gitlab_personal_token
}
return requests.get(url, headers=headers).json()
if __name__ == "__main__":
if not SECRET_ACCESS_KEY or not GITLAB_PERSONAL_TOKEN:
msg = ("The Environment Variables SECRET_ACCESS_KEY and "
"GITLAB_PERSONAL_TOKEN are needed, define them before starting "
"the app.")
raise Exception(msg)
listen_ip, listen_port = "0.0.0.0", "8080"
if len(sys.argv) > 1:
if ':' in sys.argv[1]:
listen_ip, listen_port = sys.argv[1].strip().split(':')
else:
listen_port = sys.argv[1]
app.run(debug=True, use_reloader=True, host=listen_ip, port=listen_port)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment