Skip to content

add basic search functionality to the Backlog plugin #26

Open
wants to merge 1 commit into from

1 participant

@zwily
zwily commented Nov 13, 2011

Adds a search command to the bot that will return the last 10 lines matching
the provided string in the specified context.

This required sending the bouncer to the bot instead of the just the user,
since we needed to get more state.

Stuff to be done to make better:

  • Let users page through results
  • Let users ask for X lines of context around one of the results
  • Make searching more efficient (we normally want to search from the end of a backlog)
  • Colorize results

The first two items will require keeping some state around for searches
(things like last query, offsets of each result into the file, etc.)

@zwily zwily add basic search functionality to the Backlog plugin
Adds a search command to the bot that will return the last 10 lines matching
the provided string in the specified context.

This required sending the bouncer to the bot instead of the just the user,
since we needed to get more state.

Stuff to be done to make better:

 * Let users page through results
 * Let users ask for X lines of context around one of the results
 * Make searching more efficient (we normally want to search from the end of a
   backlog)
 * Colorize results

The first two items will require keeping some state around for searches
(things like last query, offsets of each result into the file, etc.)
45c2a3d
@zwily zwily commented on the diff Nov 13, 2011
lib/tkellem/plugins/backlog.rb
+ return
+ end
+
+ backlog = Backlog.get_instance(bouncer)
+
+ filename = backlog.stream_filename(ctx)
+ unless File.exists?(filename)
+ r "Can't find backlog for #{ctx}."
+ return
+ end
+
+ r "Searching #{ctx} for \"#{query}\""
+
+ # TODO: implement a smarter, reverse search, as this can be expensive on very long backlogs.
+ # TODO: keep some state after a search and let the user get context around one of the results.
+ result = %x{grep #{query.shellescape} #{filename} | tail -n 10}
@zwily
zwily added a note Nov 13, 2011

Oops - security hole here. filename is built from the user-specified ctx which is not sanitized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.