<commit_before>'use strict'

const Fetch = require('node-fetch')
const Qs = require('qs')

class Jira {
  constructor (config) {
    this.config = config
    this.defaults = {
      method: 'GET',
      mode: 'cors',
      headers: {
        'Authorization': 'Basic ' + new Buffer(`${config.username}:${config.password}`).toString('base64'),
        'Content-Type': 'application/json',
        Accept: 'application/json'
      }
    }
  }
  fetchWithDefaults (url, options = {}) {
    const opts = Object.assign({}, this.defaults, options)
    return Fetch(url, opts).then((response) => {
      if (!response.ok) {
        const error = new Error(response.statusText)
        error.response = response
        throw error
      }
      if (response.status === 204) {
        return Promise.resolve({})
      }
      return response.json()
    })
  }
  search (jql) {
    const startAt = 0
    const maxResults = 1000
    const qs = Qs.stringify({
      jql,
      startAt,
      maxResults
    })
    return this.fetchWithDefaults(`${this.config.server}rest/api/2/search?${qs}`)
  }
  getIssue (id) {
    return Promise.resolve({})
  }
}

exports = module.exports = Jira<commit_msg>split out handling for search and by id<commit_after>'use strict'

const Fetch = require('node-fetch')
const Qs = require('qs')

class Jira {
  constructor (config) {
    this.config = config
    this.defaults = {
      method: 'GET',
      mode: 'cors',
      headers: {
        'Authorization': 'Basic ' + new Buffer(`${config.username}:${config.password}`).toString('base64'),
        'Content-Type': 'application/json',
        Accept: 'application/json'
      }
    }
  }

  /**
   * Pass a search query to Jira
   * [Jira Doc](https://docs.atlassian.com/jira/REST/cloud/#api/2/search-search)
   * @name search
   * @function
   * @param {string} jql - jira query string in JQL
   */
  search (jql) {
    const startAt = 0
    const maxResults = 1000
    const qs = Qs.stringify({
      jql,
      startAt,
      maxResults,
      fields: this.config.issueFields.join(',')
    })
    console.log(qs)
    const url = `${this.config.server}rest/api/2/search?${qs}`
    const opts = Object.assign({}, this.defaults, {})
    return Fetch(url, opts).then((response) => {
      if (!response.ok) {
        const error = new Error(response.statusText)
        error.response = response
        throw error
      }
      return response.json()
    })
  }

  /**
   * Gets an issue in jira, or returns undefine
   * @name getIssue
   * @function
   * [Jira Doc](https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getIssue)
   * @param {string} key - The issue key (including the project key prefix)
   */
  getIssue (key) {
    const qs = Qs.stringify({
      fields: this.config.issueFields.join(',')
    })
    const url = `${this.config.server}rest/api/2/issue/${key}?${qs}`
    const opts = Object.assign({}, this.defaults, {})
    return Fetch(url, opts).then((response) => {
      if (response.status === 404) {
        return Promise.resolve(undefined)
      }
      if (!response.ok) {
        const error = new Error(response.statusText)
        error.response = response
        throw error
      }
      return response.json()
    })
  }
}

exports = module.exports = Jira
{'fraction_non_alphanumeric': 0.15033680342927128, 'fraction_numerical': 0.0076546233925290875, 'mean_word_length': 2.464475079533404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '612024', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1038, 'n_words': 232}