mirror of
https://github.com/lubuntu-team/lugito.git
synced 2025-05-01 21:11:28 +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
|
irc = cqg42zdcuqysff632kc6rnsu4m3hjg6c
|
||||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
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]
|
[connector.irc]
|
||||||
host = irc.freenode.net
|
host = irc.freenode.net
|
||||||
port = 6697
|
port = 6697
|
||||||
@ -41,14 +53,6 @@ supported_versions =
|
|||||||
Bionic
|
Bionic
|
||||||
Xenial
|
Xenial
|
||||||
Trusty
|
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
|
Features
|
||||||
|
20
README.rst
20
README.rst
@ -30,6 +30,18 @@ Temp - Example .lugitorc
|
|||||||
irc = cqg42zdcuqysff632kc6rnsu4m3hjg6c
|
irc = cqg42zdcuqysff632kc6rnsu4m3hjg6c
|
||||||
commithook = znkyfflbcia5gviqx5ybad7s6uyfywxi
|
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]
|
[connector.irc]
|
||||||
host = irc.freenode.net
|
host = irc.freenode.net
|
||||||
port = 6697
|
port = 6697
|
||||||
@ -47,14 +59,6 @@ Temp - Example .lugitorc
|
|||||||
Xenial
|
Xenial
|
||||||
Trusty
|
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
|
Features
|
||||||
|
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']\
|
lugito.config.CONFIG['connectors']\
|
||||||
['launchpad']['supported_versions']
|
['launchpad']['supported_versions']
|
||||||
self.package_names =\
|
self.package_names =\
|
||||||
lugito.config.CONFIG['connectors']\
|
lugito.config.CONFIG['phabricator']['package_names']
|
||||||
['launchpad']['package_names']
|
|
||||||
|
|
||||||
|
|
||||||
# Phabricator info
|
# Phabricator info
|
||||||
|
@ -17,7 +17,7 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
from lugito import Lugito
|
from lugito import Lugito
|
||||||
from lugito.connectors import irc, launchpad
|
from lugito.connectors import irc, launchpad, jenkins
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
GLOBAL_LOG_LEVEL = logging.DEBUG
|
GLOBAL_LOG_LEVEL = logging.DEBUG
|
||||||
@ -29,6 +29,7 @@ WEBSITE = lugito.host.replace('/api/', '')
|
|||||||
# Connectors
|
# Connectors
|
||||||
irc_con = irc()
|
irc_con = irc()
|
||||||
launchpad_con = launchpad()
|
launchpad_con = launchpad()
|
||||||
|
jenkins_con = jenkins()
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
logger = logging.getLogger('lugito.webhooks')
|
logger = logging.getLogger('lugito.webhooks')
|
||||||
@ -75,8 +76,6 @@ def commithook():
|
|||||||
return 'Ok'
|
return 'Ok'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/irc", methods=["POST"])
|
@app.route("/irc", methods=["POST"])
|
||||||
def _main():
|
def _main():
|
||||||
"""Main route"""
|
"""Main route"""
|
||||||
@ -166,6 +165,29 @@ def _main():
|
|||||||
return 'Ok'
|
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():
|
def run():
|
||||||
irc_con.connect()
|
irc_con.connect()
|
||||||
launchpad_con.connect()
|
launchpad_con.connect()
|
||||||
|
@ -48,6 +48,15 @@ def test_loading_config_hooks():
|
|||||||
'vglzi6t4gsumnilv27r27no7rs3vgs75')
|
'vglzi6t4gsumnilv27r27no7rs3vgs75')
|
||||||
assert(CONFIG['phabricator']['hooks']['commithook'] ==\
|
assert(CONFIG['phabricator']['hooks']['commithook'] ==\
|
||||||
'znkyfflbcia5gviqx5ybad7s6uyfywxi')
|
'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():
|
def test_loading_config_connectors():
|
||||||
@ -71,14 +80,6 @@ def test_loading_config_connectors():
|
|||||||
'staging': 'production',
|
'staging': 'production',
|
||||||
'version': 'devel',
|
'version': 'devel',
|
||||||
'supported_versions': ['Cosmic', 'Bionic', 'Xenial', 'Trusty'],
|
'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()
|
import pdb;pdb.set_trace()
|
||||||
|
|
||||||
|
@ -22,6 +22,14 @@ lugito.config.CONFIG = {
|
|||||||
'diffhook': 'vglzi6t4gsumnilv27r27no7rs3vgs75',
|
'diffhook': 'vglzi6t4gsumnilv27r27no7rs3vgs75',
|
||||||
'commithook': 'znkyfflbcia5gviqx5ybad7s6uyfywxi',
|
'commithook': 'znkyfflbcia5gviqx5ybad7s6uyfywxi',
|
||||||
},
|
},
|
||||||
|
'package_names': {
|
||||||
|
'rDEFAULTSETTINGS': 'lubuntu-default-settings',
|
||||||
|
'rART': 'lubuntu-artwork',
|
||||||
|
'rCALASETTINGS': 'calamares-settings-ubuntu',
|
||||||
|
'rQTERMINALPACKAGING': 'qterminal',
|
||||||
|
'rLXQTCONFIGPACKAGING': 'lxqt-config',
|
||||||
|
'rNMTRAYPACKAGING': 'nm-tray',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'connectors': {
|
'connectors': {
|
||||||
'irc': {
|
'irc': {
|
||||||
@ -36,14 +44,6 @@ lugito.config.CONFIG = {
|
|||||||
'staging': 'production',
|
'staging': 'production',
|
||||||
'version': 'devel',
|
'version': 'devel',
|
||||||
'supported_versions': ['Cosmic', 'Bionic', 'Xenial', 'Trusty'],
|
'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