Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Http-info now accepts environment variables to ignore more urls #680

Merged
merged 1 commit into from

2 participants

@Iristyle

No description provided.

@Iristyle Iristyle http-info can ignore specific users
With other notifications from scripts, and links to private GitHub
repos, this script can get pretty noisy.

Added HUBOT_HTTP_INFO_IGNORE_URLS to exclude urls by RegEx
Added HUBOT_HTTP_INFO_IGNORE_USERS to exclude users in a list

Control the noise by excluding users, or regex matches on notification
text or both
406d58b
@tombell tombell merged commit babe278 into github:master
@Iristyle Iristyle deleted the Iristyle:httpinfo-ignores branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 4, 2013
  1. @Iristyle

    http-info can ignore specific users

    Iristyle authored
    With other notifications from scripts, and links to private GitHub
    repos, this script can get pretty noisy.
    
    Added HUBOT_HTTP_INFO_IGNORE_URLS to exclude urls by RegEx
    Added HUBOT_HTTP_INFO_IGNORE_USERS to exclude users in a list
    
    Control the noise by excluding users, or regex matches on notification
    text or both
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 4 deletions.
  1. +24 −4 src/scripts/http-info.coffee
View
28 src/scripts/http-info.coffee
@@ -5,7 +5,10 @@
# "jsdom": "0.2.15"
#
# Configuration:
-# None
+#
+# Optional Configuration:
+# HUBOT_HTTP_INFO_IGNORE_URLS - RegEx used to exclude Urls
+# HUBOT_HTTP_INFO_IGNORE_USERS - Comma separated list of users to ignore
#
# Commands:
# http(s)://<site> - prints the title and meta description for sites linked.
@@ -13,14 +16,31 @@
# Authors:
# ajacksified
-jsdom = require('jsdom')
+jsdom = require 'jsdom'
+_ = require 'underscore'
module.exports = (robot) ->
+ ignoredusers = []
+ if process.env.HUBOT_HTTP_INFO_IGNORE_USERS?
+ ignoredusers = process.env.HUBOT_HTTP_INFO_IGNORE_USERS.split(',')
+
robot.hear /http(s?):\/\/(.*)/i, (msg) ->
url = msg.match[0]
- unless url.match(/\.(png|jpg|jpeg|gif|txt|zip|tar\.bz|js|css)/) # filter out some common files from trying
+ username = msg.message.user.name
+ if _.some(ignoredusers, (user) -> user == username)
+ console.log 'ignoring user due to blacklist:', username
+ return
+
+ # filter out some common files from trying
+ ignore = url.match(/\.(png|jpg|jpeg|gif|txt|zip|tar\.bz|js|css)/)
+
+ ignorePattern = process.env.HUBOT_HTTP_INFO_IGNORE_URLS
+ if !ignore && ignorePattern
+ ignore = url.match(ignorePattern)
+
+ unless ignore
jsdom.env(
html: msg.match[0]
scripts: [
@@ -32,7 +52,7 @@ module.exports = (robot) ->
title = $('title').text()
description = $('meta[name=description]').attr("content") || ""
description = "\n" + description if description
-
+
if title
msg.send "#{title}#{description}"
)
Something went wrong with that request. Please try again.