<commit_before>/* @flow */

import axios from 'axios'

const state: any = {
  api: 'https://api.github.com/gists',
  token: '',
  isSending: false,
  gistUrl: '',
  errorMsg: '',
  gist: {
    'description': '',
    'public': true, // default
    'files': {}
  },
  validation: {
    'fileName': {
      getMessage (field: string): string {
        return `The ${field} field contains characters that can not be used in the ${field}.`
      },
      validate (value: string): boolean {
        return !/^.*[(\s|\\|/|'|"|?|<|>|:|*)].*$/.test(value)
      }
    }
  },
  ext: {
    'txt': 'plantuml',
    'svg': 'svg'
  }
}

const mutations: any = {
  setToken (state: any, token: string) {
    state.token = token
  },
  setDescription (state: any, description: string) {
    state.gist.description = description
  },
  setPublic (state: any, isPublic: boolean) {
    state.gist.public = isPublic
  },
  addFiles (state: any, data: any) {
    if (data && data.fileName && data.text && data.ext) {
      state.gist.files[`${data.fileName}.${data.ext}`] = {
        'content': data.text
      }
    }
  },
  resetFiles () {
    state.gist.files = {}
  },
  addTxtUML (state: any, data: any) {
    if (data) {
      data.ext = state.ext.txt
      mutations.addFiles(state, data)
    }
  },
  addSvgUML (state: any, data: any): any {
    return axios.get(data.src || '')
    .then((response: any) => {
      if (response && response.data) {
        data.ext = state.ext.svg
        data.text = response.data
        mutations.addFiles(state, data)
      }
    })
  },
  createGist (state: any, data: any) {
    // 送信中フラグ ON
    state.isSending = true

    // リセット
    mutations.resetResponse()
    mutations.resetFiles()

    // テキスト追加
    mutations.addTxtUML(state, data)

    // svg 再取得
    axios.all([mutations.addSvgUML(state, data)])
    .then(axios.spread(() => {
      // text と svg が両方ある場合
      if (Object.keys(state.gist.files).length >= 2) {
        // Gist 投稿
        axios.post(`${state.api}?access_token=${state.token}`, state.gist)
        .then((response: any) => {
          state.gistUrl = response.data.html_url
          state.isSending = false
        })
        .catch((error: any) => {
          state.errorMsg = `${error.response.status} ${error.response.statusText} ${error.response.data.message}`
          state.isSending = false
        })
      } else {
        state.errorMsg = 'could not get SVG'
        state.isSending = false
      }
    }))
  },
  resetGist () {
    mutations.setDescription(state, '')
    mutations.setPublic(state, true)
    mutations.resetFiles()
    mutations.resetResponse()
  },
  resetResponse () {
    state.gistUrl = ''
    state.errorMsg = ''
  }
}

const actions: any = {
  setToken (context: any, token: string) {
    context.commit('setToken', token)
  },
  setDescription (context: any, description: string) {
    context.commit('setDescription', description)
  },
  setPublic (context: any, isPublic: boolean) {
    context.commit('setPublic', isPublic)
  },
  createGist (context: any, data: any) {
    context.commit('createGist', data)
  },
  resetGist (context: any) {
    context.commit('resetGist')
  }
}

export default {
  state,
  mutations,
  actions
}
<commit_msg>非同期処理を actions へ移行<commit_after>/* @flow */

import axios from 'axios'

const state: any = {
  api: 'https://api.github.com/gists',
  token: '',
  isSending: false,
  gistUrl: '',
  errorMsg: '',
  gist: {
    'description': '',
    'public': true, // default
    'files': {}
  },
  validation: {
    'fileName': {
      getMessage (field: string): string {
        return `The ${field} field contains characters that can not be used in the ${field}.`
      },
      validate (value: string): boolean {
        return !/^.*[(\s|\\|/|'|"|?|<|>|:|*)].*$/.test(value)
      }
    }
  },
  ext: {
    'txt': 'plantuml',
    'svg': 'svg'
  }
}

const mutations: any = {
  setToken (state: any, token: string) {
    state.token = token
  },
  setDescription (state: any, description: string) {
    state.gist.description = description
  },
  setPublic (state: any, isPublic: boolean) {
    state.gist.public = isPublic
  },
  addFiles (state: any, data: any) {
    if (data && data.fileName && data.text && data.ext) {
      state.gist.files[`${data.fileName}.${data.ext}`] = {
        'content': data.text
      }
    }
  },
  resetFiles () {
    state.gist.files = {}
  },
  startSending (state: any) {
    state.isSending = true
  },
  stopSending (state: any) {
    state.isSending = false
  },
  setGistURL (state: any, url: string) {
    state.gistUrl = url
  },
  setErrorMsg (state: any, errorMsg: string) {
    state.errorMsg = errorMsg
  },
  resetResponse () {
    state.gistUrl = ''
    state.errorMsg = ''
  }
}

const actions: any = {
  setToken (context: any, token: string) {
    context.commit('setToken', token)
  },
  setDescription (context: any, description: string) {
    context.commit('setDescription', description)
  },
  setPublic (context: any, isPublic: boolean) {
    context.commit('setPublic', isPublic)
  },
  addTxtUML ({state, commit}: any, data: any) {
    if (data) {
      data.ext = state.ext.txt
      commit('addFiles', data)
    }
  },
  addSvgUML ({state, commit}: any, data: any): any {
    return axios.get(data.src || '')
    .then((response: any) => {
      if (response && response.data) {
        data.ext = state.ext.svg
        data.text = response.data
        commit('addFiles', data)
      }
    })
  },
  createGist ({state, commit, dispatch}: any, data: any) {
    // 送信中フラグ ON
    commit('startSending')

    // リセット
    commit('resetResponse')
    commit('resetFiles')

    // テキスト追加
    dispatch('addTxtUML', data)

    // svg 再取得
    axios.all([dispatch('addSvgUML', data)])
    .then(axios.spread(() => {
      // text と svg が両方ある場合
      if (Object.keys(state.gist.files).length >= 2) {
        // Gist 投稿
        axios.post(`${state.api}?access_token=${state.token}`, state.gist)
        .then((response: any) => {
          commit('setGistURL', response.data.html_url)
          commit('stopSending')
        })
        .catch((error: any) => {
          commit('setErrorMsg', `${error.response.status} ${error.response.statusText} ${error.response.data.message}`)
          commit('stopSending')
        })
      } else {
        commit('setErrorMsg', 'could not get SVG')
        commit('stopSending')
      }
    }))
  },
  resetGist ({commit}: any) {
    commit('setDescription', '')
    commit('setPublic', true)
    commit('resetFiles')
    commit('resetResponse')
  }
}

export default {
  state,
  mutations,
  actions
}

{'fraction_non_alphanumeric': 0.17046655594141627, 'fraction_numerical': 0.00030197795560924054, 'mean_word_length': 2.4808197582764056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '4200637', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2325, 'n_words': 465}