Permalink
Browse files

Simplified the TargetProcess hook, should play nicely with the latest…

… versions of TP now
  • Loading branch information...
1 parent cd6e35e commit 1f44abf6b73f3296b267c341c3b063798c379b94 @JonnyFunFun JonnyFunFun committed Sep 12, 2012
Showing with 15 additions and 29 deletions.
  1. +2 −1 docs/targetprocess
  2. +13 −28 services/target_process.rb
View
@@ -31,8 +31,9 @@ Commit Message Syntax
General comment format for adding comments and/or changing entity states:
- #[Entity ID]:<new state>
+ (#|id:)[Entity ID]:<new state>
Eg: Fixed out of memory exceptions #1221:Fixed
+ id:1221:Fixed Fixed out of memory exceptions
The entire line will appear as a comment in your User Story, Bug, Feature, or Task; and the entity's
@@ -1,12 +1,13 @@
class Service::TargetProcess < Service
- string :base_url, :username, :project_id
+ string :base_url, :username
password :password
- white_list :base_url, :username, :project_id
+ white_list :base_url, :username
def receive_push
# setup things for our REST calls
http.ssl[:verify] = false
http.url_prefix = data['base_url']
+ http.headers['Content-Type'] = 'application/json'
http.basic_auth(data['username'], data['password'])
@project_id = data['project_id']
# And go!
@@ -30,48 +31,32 @@ def process_commit(commit)
author = commit["author"]["email"]
commit_url = commit["url"]
commit["message"].split("\n").each { |commit_line|
- parts = commit_line.match(/(\s|^)#(\d+)(:[^\s]+)?(\s|$)/)
+ parts = commit_line.match(/(\s|^)(?#|id:)(\d+)(:[^\s]+)?(\s|$)/)
next if parts.nil?
- entity_id = parts[2].strip
+ entity_id = parts[3].strip
next if entity_id.nil? or entity_id.length == 0
- if parts[3].nil? or parts[3].length == 0
+ if parts[4].nil? or parts[4].length == 0
command = nil
else
- command = parts[3].strip
+ command = parts[4].strip
end
- execute_command(author, entity_id, command, commit_line, commit_url)
+ execute_command(author, entity_id, command, commit_line, commit_url, commit)
}
end
- def execute_command(author, entity_id, command, commit_message, commit_url)
+ def execute_command(author, entity_id, new_state, commit_message, commit_url, raw_commit)
return if command.nil?
+ require 'json'
# get the user's id
res = http_get "api/v1/Users", {:where => "(Email eq '%s')" % author}
valid_response?(res)
- author_id = begin Hash.from_xml(res.body)['Users']['User']['Id'] rescue nil end
+ author_id = begin JSON.parse(res.body)['Users']['User']['Id'] rescue nil end
return if author_id.nil?
- # get Context data for our project
- res = http_get "api/v1/Context", :ids => @project_id
- valid_response?(res)
- context_data = Hash.from_xml res.body
- acid = context_data['Context']['Acid']
- # get the assignable's type
- res = http_get "api/v1/Assignables/%s" % entity_id, {:include => '[EntityType]', :acid => acid}
- valid_response?(res)
- assignable = Hash.from_xml res.body
- return if assignable.nil?
- entity_type = assignable['Assignable']['EntityType']['Name']
- # Gather next state's ID
- res = http_get "api/v1/Processes/%s/EntityStates" % [context_data['Context']['Processes']['ProcessInfo']['Id']],
- {:where => "(Name eq '%s') and (EntityType.Name eq '%s')" % [command, entity_type], :acid => acid}
- valid_response?(res)
- new_state = begin Hash.from_xml(res.body)['EntityStates']['EntityState']['Id'] rescue nil end
# Make it happen
- http.headers['Content-Type'] = 'application/json'
commit_message = "#{commit_message}<br />Commit: #{commit_url}"
valid_response?(http_post "api/v1/Comments", "{General: {Id: #{entity_id}}, Description: '#{commit_message.gsub("'","\'")}', Owner: {Id: #{author_id}}}")
- if !command.nil? and !new_state.nil?
- valid_response?(http_post "api/v1/%s" % ((entity_type == "UserStory") ? "UserStories" : entity_type+'s'), "{Id: #{entity_id}, EntityState: {Id: #{new_state}}}")
+ if !new_state.nil?
+ valid_response?(http_post "api/v1/Assignables/%s" % entity_id, "{EntityState: {Name: #{new_state}}}")
end
end
end

3 comments on commit 1f44abf

@nzben
nzben commented on 1f44abf Jul 29, 2014

Hey @JonnyFunFun, I'm experimenting with this service against tpondemand.com but your latest change seems to have a few problems:

  • TP isn't respecting Content-Type, and instead wants ?format=json
  • Your original code around requesting valid entity states for a given entitytype is still required.

Are you actively looking at this? To me it seems like a revert would get this working again.

@JonnyFunFun
Contributor

Hey @nzben! To be honest, there really hasn't been much progress on this hook now that Targetprocess has a native plugin for Git. I'd recommend checking that plugin out if you're looking to integrate your repositories with Targetprocess - it works a lot better. In the meantime, I'll make a note here to look into fixing this when some spare time comes around 😆

@nzben
nzben commented on 1f44abf Jul 29, 2014

Yeah, the integrated GitHub plugin is a bit useless, because it polls for changes every 5 minutes, and usually misses a few, especially with a busy repo.

What I've done instead is add a separate service that caters for TP OnDemand's unique API: #900

Please sign in to comment.