This repository was archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Initial support for Work Market service hook #346
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', { | ||
| :access_token => token, | ||
| :id => work_number, | ||
| :content => message, | ||
| :is_private => false | ||
| }.to_query | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: The authorization stub should return |
||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine.