<commit_before># Description
#   A hubot script that shows who has the longest github streak in your org
#
# Configuration:
#   LIST_OF_ENV_VARS_TO_SET
#   HUBOT_ORG_ACCESS_TOKEN
#
# Commands:
#   streak ladder - <Gets a list of the longest github commit streaks in your org>
#
# Notes:
#   An access token is required by the github api to access a private org's members
#   so an account that is a member of the private org is required.
#
# Author:
#   <NAME> <<EMAIL>>
#   <NAME> <>

Promise = require("bluebird")
request = Promise.promisify(require("request"))

module.exports = (robot) ->
  robot.hear /ladder/i, (res) ->
    orgLogin = "pulseenergy"  # TODO: also get this from an env var
    access_token = process.env.HUBOT_ORG_ACCESS_TOKEN
    unless access_token?
      console.log("Missing ORG_ACCESS_TOKEN in environment: please set and try again")
      return
    console.log("Found the access token in the environment! #{access_token}")

    options = {
      uri: "https://api.github.com/orgs/#{orgLogin}/members",
      json: "true",
      headers: {
        "accept": "application/json",
        "Authorization": "token #{access_token}",
        'User-Agent': 'request'
      }
    }
    request(options).spread((response, body) ->
      console.log(response)
      console.log('\n\n@@@\n')
      console.log(body)
      return body
    ).then((body) ->
      # Use a map here to create an array of promises, then promise.all the promises
      # and iterate through results to get contribs for each user.
      return getContributions(body[0].login)
    ).then((user) ->
      console.log('\n\nUSERLOGIN')
      console.log(user)
    )

getContributions = (userLogin) ->
  request({uri: "https://github.com/users/#{userLogin}/contributions"}).spread((response, body) ->
    return body
  )
<commit_msg>Get contributions for each user in org<commit_after># Description
#   A hubot script that shows who has the longest github streak in your org
#
# Configuration:
#   LIST_OF_ENV_VARS_TO_SET
#   HUBOT_ORG_ACCESS_TOKEN
#
# Commands:
#   streak ladder - <Gets a list of the longest github commit streaks in your org>
#
# Notes:
#   An access token is required by the github api to access a private org's members
#   so an account that is a member of the private org is required.
#
# Author:
#   <NAME> <<EMAIL>>
#   <NAME> <>

Promise = require("bluebird")
request = Promise.promisify(require("request"))
_ = require("underscore")

module.exports = (robot) ->
  robot.hear /ladder/i, (res) ->
    orgLogin = "pulseenergy"  # TODO: also get this from an env var
    access_token = process.env.HUBOT_ORG_ACCESS_TOKEN
    unless access_token?
      console.log("Missing ORG_ACCESS_TOKEN in environment: please set and try again")
      return
    console.log("Found the access token in the environment! #{access_token}")

    options = {
      uri: "https://api.github.com/orgs/#{orgLogin}/members",
      json: "true",
      headers: {
        "accept": "application/json",
        "Authorization": "token #{access_token}",
        'User-Agent': 'request'
      }
    }

    # Store the contribution svgs in this list
    contributions = []

    request(options).spread((response, body) ->
      # console.log(response)
      return body
    ).then((body) ->
      promises = _.map(body, (userJson) ->
        return getContributions(userJson.login, contributions)
      )

      Promise.all(promises).then(() ->
        console.log("what should we have here?")
        console.log("contributions: ", contributions.length)
      )
    )

getContributions = (userLogin, contributions) ->
  console.log(userLogin)
  return request({uri: "https://github.com/users/#{userLogin}/contributions"}).spread((response, body) ->
    contributions.push(body)
  )

{'fraction_non_alphanumeric': 0.1245683930942895, 'fraction_numerical': 0.0002656042496679947, 'mean_word_length': 3.165929203539823, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 30, 'https://': 4, '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': '3916595', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1152, 'n_words': 330}