mirror of
https://github.com/lubuntu-team/lugito.git
synced 2025-03-10 06:31:09 +00:00
Add Jenkins support.
This commit is contained in:
parent
ac7b470dbc
commit
5f24aa7375
20
README.md
20
README.md
@ -25,6 +25,18 @@ token = api-nojs2ip33hmp4zn6u6cf72w7d6yh
|
||||
irc = cqg42zdcuqysff632kc6rnsu4m3hjg6c
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
|
||||
[phabricator.package_names]
|
||||
rDEFAULTSETTINGS = lubuntu-default-settings
|
||||
rART = lubuntu-artwork
|
||||
rCALASETTINGS = calamares-settings-ubuntu
|
||||
rQTERMINALPACKAGING = qterminal
|
||||
rLXQTCONFIGPACKAGING = lxqt-config
|
||||
rNMTRAYPACKAGING = nm-tray
|
||||
|
||||
[jenkins]
|
||||
site = https://ci.lubuntu.me
|
||||
template_url = ssh://git@phab.lubuntu.me:2222/source/PACKAGE.git
|
||||
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
@ -41,14 +53,6 @@ supported_versions =
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
||||
|
||||
[connector.launchpad.package_names]
|
||||
rDEFAULTSETTINGS = lubuntu-default-settings
|
||||
rART = lubuntu-artwork
|
||||
rCALASETTINGS = calamares-settings-ubuntu
|
||||
rQTERMINALPACKAGING = qterminal
|
||||
rLXQTCONFIGPACKAGING = lxqt-config
|
||||
rNMTRAYPACKAGING = nm-tray
|
||||
```
|
||||
|
||||
Features
|
||||
|
60
README.rst
60
README.rst
@ -22,38 +22,42 @@ Temp - Example .lugitorc
|
||||
|
||||
.. code::
|
||||
|
||||
[phabricator]
|
||||
host = http://127.0.0.1:9091/api/
|
||||
token = api-nojs2ip33hmp4zn6u6cf72w7d6yh
|
||||
[phabricator]
|
||||
host = http://127.0.0.1:9091/api/
|
||||
token = api-nojs2ip33hmp4zn6u6cf72w7d6yh
|
||||
|
||||
[phabricator.hooks]
|
||||
irc = cqg42zdcuqysff632kc6rnsu4m3hjg6c
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
[phabricator.hooks]
|
||||
irc = cqg42zdcuqysff632kc6rnsu4m3hjg6c
|
||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
||||
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
username = someusername
|
||||
password = somepassword
|
||||
channel = #somechannel
|
||||
[phabricator.package_names]
|
||||
rDEFAULTSETTINGS = lubuntu-default-settings
|
||||
rART = lubuntu-artwork
|
||||
rCALASETTINGS = calamares-settings-ubuntu
|
||||
rQTERMINALPACKAGING = qterminal
|
||||
rLXQTCONFIGPACKAGING = lxqt-config
|
||||
rNMTRAYPACKAGING = nm-tray
|
||||
|
||||
[connector.launchpad]
|
||||
application = lugito
|
||||
staging = production
|
||||
version = devel
|
||||
supported_versions =
|
||||
Cosmic
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
||||
[jenkins]
|
||||
site = https://ci.lubuntu.me
|
||||
template_url = ssh://git@phab.lubuntu.me:2222/source/PACKAGE.git
|
||||
|
||||
[connector.launchpad.package_names]
|
||||
rDEFAULTSETTINGS = lubuntu-default-settings
|
||||
rART = lubuntu-artwork
|
||||
rCALASETTINGS = calamares-settings-ubuntu
|
||||
rQTERMINALPACKAGING = qterminal
|
||||
rLXQTCONFIGPACKAGING = lxqt-config
|
||||
rNMTRAYPACKAGING = nm-tray
|
||||
[connector.irc]
|
||||
host = irc.freenode.net
|
||||
port = 6697
|
||||
username = someusername
|
||||
password = somepassword
|
||||
channel = #somechannel
|
||||
|
||||
[connector.launchpad]
|
||||
application = lugito
|
||||
staging = production
|
||||
version = devel
|
||||
supported_versions =
|
||||
Cosmic
|
||||
Bionic
|
||||
Xenial
|
||||
Trusty
|
||||
|
||||
|
||||
|
||||
|
91
lugito/connectors/jenkins.py
Normal file
91
lugito/connectors/jenkins.py
Normal file
@ -0,0 +1,91 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# S.D.G
|
||||
"""
|
||||
:mod:`lugito.connectors.jenkins`
|
||||
======================================
|
||||
|
||||
Define a jenkins connector class
|
||||
|
||||
.. currentmodule:: lugito.connectors.jenkins
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import re
|
||||
import logging
|
||||
import phabricator
|
||||
import lugito
|
||||
import requests
|
||||
from string import Template
|
||||
|
||||
|
||||
class launchpad(object):
|
||||
|
||||
def __init__(self, log_level=logging.DEBUG):
|
||||
|
||||
# Launchpad info
|
||||
# Read the configuration out of the .lugitorc file
|
||||
self.package_names =\
|
||||
lugito.config.CONFIG['phabricator']['package_names']
|
||||
|
||||
# Phabricator info
|
||||
self.phab = phabricator.Phabricator(
|
||||
host=lugito.config.CONFIG['phabricator']['host'],
|
||||
token=lugito.config.CONFIG['phabricator']['token'],
|
||||
)
|
||||
|
||||
# Jenkins info
|
||||
self.jenkins_site = lugito.config.CONFIG['jenkins']['site']
|
||||
self.jenkins_trigger_url = lugito.config.CONFIG['jenkins']\
|
||||
['template_url']
|
||||
|
||||
self.phab_host = lugito.config.CONFIG['phabricator']['host'].replace(
|
||||
'api/', '')
|
||||
|
||||
self.logger = logging.getLogger('lugito.connector.jenkins')
|
||||
|
||||
# Add log level
|
||||
ch = logging.StreamHandler()
|
||||
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
ch.setFormatter(formatter)
|
||||
|
||||
self.logger.addHandler(ch)
|
||||
self.logger.setLevel(log_level)
|
||||
|
||||
|
||||
def get_package_name(self, name):
|
||||
"""Need to check"""
|
||||
|
||||
if name in self.package_names:
|
||||
return self.package_names[name]
|
||||
|
||||
self.logger.debug('{} is an unsupported repository'.format(
|
||||
name))
|
||||
|
||||
|
||||
def send(self, *args, **kwargs):
|
||||
"""Send the commit message"""
|
||||
|
||||
if len(args) == 1:
|
||||
package_name = args
|
||||
elif len(kwargs) == 1:
|
||||
package_name = kwargs['package_name']
|
||||
|
||||
# Get the package name we'll be triggering; this assumes the repo
|
||||
# name always matches the package name
|
||||
package_name = self.get_package_name(package_name)
|
||||
|
||||
if package_name:
|
||||
package_url = self.jenkins_trigger_url.replace(
|
||||
"PACKAGE", package_name)
|
||||
r = requests.post("{}/git/notifyCommit?url={}".format(
|
||||
self.jenkins_site, package_url), data="")
|
||||
|
||||
self.logger.debug("Sent to Jenkins: {} {}".format(
|
||||
r.status_code, r.reason))
|
||||
|
||||
|
||||
def listen(self):
|
||||
pass
|
@ -44,8 +44,7 @@ class launchpad(object):
|
||||
lugito.config.CONFIG['connectors']\
|
||||
['launchpad']['supported_versions']
|
||||
self.package_names =\
|
||||
lugito.config.CONFIG['connectors']\
|
||||
['launchpad']['package_names']
|
||||
lugito.config.CONFIG['phabricator']['package_names']
|
||||
|
||||
|
||||
# Phabricator info
|
||||
|
@ -17,7 +17,7 @@ import logging
|
||||
import threading
|
||||
from flask import Flask, request
|
||||
from lugito import Lugito
|
||||
from lugito.connectors import irc, launchpad
|
||||
from lugito.connectors import irc, launchpad, jenkins
|
||||
|
||||
# Constants
|
||||
GLOBAL_LOG_LEVEL = logging.DEBUG
|
||||
@ -29,6 +29,7 @@ WEBSITE = lugito.host.replace('/api/', '')
|
||||
# Connectors
|
||||
irc_con = irc()
|
||||
launchpad_con = launchpad()
|
||||
jenkins_con = jenkins()
|
||||
|
||||
# Logging
|
||||
logger = logging.getLogger('lugito.webhooks')
|
||||
@ -75,8 +76,6 @@ def commithook():
|
||||
return 'Ok'
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route("/irc", methods=["POST"])
|
||||
def _main():
|
||||
"""Main route"""
|
||||
@ -166,6 +165,29 @@ def _main():
|
||||
return 'Ok'
|
||||
|
||||
|
||||
@app.route("/jenkins", methods=["POST"])
|
||||
def jenkinstrigger():
|
||||
"""Jenkins trigger"""
|
||||
|
||||
if lugito.validate_request('jenkins', request):
|
||||
|
||||
author = lugito.get_author_fullname()
|
||||
|
||||
# Without the author we can't continue
|
||||
if author is None:
|
||||
return 'Ok'
|
||||
|
||||
object_type = lugito.request_data["object"]["type"]
|
||||
|
||||
if object_type == "CMIT":
|
||||
logger.debug("Object is a commit.")
|
||||
|
||||
jenkins_con.send(pkg_name)
|
||||
|
||||
|
||||
return 'Ok'
|
||||
|
||||
|
||||
def run():
|
||||
irc_con.connect()
|
||||
launchpad_con.connect()
|
||||
|
@ -48,6 +48,15 @@ def test_loading_config_hooks():
|
||||
'vglzi6t4gsumnilv27r27no7rs3vgs75')
|
||||
assert(CONFIG['phabricator']['hooks']['commithook'] ==\
|
||||
'znkyfflbcia5gviqx5ybad7s6uyfywxi')
|
||||
assert(CONFIG['phabricator']['package_names'] ==\
|
||||
{
|
||||
'rDEFAULTSETTINGS': 'lubuntu-default-settings',
|
||||
'rART': 'lubuntu-artwork',
|
||||
'rCALASETTINGS': 'calamares-settings-ubuntu',
|
||||
'rQTERMINALPACKAGING': 'qterminal',
|
||||
'rLXQTCONFIGPACKAGING': 'lxqt-config',
|
||||
'rNMTRAYPACKAGING': 'nm-tray',
|
||||
})
|
||||
|
||||
|
||||
def test_loading_config_connectors():
|
||||
@ -71,14 +80,6 @@ def test_loading_config_connectors():
|
||||
'staging': 'production',
|
||||
'version': 'devel',
|
||||
'supported_versions': ['Cosmic', 'Bionic', 'Xenial', 'Trusty'],
|
||||
'package_names': {
|
||||
'rDEFAULTSETTINGS': 'lubuntu-default-settings',
|
||||
'rART': 'lubuntu-artwork',
|
||||
'rCALASETTINGS': 'calamares-settings-ubuntu',
|
||||
'rQTERMINALPACKAGING': 'qterminal',
|
||||
'rLXQTCONFIGPACKAGING': 'lxqt-config',
|
||||
'rNMTRAYPACKAGING': 'nm-tray',
|
||||
},
|
||||
}):
|
||||
import pdb;pdb.set_trace()
|
||||
|
||||
|
@ -22,6 +22,14 @@ lugito.config.CONFIG = {
|
||||
'diffhook': 'vglzi6t4gsumnilv27r27no7rs3vgs75',
|
||||
'commithook': 'znkyfflbcia5gviqx5ybad7s6uyfywxi',
|
||||
},
|
||||
'package_names': {
|
||||
'rDEFAULTSETTINGS': 'lubuntu-default-settings',
|
||||
'rART': 'lubuntu-artwork',
|
||||
'rCALASETTINGS': 'calamares-settings-ubuntu',
|
||||
'rQTERMINALPACKAGING': 'qterminal',
|
||||
'rLXQTCONFIGPACKAGING': 'lxqt-config',
|
||||
'rNMTRAYPACKAGING': 'nm-tray',
|
||||
},
|
||||
},
|
||||
'connectors': {
|
||||
'irc': {
|
||||
@ -36,14 +44,6 @@ lugito.config.CONFIG = {
|
||||
'staging': 'production',
|
||||
'version': 'devel',
|
||||
'supported_versions': ['Cosmic', 'Bionic', 'Xenial', 'Trusty'],
|
||||
'package_names': {
|
||||
'rDEFAULTSETTINGS': 'lubuntu-default-settings',
|
||||
'rART': 'lubuntu-artwork',
|
||||
'rCALASETTINGS': 'calamares-settings-ubuntu',
|
||||
'rQTERMINALPACKAGING': 'qterminal',
|
||||
'rLXQTCONFIGPACKAGING': 'lxqt-config',
|
||||
'rNMTRAYPACKAGING': 'nm-tray',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user