<commit_before>require 'faraday'
require 'json'
require 'optparse'

module TravisDedup
  ACTIVE = %w[created started queued]

  class << self
    attr_accessor :pro, :verbose, :branches

    def cli(argv)
      parser = OptionParser.new do |opts|
        opts.banner = <<-BANNER.gsub(/^          /, "")
          Stop all builds on the same PR when a new job starts.

          Usage:
              travis-dedup your_org/your_repo $TRAVIS_ACCESS_TOKEN --pro

          Options:
        BANNER
        opts.on("--pro", "travis pro") { self.pro = true }
        opts.on("--branches", "dedup builds on branches too") { self.branches = true }
        opts.on("-h", "--help","Show this") { puts opts; exit }
        opts.on('-v', '--version','Show Version'){ require 'travis_dedup/version'; puts TravisDedup::VERSION; exit}
      end
      parser.parse!(argv)

      unless argv.size == 2
        puts parser
        return 1
      end

      puts dedup_message(*argv)
      0
    end

    def dedup(repo, access_token)
      dedup_builds(repo, access_token).last
    end

    def dedup_message(repo, access_token)
      all, canceled = dedup_builds(repo, access_token)
      canceled = (canceled.any? ? canceled.map { |b| b.fetch("id") }.join(", ") : "None")
      "Found #{all.size} builds, canceled: #{canceled}"
    end

    def access_token(github_token)
      request(:post, "auth/github", github_token: github_token).fetch("access_token")
    end

    private

    def dedup_builds(repo, access_token)
      builds = active_builds(repo, access_token)
      cancel = duplicate_builds(builds)
      cancel(cancel, access_token)<commit_msg>fix travis being unreachable ... https://github.com/travis-ci/travis-ci/issues/5649<commit_after>require 'faraday'
require 'json'
require 'optparse'

module TravisDedup
  ACTIVE = %w[created started queued]

  class << self
    attr_accessor :pro, :verbose, :branches

    def cli(argv)
      parser = OptionParser.new do |opts|
        opts.banner = <<-BANNER.gsub(/^          /, "")
          Stop all builds on the same PR when a new job starts.

          Usage:
              travis-dedup your_org/your_repo $TRAVIS_ACCESS_TOKEN --pro

          Options:
        BANNER
        opts.on("--pro", "travis pro") { self.pro = true }
        opts.on("--branches", "dedup builds on branches too") { self.branches = true }
        opts.on("-h", "--help","Show this") { puts opts; exit }
        opts.on('-v', '--version','Show Version'){ require 'travis_dedup/version'; puts TravisDedup::VERSION; exit}
      end
      parser.parse!(argv)

      unless argv.size == 2
        puts parser
        return 1
      end

      puts dedup_message(*argv)
      0
    end

    def dedup(repo, access_token)
      dedup_builds(repo, access_token).last
    end

    def dedup_message(repo, access_token)
      all, canceled = dedup_builds(repo, access_token)
      canceled = (canceled.any? ? canceled.map { |b| b.fetch("id") }.join(", ") : "None")
      "Found #{all.size} builds, canceled: #{canceled}"
    end

    def access_token(github_token)
      request(:post, "auth/github", {github_token: github_token}, 'User-Agent' => 'Travis/1.0').fetch("access_token")
    end

    private

    def dedup_builds(repo, access_token)
      builds = active_builds(repo, access_token)
      cancel = duplicate_builds(builds)
      cancel(cancel, access_token)
{'fraction_non_alphanumeric': 0.12928994082840237, 'fraction_numerical': 0.0035502958579881655, 'mean_word_length': 2.6044776119402986, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '6394975', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1100, 'n_words': 265}