Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/workmarket
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Work Market
===========

Use this service hook to add notes to Work Market assignments.

Install Notes
-------------

**API token and secret** - One of your company's API tokens. See [Settings > API](http://www.workmarket.com/mmw/api)

In order to update an assignment, you must include the Work Market assignment number in the commit message, e.g.:

Fixed a bug [#1234567890]

Developer Notes
---------------

data
- token
- secret

payload
- refer to docs/github_payload
47 changes: 47 additions & 0 deletions services/workmarket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class Service::Workmarket < Service

string :token
password :secret
white_list :token
default_events :push

def auth_token
http.url_prefix = 'https://www.workmarket.com/api/v1'
http.headers['Accept'] = 'application/json'

r = http_post 'authorization/request', {
:token => data['token'],
:secret => data['secret'],
:type => 'json'
}.to_query

response = JSON.parse(r.body)
token = response['response']['access_token']

raise_config_error 'Invalid API token or secret' if token.empty?

token
end

def receive_push
token = auth_token

commits.each do |commit|
next if commit['message'] =~ /^x /

commit['message'].match(/\[#(\d{10})\]/)

next unless $1

work_number = $1
message = "#{commit['id'][0..6]} #{format_commit_message(commit)}"

http_post 'assignments/add_note', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way you can change this to a single HTTP request?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. The push summary should suffice here anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, at the moment, not possible to reduce down to a single request. The existing Work Market API doesn't support a batch payload, and commit messages identify specific entities that they need to be attached to.

Current usage is purely for internal tests at the moment. Is this something you're completely against or think it could fly with low volume?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine.

:access_token => token,
:id => work_number,
:content => message,
:is_private => false
}.to_query
end
end
end
25 changes: 25 additions & 0 deletions test/workmarket_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require File.expand_path('../helper', __FILE__)

class WorkmarketTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
end

def test_push
@stubs.post "/api/v1/authorization/request" do |env|
assert_equal 'application/json', env[:request_headers]['Content-Type']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tests don't work. You're setting Accept, but not Content-Type above, and definitely not sending JSON.

Also, you've only stubbed the token request, and not the commits. The test fails:

test_push(WorkmarketTest):
NoMethodError: undefined method `[]' for nil:NilClass
    /Users/rick/p/github-services/lib/service/../../services/workmarket.rb:19:in `auth_token'
    /Users/rick/p/github-services/lib/service/../../services/workmarket.rb:27:in `receive_push'
    test/workmarket_test.rb:19:in `test_push'

The authorization stub should return {"response":{"access_token":"monkey"}} so it can parse the token out and send the commits.

assert_equal 'www.workmarket.com', env[:url].host
[200, {}, '']
end

svc = service(
{'token' => 't', 'secret' => 's'},
payload
)
svc.receive_push
end

def service(*args)
super Service::Workmarket, *args
end
end