Commit Graph

53 Commits

Author SHA1 Message Date
Zuul 3497425ff4 Merge "Add branch to all the remaining event messages" 2021-07-28 16:54:09 +00:00
Clark Boylan 6f78d6e52b Support normal auth in gerritbot
This is a partial revert of 57a669d35d
which added SASL auth support but in the process removed normal auth. In
order to support OFTC which doesn't currentl do SASL we add back in
normal auth support while keeping SASL for OFTC should they add the
functionality.

Change-Id: I191ced962e91226d196e6fae728484d8cd7233e2
2021-05-29 10:08:56 -07:00
Radosław Piliszek 75e2c2f03d Add branch to all the remaining event messages
Branch is always useful to know. ;-)

Change-Id: Icece8d06c771dbd55825655206f75810d9fa43e6
2021-04-28 18:39:09 +00:00
Jeremy Stanley 3cefaa8617 Don't reconnect on MessageTooLong exceptions
If a user pushes a commit with an overly-long subject (most often
forgetting to separate it from the rest of the commit message with a
blank line), the resulting IRC message will be longer than the
protocol allows. In these cases, irc.client.MessageTooLong is
raised. This is an unfortunately all-too-common occurrence, so catch
it specifically in order to not enter the reconnect phase
needlessly. Log the failure to send, so that it can still be found
if someone is trying to identify the reason a change was not
announced.

Change-Id: I3cfaa3ea3b3f8f2de20bfe425c345385eb7cbba6
2021-03-19 22:12:29 +00:00
Jeremy Stanley 03c21d8369 Explicitly clear joined channels when reconnecting
If we try to reconnect after an error sending a message to the IRC
server, clear the tracking of which channels are currently joined,
since none will be joined once reconnected. This fixes a
longstanding regression where the bot would appear to quit the
network and never return, when in actuality it just didn't know it
needed to rejoin channels once reconnected.

Change-Id: Ic865e307609285708c40e11a66b4b9643afc178e
2021-03-19 21:44:37 +00:00
Jeremy Stanley 225a6a3502 Revert "Skip notifications about WIP changes"
Needs more discussion.

This reverts commit 54e2f218d6.

Change-Id: I7fd6b8f78830cc87d14b67d957fa64cc0d453c0b
2021-01-19 19:26:45 +00:00
Zuul e3bcd8a4e9 Merge "Skip notifications about WIP changes" 2021-01-19 15:46:11 +00:00
Sorin Sbarnea 7d473e4d43 Use yaml.safe_load instead of load.
Fixes security issue and deprecation of simple use of yaml.load
without an explicit loader.

Change-Id: If47e3fd1cc09c7a1db1fad05a643aa3da04cf26c
2020-12-02 16:51:28 +00:00
Sorin Sbarnea 54e2f218d6 Skip notifications about WIP changes
WIP changes are likely to spam irc channels as they are not even
visible by default in dashboards. If we detect the WIP flag as present
and set to true, we just skip doing anything about that message.

Change-Id: Id4ee6c825e6d508c0c722d01ac8b1147b4025dbe
2020-12-02 15:32:09 +00:00
Jeremy Stanley 04a8d696f1 Iterate over a copy of the channel keys
In Python 2, dict.keys() created a list copy of a dictionary's keys,
but in Python 3 it's an iterable tied to the original dict instead.
Modifying the data dict while iterating over its keys under Python 3
therefore causes items to get removed out from under the loop before
they're reached. Switch to using an explicit list copy instead for
iteration, and similarly save the result as an explicit list rather
than carrying over the iterable.

Change-Id: Iac96cdf3bab47071f197832172b94481e7bf00d5
2020-08-12 16:50:33 +00:00
Clark Boylan 1da055f809 Add option to disable daemonization
We are double forking in the docker image and that seems to confuse
docker because the process it started has exited. Fix this by adding a
--no-daemon option to gerritbot then set that in the dockerfile. This
should run gerritbot without any additional forking.

Change-Id: I048115da5362a883360dcaf40860022ed5b63d47
2020-08-07 10:10:20 -07:00
Monty Taylor 29ff7b3bec Update for python3
We're gonna build an image in the next patch, so let's fix things
up to be python3 ready.

Change-Id: Ia0e1ecf75e6593a7e7be9dc962a1e2f3dc23fe27
2020-03-28 11:46:39 -05:00
Steve Baker e3879412b7 Fix event comment-added
This change fixes the comment-added message sending to filter by the
event type which gerrit is now sending (Verified and Code-Review)

Adding the following to project-config/gerritbot/channels.yaml will
restore the previous functionality of sending messages for Verified,
Code-Review +2 and -2:

  events:
    - comments-added
    - x-vrif-minus-2
    - x-vrif-plus-2
    - x-crvw-minus-2
    - x-crvw-plus-2

Additionally, specifying 'comments-added' will send a message for
*every* gerrit comment, so the only way to get messages for
x-vrif-plus-2 (for example) is to also receive a firehose of every
gerrit comment.

To make this more configurable, the event type x-all-comments has been
added, which is now required in combination with 'comments-added' to
send a message for every gerrit comment:

  events:
    - comments-added
    - x-all-comments

Change-Id: I9971e045c3416b300d1fd4683a2c145afef3d44f
2019-12-10 10:49:01 +13:00
Clark Boylan fefaae1109 Don't autojoin channels
Don't pass the channels list to super in the irc bot class init method
because this appears to cause autojoining to happen which breaks because
we have too many channels. Instead let the event driven processing join
and part channels as needed to make the least recently used channel
rotation with channel limit work.

Change-Id: I447e75e84526d08fb9ec88eaae9a90f950dc5349
2018-10-15 15:38:16 -07:00
Jeremy Stanley 57a669d35d Identify with SASL
Identify through SASL using the convenient ib3 mixins, and
get rid of a bunch of special-case code in the process.

This helps when dealing with channels set to require identified
users, as otherwise channel joins will race NickServ's processing of
the identify message and some channels will end up not serviced by
the bot (an alternative would be to delay joining channels until the
identify success is confirmed, but the implementation for that looks
like it would be at least as complex).

Change-Id: I1a01eed8102b59818df247a93fbe4bf50148e76a
Co-Authored-By: Thierry Carrez <thierry@openstack.org>
Depends-On: https://review.openstack.org/608313
2018-10-05 17:13:59 +00:00
Zuul f32d742eff Merge "Add _get_username method to discover username" 2018-02-21 17:25:20 +00:00
Eric Fried 981dfa50fa Support regexes in channel config yaml
With this change, the channel config yaml file can now be configured to
support regular expressions.

Any value in any section may be prefixed with `^` to denote that it is
to be treated as a regular expression [1].  Start and end ^anchors$ are
implicit (so add `.*` if needed).

For example, given the following paragraph in the channel config yaml:

openstack-foo:
  events:
    - patchset-created
    - change-merged
  projects:
    - openstack/foo
    - ^openstack/foo-.*
    - openstack/oslo.foo
  branches:
    - master
    - ^stable/(newton|ocata|pike)

...messages will be posted to #openstack-foo for events coming in from
project openstack/foo, openstack/foo-one, openstack/foo-bar, etc.; on
branches master, stable/newton, stable/ocata, or stable/pike.

Behavior is unchanged for values not prefixed with `^`.

[1] This paradigm cribbed from gerrit's search functionality:
https://review.openstack.org/Documentation/user-search.html#path

Change-Id: I97cb8faa72600bd1bd9792bb6bb59a3b652ec389
2018-02-17 11:35:39 -08:00
Eric Fried fc4041f6a3 Test Gerrit message filtering
Enhance the tests introduced in [1] to exercise the filtering logic in
the Gerrit class.

[1] https://review.openstack.org/#/c/545128/

Change-Id: Ib4ecd9e7ee233378f25d585f016ba1448b9e8797
2018-02-17 11:35:31 -08:00
John L. Villalovos 01e1a0f979 Add more unit tests including testing of Gerrit() class
* Add some additional unit tests, including the initial framework to
    be able to test the Gerrit() class.

  * Improve the readability of the code by using more descriptive
    variable names.

  * Migrate to using '.stestr.conf' instead of '.testr.conf'. This
    removes warning message that was being displayed.

Change-Id: I596c4ccb9fe37d996de26089eefd8481a12ff13b
2018-02-17 11:28:38 -08:00
John L. Villalovos 4658934d22 Add unit test framework and one unit test
Add an initial unit test framework and one unit test. This way we can
ask people to add unit tests when they contribute code.

Change-Id: If52976e1992945a8e38af3cbad5b5f4389922d4c
2018-02-05 12:59:39 -08:00
Tristan Cacqueray 2240fc3450 Add _get_username method to discover username
This change mitigate this exception:
  File "gerritbot/bot.py", line 154, in change_created
    data['patchSet']['uploader']['name'],
KeyError: 'name'

Change-Id: Ia1f394d6ff0e158df16461cf3150761f6ec12f29
2017-03-15 02:09:49 +00:00
John L. Villalovos 033a83b870 For patch submitted/merged, announce the branch
When announcing that a patch has been submitted or merged, also announce
the branch that the patch is against.

Change-Id: I5b325951bdc1b0fca37d8579a14747a4da3b558e
2017-01-09 21:50:20 -08:00
James E. Blair 91d908b807 Treat channels as an LRU list
Freenode has a limit of 120 channels joined by a single connection.
Since some of the channels Gerritbot reports to are less active
than others, have it only join channels when it needs to send a
message.  If it has joined the max number of channels, part from
the least recently used channel to make room to join a new one.

Change-Id: Ifafeed77e640bc7b5910251c619358a8a2bd78a6
2016-11-02 12:03:42 -07:00
Matthew Treinish 7c6e57983d
Add gerrit stream over MQTT support to gerritbot
With the start of the germqtt project and it being deployed on
firehose.openstack.org services listening to gerrit no longer need
to connect via ssh to get the event stream. This commit adds support
for using an mqtt event stream as the input into gerritbot.

Change-Id: I4130edac746ab7ae979cad5e3ccad3be0321c909
2016-08-11 17:32:07 -04:00
Joshua Hesketh d48b1bc417 Fix reconnection method
The reconnect method is on the connection object, not the bot or
client objects.

See http://paste.openstack.org/show/481770/

Change-Id: I14856c0c451e51973e9b062cb9b4f35362cb3766
2015-12-14 18:17:49 +11:00
Monty Taylor f907ae7054 Add a log entry to the debug log on config error
Recently a config problem broke gerritbot's ability to start, but what's
worse, there was no logging about why. Log the exception when this
happens.

Change-Id: If7832cbe5cbf5f506d5dfbb849f05f2e7670a2df
2015-09-20 19:33:09 -04:00
Monty Taylor 506aea9010 Replace six.iteritems with iter()
We don't need six for this.

Change-Id: I19673bf47ef74b5e67c4197d31600c73c025ab4c
2015-02-27 22:14:23 -05:00
Monty Taylor 4851742244 Update to modern pbr
d2to1 hasn't been a thing in a VERY long time. We have to update hacking
as well beause the hacking this depends on also depends on a very old
pbr.

Change-Id: I1bf97a5fe1c1ae10f951510c2b95d43b4e9b8b19
2015-02-27 22:14:00 -05:00
Jenkins 9258586a86 Merge "Adding a configuration option for gerritbots PID file path." 2014-08-11 14:12:15 +00:00
Christian Berendt 1143bda887 replace dict.iteritems() with six.iteritems(dict)
According to https://wiki.openstack.org/wiki/Python3 dict.iteritems()
should be replaced with six.iteritems(dict).

Added six >= 1.6.0 as new requirement.

Change-Id: Ie8a3eacc00dd9248ee80956b3e72f0e80655b1f1
2014-07-10 19:16:48 +00:00
Tim Kelsey ed4e3d0b5c Adding a configuration option for gerritbots PID file path.
Closes-Bug: 1325583

Change-Id: I7200ae87963181e6ff8583ba665a141d7392605a
2014-06-02 14:48:34 +00:00
Matthew Montgomery 6208bd982f Force SSL Configuration Parameter
Adds a new optional config parameter "force_ssl" that applies the SSL wrapper
regardless of the specified port. The previous logic only allowed for SSL
on port 6697. This change is intended to be backwards compatible with
existing configs.

Added *.egg  ignore patterns to .gitignore

Change-Id: I6fe6d9ad2d8461d759a63123af79f229b8f8b6f2
2014-05-23 08:39:55 -05:00
Ricardo Carrillo Cruz 575b062cbd Add support for notification of releases on IRC
Closes-Bug: #1227985

Change-Id: I9b80b465d9d6b0e2793286cc8229b82b4389a08d
2014-03-25 23:23:01 +00:00
James E. Blair cf56901920 Support SSL
Change-Id: I0c98febc3bdf15b0f92b749fd3b1afd3d0e1edbb
2014-03-10 08:29:58 -07:00
James E. Blair 4d99747b70 Don't crash on UTF8 errors
https://bitbucket.org/jaraco/irc/issue/34/irc-client-should-not-crash-on-failed

Change-Id: Ifb56ce80a170baf8c36a5fa1a2d0c88ea13885a5
2014-03-07 10:06:44 -08:00
Matthew Treinish d2c5ba1cb0 Actually use super calls for init functions in bot.py
This commit fixes the gerritbot __init__ methods to use a proper super
call instead of directly calling the parent class's __init__.

Change-Id: I72894a978b7bcef782236f5d43f601697a89c50d
2014-01-13 19:53:48 +00:00
James E. Blair bcb72904de Reconnect to IRC on send error
If any error is encountered while sending to IRC, try to reconnect.

This is an attempt to deal with this exception:

2013-10-07 23:00:00,937 ERROR gerritbot: Exception encountered in event loop
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gerritbot/bot.py", line 225, in run
    self._read(event)
  File "/usr/local/lib/python2.7/dist-packages/gerritbot/bot.py", line 216, in _read
    self.change_merged(channel, data)
  File "/usr/local/lib/python2.7/dist-packages/gerritbot/bot.py", line 194, in change_merged
    self.ircbot.send(channel, msg)
  File "/usr/local/lib/python2.7/dist-packages/gerritbot/bot.py", line 98, in send
    self.connection.privmsg(channel, msg)
  File "/usr/local/lib/python2.7/dist-packages/irc/client.py", line 933, in privmsg
    self.send_raw("PRIVMSG %s :%s" % (target, text))
  File "/usr/local/lib/python2.7/dist-packages/irc/client.py", line 960, in send_raw
    sender = self.ssl.write if self.ssl else self.socket.send
AttributeError: 'NoneType' object has no attribute 'send'

Change-Id: I8c845626260ec7b9ee7f9e409adba4796dd367ee
2013-10-07 16:07:22 -07:00
Joe Gordon 14679c6f44 Make proposed and merged messages more terse
The previous messages were wordy, when gerrit is very active, all these
wordy messages can clutter up a room.   This makes the messages more
terse.

Change-Id: I7c941a871e3f1a09dd47c72aa32f93effc04250a
2013-08-06 18:39:32 -07:00
Jenkins 07f4eddf7c Merge "Use flake8 instead pep8." 2013-06-20 16:50:26 +00:00
Jenkins 12a367b778 Merge "Migrate to pbr." 2013-06-20 16:49:45 +00:00
Jeremy Stanley a62ff34717 Pause between joins to avoid flooding.
* gerritbot/bot.py(GerritBot.on_welcome): Add a 0.5-second pause
between channel join commands to avoid being kicked for flooding.

Change-Id: I8edad4b389683e62b58f5b6e81e5f4cb1e0dad97
2013-06-06 19:23:57 +00:00
Monty Taylor 95ecb0fb29 Use flake8 instead pep8.
Change-Id: I9dd305cf06157094ea49b2f30cb8f1d28d170b8c
2013-06-02 11:20:24 -04:00
Monty Taylor 6c07bb6bc6 Migrate to pbr.
Change-Id: Id9c9837b040c634103bcc30d590e995c3b6c309d
2013-06-02 10:37:00 -04:00
Erik Dalén 4959423fd1 Add support for server passwords
Change-Id: I0e623df8848b214ef715b2e265e97b71b16d666a
2012-11-05 12:38:42 -05:00
Clark Boylan 103f0987d0 Fix Gerritbot leaking GerritLib Threads.
Gerritbot previously leaked GerritLib threads because it did not check
if the preexisting thread was dead before starting new threads. Fix
that by checking the thread's is_alive() method.

Change-Id: I7282debf5caeb73cbc46b240f10c62b75b683776
2012-08-24 13:46:06 -07:00
Clark Boylan 92b7468921 Handle KeyErrors when event data is not present.
The bot previously assumed that all event stream JSON blobs would always
have the data that the bot is interested in. Handle KeyError exceptions
when that data is missing.

Change-Id: I6ad034c5197c6778c39c334e3d9246c3b1356a81
2012-08-24 13:28:46 -07:00
Clark Boylan 383860d352 Log useful information.
Logging was configured, but only gerritlib log info was captured. Add
logging to the things that the IRC bot is doing.

Change-Id: Id38e49d95c2903ae28cfb7f2dc88d4fc201d8927
2012-08-24 11:51:06 -07:00
Clark Boylan ece8763a70 Add Apache 2 license file.
Add the full text of the Apache 2 license and add the license header
to gerritbot/bot.py.

Change-Id: Ib3308d6400ba4ac7540331179e1266aa76258566
2012-08-02 16:37:04 -07:00
Clark Boylan d15abaa25f Use gerritlib for event-stream consumption.
Gerritlib is now available for Gerrit event stream consumption. Use
it. This should fix the bug where events are missed due to the
connection dying and the resulting wait for five seconds.

Change-Id: I63e7c3064a42379c985f1a0a723d08c15a1be003
2012-07-31 11:45:53 -07:00
David Ostrovsky b2be72e69d Add setup.py to project.
Add a setup.py for the gerritbot project. This incorporates
openstack.common.setup/version as well for versioning. This change
also adds a tox.ini file and its lists of dependencies to gerritbot:
pyyaml, python-daemon and python-irclib.

Change-Id: Id9204a1ad452c8aa3c5ec5b697db4dd835e46405
2012-07-30 17:08:32 -07:00