MarkTraceur has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/98141


Change subject: Move config into a default file and WMF files
......................................................................

Move config into a default file and WMF files

Channel list is still editable here, but is in a separate file and not
used by default. Config can now be stored in config.yaml safely, without
worrying about committing private data.

Change-Id: Iae95eaee59752d7026d53cbfce27c3527cff4e4d
---
A .gitignore
R channels.wmf.yaml
A channels.yaml.sample
A config.default.yaml
M config.yaml.sample
M src/relay.js
6 files changed, 47 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/grrrit 
refs/changes/41/98141/1

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5b6b072
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+config.yaml
diff --git a/config.yaml b/channels.wmf.yaml
similarity index 96%
rename from config.yaml
rename to channels.wmf.yaml
index 87a4f8f..d488235 100644
--- a/config.yaml
+++ b/channels.wmf.yaml
@@ -1,10 +1,4 @@
-nick: grrrit-wm
-server: irc.freenode.net
-userName: lolrrit
-realName: GRRRit the Terrible
 default-channel: "#wikimedia-dev"
-blacklist:
-    L10n-bot
 channels:
     "#mediawiki-i18n": [
         "translatewiki.*",
diff --git a/channels.yaml.sample b/channels.yaml.sample
new file mode 100644
index 0000000..a7b9427
--- /dev/null
+++ b/channels.yaml.sample
@@ -0,0 +1,4 @@
+channels:
+    "#wikimedia-labs": [
+        "labs/.*"
+        ]
diff --git a/config.default.yaml b/config.default.yaml
new file mode 100644
index 0000000..ce8abfd
--- /dev/null
+++ b/config.default.yaml
@@ -0,0 +1,3 @@
+nick: grrrit
+server: chat.freenode.net
+realName: See https://www.mediawiki.org/wiki/Grrrit-wm
diff --git a/config.yaml.sample b/config.yaml.sample
index 6f601be..a752982 100644
--- a/config.yaml.sample
+++ b/config.yaml.sample
@@ -1,12 +1,8 @@
-nick: grrrit-wm
+nick: creative-bot-name
 server: irc.freenode.net
-userName: lolrrit
-password: <secret>
-realName: GRRRit the Terrible
-default-channel: "#wikimedia-dev"
+userName: uniqueusername
+password: hunter2
+realName: See http://example.org/irc-bot-docs
 blacklist:
     L10n-bot
-channels:
-    "#wikimedia-labs": [
-        "labs/.*"
-           ]
+channels-file: ../channels.example.yaml
diff --git a/src/relay.js b/src/relay.js
index b0288e9..8b05a48 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -1,19 +1,39 @@
-var _ = require('underscore'),
+var config, channelConfig,
+    _ = require('underscore'),
     irc = require('irc'),
     redis = require('redis'),
     swig = require('swig'),
     processors = require('./preprocess.js'),
     yaml = require('js-yaml'),
     logging = require('winston'),
-    config = require('../config.yaml'),
-    conns = require('../connections.yaml'),
-    // Sane? defaults
-    config_defaults = {
-        nick: 'grrrit',
-        server: 'chat.freenode.net'
-    };
+    defaultConfig = require('../config.default.yaml'),
+    conns = require('../connections.yaml');
 
-_.defaults(config, config_defaults);
+try {
+    config = require( 'config.yaml' );
+} catch ( e ) {
+    config = {};
+}
+
+_.defaults(config, defaultConfig);
+
+if ( config && config['channels-file'] ) {
+    try {
+        channelConfig = require( config['channels-file'] );
+    } catch ( e ) {
+        console.log( 'Configured channels file not found, defaulting to none' 
);
+    }
+}
+
+if ( !channelConfig || !channelConfig.channels || 
channelConfig.channels.length === 0 ) {
+    console.log( 'WARNING: No channels configured, bot will be pretty useless' 
);
+    channelConfig = {
+        'default-channel': '#wikimedia-dev',
+        channels: []
+    };
+} else if ( !channelConfig['default-channel'] ) {
+    channelConfig['default-channel'] = '#wikimedia-dev';
+}
 
 function errorLog(message) {
     logging.error(message);
@@ -31,17 +51,17 @@
 });
 logging.remove(logging.transports.Console);
 
-var allChannels = _.keys(config.channels);
+var allChannels = _.keys(channelConfig.channels);
 
-if(allChannels.indexOf(config['default-channel']) === -1) {
-    allChannels.push(config['default-channel']);
+if(allChannels.indexOf(channelConfig['default-channel']) === -1) {
+    allChannels.push(channelConfig['default-channel']);
 }
 
 logging.info("joining channels", allChannels);
 
 function channelsForRepo(repo) {
     var channels = [];
-    _.each(config.channels, function(repos, channel) {
+    _.each(channelConfig.channels, function(repos, channel) {
         _.each(repos, function(repo_candidate) {
             if((new RegExp(repo_candidate)).test(repo)) {
                 channels.push(channel);
@@ -49,7 +69,7 @@
         });
     });
     if(!channels.length) {
-        channels = [config['default-channel']];
+        channels = [channelConfig['default-channel']];
     }
     return channels;
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/98141
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae95eaee59752d7026d53cbfce27c3527cff4e4d
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/grrrit
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to