lib/janky/hubot.rb in janky-0.9.0 vs lib/janky/hubot.rb in janky-0.9.9

- old
+ new

@@ -2,22 +2,22 @@ # Web API taylored for Hubot's needs. Supports setting up and disabling # repositories, querying the status of branch or a repository and triggering # builds. # # The client side implementation is at - # <https://github.com/github/hubot/blob/master/scripts/ci.js> + # <https://github.com/github/hubot-scripts/blob/master/src/scripts/janky.coffee> class Hubot < Sinatra::Base register Helpers # Setup a new repository. post "/setup" do nwo = params["nwo"] name = params["name"] repo = Repository.setup(nwo, name) if repo - url = "#{settings.base_url}/#{repo.name}" + url = "#{settings.base_url}#{repo.name}" [201, "Setup #{repo.name} at #{repo.uri} | #{url}"] else [400, "Couldn't access #{nwo}. Check the permissions."] end end @@ -29,16 +29,17 @@ [200, "#{repo.name} is now #{status}"] end # Build a repository's branch. - post "/:repo_name/:branch" do |repo_name, branch_name| + post %r{\/([-_\.0-9a-zA-Z]+)\/([-_\.a-zA-z0-9\/]+)} do |repo_name, branch_name| repo = find_repo(repo_name) branch = repo.branch_for(branch_name) build = branch.current_build - room_id = params["room_id"] && Integer(params["room_id"]) + room_id = (params["room_id"] && Integer(params["room_id"]) rescue nil) + if build build.rerun(room_id) [201, "Going ham on #{build.repo_name}/#{build.branch_name}"] else @@ -46,30 +47,30 @@ end end # Get a list of available rooms. get "/rooms" do - Yajl.dump(Campfire.room_names) + Yajl.dump(ChatService.room_names) end # Update a repository's notification room. put "/:repo_name" do |repo_name| repo = find_repo(repo_name) room = params["room"] - if room_id = Campfire.room_id(room) + if room_id = ChatService.room_id(room) repo.update_attributes!(:room_id => room_id) [200, "Room for #{repo.name} updated to #{room}"] else [403, "Unknown room: #{room.inspect}"] end end # Get the status of all projects. get "/" do content_type "text/plain" - repos = Repository.all.map do |repo| + repos = Repository.all(:include => [:branches, :commits, :builds]).map do |repo| master = repo.branch_for("master") "%-17s %-13s %-10s %40s" % [ repo.name, master.status, @@ -79,11 +80,11 @@ end repos.join("\n") end # Get the status of a repository's branch. - get "/:repo_name/:branch_name" do |repo_name, branch_name| + get %r{\/([-_\.0-9a-zA-Z]+)\/([-_\.a-zA-z0-9\/]+)} do |repo_name, branch_name| limit = params["limit"] repo = find_repo(repo_name) branch = repo.branch_for(branch_name) builds = branch.completed_builds.limit(limit).map do |build| @@ -103,15 +104,15 @@ # Learn everything you need to know about Janky. get "/help" do content_type "text/plain" <<-EOS -hubot ci build janky -hubot ci build janky/fix-everything -hubot ci setup github/janky [name] -hubot ci toggle janky -hubot ci rooms -hubot ci set room janky The Danger Room +ci build janky +ci build janky/fix-everything +ci setup github/janky [name] +ci toggle janky +ci rooms +ci set room janky development EOS end end end