<commit_before>class BitbucketClient
  include HTTParty
  base_uri 'https://api.bitbucket.org/2.0/repositories'

  def initialize(username, password)
    self.class.basic_auth(username, password)
  end

  def commit_comments(slug, sha)
    response = get("/#{slug}/changesets/#{sha}/comments")
    openstruct(response['values'])
  end

  def create_commit_comment(slug, sha, body, path, position)
    post("/#{slug}/changesets/#{sha}/comments", body, path, position)
  end

  def pull_comments(slug, pull_id)
    response = get("/#{slug}/pullrequests/#{pull_id}/comments")
    openstruct(response['values'])
  end

  def pull_requests(slug)
    response = get("#{pull_request_api(slug)}/pullrequests?state=OPEN")
    openstruct(response['values'])
  end

  def create_pull_comment(slug, pull_id, body, path, position)
    post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position)
  end

  def approve_pull_request(slug, pull_id)
    self.class.post("#{slug}/pullrequests/#{pull_id}/approve")
  end

  def unapprove_pull_request(slug, pull_id)
    self.class.delete("#{slug}/pullrequests/#{pull_id}/approve")
  end

  private

  def openstruct(response)
    response.map { |r| OpenStruct.new(r) }
  end

  def post(url, body, path, position)
    options = {
      body: {
        content: body,
        line_to: position,
        filename: path
      }
    }
    self.class.post(url, options)
  end

  def get(url)
    self.class.get(url).parsed_response
  end
end
<commit_msg>Bitbucket deprecated its API v1.0: update all endpoints to API v2.0 (#348)<commit_after>class BitbucketClient
  include HTTParty
  base_uri 'https://api.bitbucket.org/2.0/repositories'

  def initialize(username, password)
    self.class.basic_auth(username, password)
  end

  def commit_comments(slug, sha)
    response = get("/#{slug}/changesets/#{sha}/comments")
    openstruct(response['values'])
  end

  def create_commit_comment(slug, sha, body, path, position)
    post("/#{slug}/changesets/#{sha}/comments", body, path, position)
  end

  def pull_comments(slug, pull_id)
    response = get("/#{slug}/pullrequests/#{pull_id}/comments")
    openstruct(response['values'])
  end

  def pull_requests(slug)
    response = get("/#{slug}/pullrequests?state=OPEN")
    openstruct(response['values'])
  end

  def create_pull_comment(slug, pull_id, body, path, position)
    post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position)
  end

  def approve_pull_request(slug, pull_id)
    self.class.post("/#{slug}/pullrequests/#{pull_id}/approve")
  end

  def unapprove_pull_request(slug, pull_id)
    self.class.delete("/#{slug}/pullrequests/#{pull_id}/approve")
  end

  private

  def openstruct(response)
    response.map { |r| OpenStruct.new(r) }
  end

  def post(url, body, path, position)
    options = {
      body: {
        content: body,
        line_to: position,
        filename: path
      }
    }
    self.class.post(url, options)
  end

  def get(url)
    self.class.get(url).parsed_response
  end
end

{'fraction_non_alphanumeric': 0.14111037673496366, 'fraction_numerical': 0.0036351619299405157, 'mean_word_length': 3.797147385103011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380666', 'n_tokens_mistral': 1020, 'n_tokens_neox': 1026, 'n_words': 195}