<commit_before>import github from 'octonode'

function getTeam (client, cohort, cb) {
  client.org(cohort)
    .teams((err, teams) => {
      if (err) {
        console.error(`Couldn't get teams for cohort \`${cohort}\`.`)
        return
      }
      cb(teams.find((t) => {
        return t.slug === cohort
      }))
    })
}

function getTeamMembers (client, team, cb) {
  client.team(team)
    .members((err, members) => {
      if (err) {
        console.error(`Couldn't get members for the cohort team.`)
        return
      }
      cb(members.map((member) => {
        return member.login
      }))
    })
}

function getAssignments (client, sprint, cb) {
  client.repo('dev-academy-programme/curriculum-private')
    .contents('assignments', (err, assignments) => {
      if (err) {
        console.error(`Couldn't get the assignments from the curriculum repo.`)
        return
      }
      if (assignments.length === 0) {
        console.error(`No assignments found for that sprint.`)
        return
      }
      cb(assignments.map((assignment) => {
        return assignment.path
      }))
    })
}

function push (sprint, cohort) {
  if (!process.env['WTR_OAUTH_TOKEN']) {
    console.error('Please set WTR_OAUTH_TOKEN')
    return
  }

  const client = github.client(process.env['WTR_OAUTH_TOKEN']);

  getTeam(client, cohort, (team) => {
    if (!team) {
      console.error(`Can't find a team named \`${cohort}\` on org \`${cohort}\`.`)
      return
    }
    getTeamMembers(client, team.id, (members) => {
      getAssignments(client, sprint, (assignments) => {
      })
    })
  })
  console.log(`Pushing sprint ${sprint} assignments to \`${cohort}\`...`)
}

export default push
<commit_msg>Successful issue posting, but no assignee<commit_after>import github from 'octonode'

function getTeam (client, cohort, next) {
  console.log(`Checking for a \`${cohort}\` cohort...`)
  client.org(cohort)
    .teams((err, teams) => {
      if (err) {
        return next(new Error(`Couldn't get teams for cohort ${cohort}.`))
      }
      const team = teams.find((t) => {
        return t.slug === cohort
      })
      if (!team) {
        return next(new Error(`Can't find team '${cohort}' on org '${cohort}'.`))
      }
      next(null, team)
    })
}

function getTeamMembers (client, team, next) {
  console.log(`Getting the students for cohort with team id ${team}...`)
  client.team(team)
    .members((err, members) => {
      if (err) {
        return next(new Error(`Couldn't get members for the cohort team.`))
      }
      next(null, members.map((member) => {
        return member.login
      }))
    })
}

function matchSprint (sprint, assignment) {
  if (assignment.split('-')[0] === 'p') {
    return true
  }
  const prefix = assignment.split('.')[0]
  const n = parseInt(prefix, 10)
  if (isNaN(n)) {
    return false
  }
  return sprint === n
}

function getAssignments (client, sprint, next) {
  console.log(`Getting assignment list for sprint ${1}...`)
  client.repo('dev-academy-programme/curriculum-private')
    .contents('assignments', (err, assignments) => {
      if (err) {
        return next(new Error(`Couldn't get the assignments from the curriculum repo.`))
      }
      if (assignments.length === 0) {
        return next(new Error(`No assignments found for that sprint.`))
      }
      next(null, assignments
        .filter((assignment) => {
          return matchSprint(sprint, assignment.name)
        })
        .map((assignment) => {
          return assignment.path
        }))
    })
}

function getAssignmentFile (client, assignment, next) {
  client.repo('dev-academy-programme/curriculum-private')
    .contents(`${assignment}/README.md`, (err, file) => {
      if (err) {
        return next(new Error(`Couldn't get assignment content for ${assignment}`))
      }
      next(null, file)
    })
}

function postAssignment (client, sprint, cohort, student, assignment, next) {
  const body = Buffer.from(assignment.content, 'base64').toString('utf8')
  const title = body.split('\n')[0]

  client.repo(`${cohort}/${cohort}`)
    .issue({
      title: title,
      body: body,
      assigneee: student,
      labels: [`sprint-${sprint}`]
    }, (err, issue) => {
      if (err) {
        return next(new Error(`Couldn't post issue: ${title}`))
      }
      next(null, issue)
    })
}

function push (sprint, cohort) {
  if (!process.env['WTR_OAUTH_TOKEN']) {
    console.error('Please set WTR_OAUTH_TOKEN')
    return
  }

  const client = github.client(process.env['WTR_OAUTH_TOKEN']);

  getTeam(client, cohort, (err, team) => {
    if (err) {
      console.error(err.message)
      return
    }

    getTeamMembers(client, team.id, (err, members) => {
      if (err) {
        console.error(err.message)
        return
      }
      getAssignments(client, sprint, (err, assignments) => {
        if (err) {
          console.error(err.message)
          return
        }
        assignments.forEach((assignment) => {
          getAssignmentFile(client, assignment, (err, file) => {
            if (err) {
              console.error(err.message)
              return
            }
            members.forEach((member) => {
              postAssignment(client, sprint, cohort, member, file, (err, result) => {
                if (err) {
                  console.error(err.message)
                  return
                }
                return
              })
              console.log(`Assignments pushed for ${member}.`)
            })
          })
        })
      })
    })
  })
  console.log(`Pushing sprint ${sprint} assignments to '${cohort}'...`)
}

export default push

{'fraction_non_alphanumeric': 0.15349166962070188, 'fraction_numerical': 0.0019496632399858206, 'mean_word_length': 2.331168831168831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '4339614', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1755, 'n_words': 405}