<commit_before>/* eslint-disable prefer-arrow-callback */
import Promise from 'bluebird'
import generateProjectName from 'src/server/actions/generateProjectName'
import sendCycleLaunchAnnouncements from 'src/server/actions/sendCycleLaunchAnnouncements'
import {formProjectsIfNoneExist} from 'src/server/actions/formProjects'
import {getGoalInfo} from 'src/server/services/goalLibraryService'
import {Phase, Member, Project} from 'src/server/services/dataService'

export function start() {
  const jobService = require('src/server/services/jobService')
  jobService.processJobs('cycleLaunched', processCycleLaunched)
}

export async function processCycleLaunched(cycle) {
  console.log(`Forming teams for cycle ${cycle.cycleNumber} of chapter ${cycle.chapterId}`)

  const nonVotingProjects = await _createProjectsInCycleForNonVotingPhases(cycle)
  console.log(`${nonVotingProjects.length} project(s) created for non-voting phases`)

  const votingProjects = await formProjectsIfNoneExist(cycle.id, null)
  console.log(`${votingProjects.length} project(s) created for voting phases`)

  try {
    await sendCycleLaunchAnnouncements(cycle.id)
  } catch (err) {
    console.warn(`Failed to send cycle launch announcement for cycle ${cycle.cycleNumber}: ${err}`)
  }
}

async function _createProjectsInCycleForNonVotingPhases(cycle) {
  console.log('Automatically creating projects for non-voting phases')

  const nonVotingPhases = await Phase.filter({hasVoting: false}).hasFields('practiceGoalNumber')
  if (nonVotingPhases.length === 0) {
    console.log('No non-voting phases found; skipped')
    return []
  }

  let newPhaseProjects = []
  await Promise.each(nonVotingPhases, async phase => {
    const existingProjects = await Project.filter({cycleId: cycle.id, phaseId: phase.id})
    if (existingProjects.length > 0) {
      console.log(`Existing projects found for non-voting phase ${phase.number}; skipped`)
      return<commit_msg>Removes unnecessary null parameter<commit_after>/* eslint-disable prefer-arrow-callback */
import Promise from 'bluebird'
import generateProjectName from 'src/server/actions/generateProjectName'
import sendCycleLaunchAnnouncements from 'src/server/actions/sendCycleLaunchAnnouncements'
import {formProjectsIfNoneExist} from 'src/server/actions/formProjects'
import {getGoalInfo} from 'src/server/services/goalLibraryService'
import {Phase, Member, Project} from 'src/server/services/dataService'

export function start() {
  const jobService = require('src/server/services/jobService')
  jobService.processJobs('cycleLaunched', processCycleLaunched)
}

export async function processCycleLaunched(cycle) {
  console.log(`Forming teams for cycle ${cycle.cycleNumber} of chapter ${cycle.chapterId}`)

  const nonVotingProjects = await _createProjectsInCycleForNonVotingPhases(cycle)
  console.log(`${nonVotingProjects.length} project(s) created for non-voting phases`)

  const votingProjects = await formProjectsIfNoneExist(cycle.id)
  console.log(`${votingProjects.length} project(s) created for voting phases`)

  try {
    await sendCycleLaunchAnnouncements(cycle.id)
  } catch (err) {
    console.warn(`Failed to send cycle launch announcement for cycle ${cycle.cycleNumber}: ${err}`)
  }
}

async function _createProjectsInCycleForNonVotingPhases(cycle) {
  console.log('Automatically creating projects for non-voting phases')

  const nonVotingPhases = await Phase.filter({hasVoting: false}).hasFields('practiceGoalNumber')
  if (nonVotingPhases.length === 0) {
    console.log('No non-voting phases found; skipped')
    return []
  }

  let newPhaseProjects = []
  await Promise.each(nonVotingPhases, async phase => {
    const existingProjects = await Project.filter({cycleId: cycle.id, phaseId: phase.id})
    if (existingProjects.length > 0) {
      console.log(`Existing projects found for non-voting phase ${phase.number}; skipped`)
      return
{'fraction_non_alphanumeric': 0.10603337612323492, 'fraction_numerical': 0.0010269576379974327, 'mean_word_length': 5.823117338003502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6877246', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1138, 'n_words': 267}