Class: Danger::RequestSources::VSTSAPI
- Inherits:
-
Object
- Object
- Danger::RequestSources::VSTSAPI
- Defined in:
- lib/danger/request_sources/vsts_api.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#min_api_version_for_comments ⇒ Object
Returns the value of attribute min_api_version_for_comments.
-
#pr_api_endpoint ⇒ Object
Returns the value of attribute pr_api_endpoint.
Instance Method Summary collapse
- #credentials_given? ⇒ Boolean
- #fetch_last_comments ⇒ Object
- #fetch_pr_json ⇒ Object
-
#initialize(_project, slug, pull_request_id, environment) ⇒ VSTSAPI
constructor
A new instance of VSTSAPI.
- #inspect ⇒ Object
- #post_comment(text) ⇒ Object
- #supports_comments? ⇒ Boolean
- #update_comment(thread, id, new_comment) ⇒ Object
Constructor Details
#initialize(_project, slug, pull_request_id, environment) ⇒ VSTSAPI
Returns a new instance of VSTSAPI.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/danger/request_sources/vsts_api.rb', line 11 def initialize(_project, slug, pull_request_id, environment) self.min_api_version_for_comments = "3.0" user_name = "" personal_access_token = environment["DANGER_VSTS_API_TOKEN"] @token = Base64.strict_encode64("#{user_name}:#{personal_access_token}") @api_version = environment["DANGER_VSTS_API_VERSION"] ||= self.min_api_version_for_comments self.host = environment["DANGER_VSTS_HOST"] if self.host && !(self.host.include? "http://") && !(self.host.include? "https://") self.host = "https://" + self.host end self.pr_api_endpoint = "#{host}/_apis/git/repositories/#{slug}/pullRequests/#{pull_request_id}" end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/danger/request_sources/vsts_api.rb', line 9 def host @host end |
#min_api_version_for_comments ⇒ Object
Returns the value of attribute min_api_version_for_comments.
9 10 11 |
# File 'lib/danger/request_sources/vsts_api.rb', line 9 def min_api_version_for_comments @min_api_version_for_comments end |
#pr_api_endpoint ⇒ Object
Returns the value of attribute pr_api_endpoint.
9 10 11 |
# File 'lib/danger/request_sources/vsts_api.rb', line 9 def pr_api_endpoint @pr_api_endpoint end |
Instance Method Details
#credentials_given? ⇒ Boolean
45 46 47 |
# File 'lib/danger/request_sources/vsts_api.rb', line 45 def credentials_given? @token && !@token.empty? end |
#fetch_last_comments ⇒ Object
54 55 56 57 |
# File 'lib/danger/request_sources/vsts_api.rb', line 54 def fetch_last_comments uri = URI("#{pr_api_endpoint}/threads?api-version=#{@api_version}") fetch_json(uri)[:value] end |
#fetch_pr_json ⇒ Object
49 50 51 52 |
# File 'lib/danger/request_sources/vsts_api.rb', line 49 def fetch_pr_json uri = URI("#{pr_api_endpoint}?api-version=#{@api_version}") fetch_json(uri) end |
#inspect ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/danger/request_sources/vsts_api.rb', line 35 def inspect inspected = super if @token inspected = inspected.sub! @token, "********".freeze end inspected end |
#post_comment(text) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/danger/request_sources/vsts_api.rb', line 59 def post_comment(text) uri = URI("#{pr_api_endpoint}/threads?api-version=#{@api_version}") body = { "comments" => [ { "parentCommentId" => 0, "content" => text, "commentType" => 1 } ], "properties" => { "Microsoft.TeamFoundation.Discussion.SupportsMarkdown" => { "type" => "System.Int32", "value" => 1 } }, "status" => 1 }.to_json post(uri, body) end |
#supports_comments? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/danger/request_sources/vsts_api.rb', line 28 def supports_comments? major_version = @api_version.split(".").first.to_i minimun_version_for_comments = self.min_api_version_for_comments.split(".").first.to_i major_version >= minimun_version_for_comments end |
#update_comment(thread, id, new_comment) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/danger/request_sources/vsts_api.rb', line 80 def update_comment(thread, id, new_comment) uri = URI("#{pr_api_endpoint}/threads/#{thread}/comments/#{id}?api-version=#{@api_version}") body = { "content" => new_comment }.to_json patch(uri, body) end |