<commit_before>require 'time'

module Dd
  class Gh
    def initialize(token, org, since)
      @org = org
      @github = Github.new oauth_token: token, auto_pagination: true
      @digest = ""
      @since = since
    end

    def run
      collect(@org)
      if(@digest.length > 0)
        <<-EOS
## Github activity in the #{@org} org

#{@digest}
        EOS
      else
        <<-EOS
## Github activity in the #{@org} org

*No activity reported for the monitored repos in this time period*
        EOS
      end
    end

    private

    def add(row)
      @digest << "#{row}\n"
    end

    def collect(org)

      repos = get_repos(ENV['GITHUB_REPOS'], org)
      repos.each do |repo_and_org|

        # repo can contain an override org
        repo, repo_org = repo_and_org.split("@").push(org)
        commits = @github.repos.commits.list(repo_org, repo, since: @since.iso8601)

        if commits.any?

          add "### Commits to #{repo}/master"
          add ""

          commits.each do |commit_data|
            commit = commit_data["commit"]
            if(commit && commit["message"])
              commit_msg = commit["message"].split("\n").first
              add "* [#{commit_msg}](#{commit_data["html_url"]}) by #{commit["committer"]["name"]}"
            end
          end
          add ""
        end
      end

      rescue => e
        add e.to_s
        e.backtrace.each { |line| add(' ' + line) }
    end

    def get_repos(repos, org)
      if repos
        repos = repos.split(",")
      else
        repos = []
        @github.repos.list(:org => org) { |repo|
          repos << repo.name
        }
      end
      repos.sort
      repos
    end

  end
end
<commit_msg>List included repos in email<commit_after>require 'time'

module Dd
  class Gh
    def initialize(token, org, since)
      @org = org
      @github = Github.new oauth_token: token, auto_pagination: true
      @digest = ""
      @since = since
    end

    def run
      collect(@org)

      body = "## Github activity in the #{@org} org\n\n"
      if(@digest.length > 0)
        body += @digest
      else
        body += "*No activity reported for the monitored repos in this time period*"
      end
      body += "\n*The following repositories were included in this digest: #{ENV["GITHUB_REPOS"].split(",").join(", ")}*"
    end

    private

    def add(row)
      @digest << "#{row}\n"
    end

    def collect(org)

      repos = get_repos(ENV['GITHUB_REPOS'], org)
      repos.each do |repo_and_org|

        # repo can contain an override org
        repo, repo_org = repo_and_org.split("@").push(org)
        commits = @github.repos.commits.list(repo_org, repo, since: @since.iso8601)

        if commits.any?

          add "### Commits to #{repo}/master"
          add ""

          commits.each do |commit_data|
            commit = commit_data["commit"]
            if(commit && commit["message"])
              commit_msg = commit["message"].split("\n").first
              add "* [#{commit_msg}](#{commit_data["html_url"]}) by #{commit["committer"]["name"]}"
            end
          end
          add ""
        end
      end

      rescue => e
        add e.to_s
        e.backtrace.each { |line| add(' ' + line) }
    end

    def get_repos(repos, org)
      if repos
        repos = repos.split(",")
      else
        repos = []
        @github.repos.list(:org => org) { |repo|
          repos << repo.name
        }
      end
      repos.sort
      repos
    end

  end
end

{'fraction_non_alphanumeric': 0.130720823798627, 'fraction_numerical': 0.002860411899313501, 'mean_word_length': 1.8292880258899675, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2299072', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1078, 'n_words': 287}