diff --git a/runbot_subject_skip/README.rst b/runbot_subject_skip/README.rst new file mode 100644 index 00000000..e08e1307 --- /dev/null +++ b/runbot_subject_skip/README.rst @@ -0,0 +1,74 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +=================== +runbot_subject_skip +=================== + +This module skip a build based on the commit message. +Inspired by Travis-CI: https://docs.travis-ci.com/user/customizing-the-build#Skipping-a-build + +Usage +===== + +To use this module, you need create a commit message with the following keywords: + - "[skip ci]" or "[ci skip]" uppercase or lowercase in anywhere + +The builds will be skipped. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/146/11.0 + + +Known issues / Roadmap +====================== + +* Just is used the first line of the commit message but in travis they are using all lines. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Moisés López (https://www.vauxoo.com) + +Do not contact contributors directly about support or help with technical issues. + +Funders +------- + +The development of this module has been financially supported by: + +* Vauxoo (https://www.vauxoo.com) + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/runbot_subject_skip/__init__.py b/runbot_subject_skip/__init__.py new file mode 100644 index 00000000..3275ac2a --- /dev/null +++ b/runbot_subject_skip/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/runbot_subject_skip/__manifest__.py b/runbot_subject_skip/__manifest__.py new file mode 100644 index 00000000..865753ab --- /dev/null +++ b/runbot_subject_skip/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright <2018> +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Runbot subject skip", + "summary": "Skip build if commit message has '[ci skip]'", + "version": "11.0.1.0.0", + "category": "runbot", + "website": "https://github.com/OCA/runbot-addons", + "author": "Vauxoo, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "runbot", + ], + "data": [ + ], + "application": False, + "installable": True, +} diff --git a/runbot_subject_skip/models/__init__.py b/runbot_subject_skip/models/__init__.py new file mode 100644 index 00000000..cd51417d --- /dev/null +++ b/runbot_subject_skip/models/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import runbot_build diff --git a/runbot_subject_skip/models/runbot_build.py b/runbot_subject_skip/models/runbot_build.py new file mode 100644 index 00000000..59242441 --- /dev/null +++ b/runbot_subject_skip/models/runbot_build.py @@ -0,0 +1,26 @@ +# Copyright <2018> +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import re + +from odoo import api, models + +SKIP_WORDS = ['[ci skip]', '[skip ci]'] +SKIP_WORDS_RE = re.compile("|".join(map(re.escape, SKIP_WORDS))) + + +class RunbotBuild(models.Model): + _inherit = "runbot.build" + + def subject_skip(self): + """Skip build if there is a commit message with one SKIP_WORDS""" + for build in self.filtered(lambda b: + SKIP_WORDS_RE.search(b.subject.lower())): + build._log('subject_skip', 'The commit message skipped this build') + build._skip() + + @api.model + def create(self, values): + build = super().create(values) + build.subject_skip() + return build diff --git a/runbot_subject_skip/tests/__init__.py b/runbot_subject_skip/tests/__init__.py new file mode 100644 index 00000000..a9e551f1 --- /dev/null +++ b/runbot_subject_skip/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_runbot_skip_build diff --git a/runbot_subject_skip/tests/test_runbot_skip_build.py b/runbot_subject_skip/tests/test_runbot_skip_build.py new file mode 100644 index 00000000..7927081d --- /dev/null +++ b/runbot_subject_skip/tests/test_runbot_skip_build.py @@ -0,0 +1,39 @@ +# Copyright <2018> +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import logging + +from odoo.tests.common import TransactionCase + +_logger = logging.getLogger(__name__) + + +class TestRunbotSkipBuild(TransactionCase): + + def test_skip_build(self): + """Test the [ci skip] feature""" + repo = self.env["runbot.repo"].create({ + "name": "https://github.com/ORG/REPO.git", + }) + branch = self.env["runbot.branch"].create({ + "name": "refs/heads/master", + "repo_id": repo.id, + }) + build = self.env["runbot.build"].create({ + "name": "HEAD", + "branch_id": branch.id, + "subject": "Test [ci skip] feature", + }) + self.assertEqual( + build.state, 'done', "State should be done") + self.assertEqual( + build.result, 'skipped', "Result should be skipped") + build = self.env["runbot.build"].create({ + "name": "HEAD", + "branch_id": branch.id, + "subject": "Test no ci skip feature", + }) + self.assertEqual( + build.state, 'pending', "State should be pending") + self.assertNotEqual( + build.result, 'skipped', "Result shouldn't be skipped")