<commit_before>'use strict'

const express = require('express')
const Slapp = require('slapp')
const ConvoStore = require('slapp-convo-beepboop')
const Context = require('slapp-context-beepboop')
require('dotenv').config() // uid/pw go in .env file not checked in

const jira = require('./jira')

// use `PORT` env var on Beep Boop - default to 3000 locally
var port = process.env.PORT || 3000

var slapp = Slapp({
  // Beep Boop sets the SLACK_VERIFY_TOKEN env var
  verify_token: process.env.SLACK_VERIFY_TOKEN,
  convo_store: ConvoStore(),
  context: Context()
})

var previousIssue = ''

// response to the user typing "help"
slapp.message('help', ['mention', 'direct_message'], (msg) => {
  msg.say(`
I will respond to the following messages:
\`help\` - to see this message
\`(ra16-|mds-|px-|vm-|vnow-)1234\` - to fetch a JIRA issue (e.g. PX-1416 or VNOW-5081).
\`rand\` - show me a random Low priority bug from the Spark Backlog
`)
})

// return a random Spark low priority bug from the backlog
slapp.message('rand', ['mention', 'direct_message'], (msg) => {
  const bugs = ['VNOW-6343', 'VNOW-6340', 'VNOW-6338', 'VNOW-6334', 'VNOW-6330', 'VNOW-6329', 'VNOW-6328', 'VNOW-6327', 'VNOW-6317', 'VNOW-6215', 'VNOW-6188', 'VNOW-6185', 'VNOW-6184', 'VNOW-6176', 'VNOW-6175', 'VNOW-6172', 'VNOW-6151', 'VNOW-6150', 'VNOW-6146', 'VNOW-6144', 'VNOW-6137', 'VNOW-6133', 'VNOW-6128', 'VNOW-6124', 'VNOW-6122', 'VNOW-6115', 'VNOW-6113', 'VNOW-6107', 'VNOW-6096', 'VNOW-6094', 'VNOW-6093', 'VNOW-6092', 'VNOW-6087', 'VNOW-6082', 'VNOW-6081', 'VNOW-6078', 'VNOW-6076', 'VNOW-6074', 'VNOW-6072', 'VNOW-6042', 'VNOW-6024', 'VNOW-6020', 'VNOW-5992', 'VNOW-5974', 'VNOW-5971', 'VNOW-5961', 'VNOW-5932', 'VNOW-5928', 'VNOW-5914', 'VNOW-5900', 'VNOW-5891', 'VNOW-5890', 'VNOW-5879', 'VNOW-5868', 'VNOW-5867', 'VNOW-5843', 'VNOW-5825', 'VNOW-5804', 'VNOW-5756', 'VNOW-5739', 'VNOW-5733', 'VNOW-5696', 'VNOW-5691', 'VNOW-5643', 'VNOW-5561', 'VNOW-5527', 'VNOW-5492', 'VNOW-5483', 'VNOW-5476', 'VNOW-5452', 'VNOW-5423', 'VNOW-5422', 'VNOW-5399', 'VNOW-5366', 'VNOW-5365', 'VNOW-5340', 'VNOW-5319', 'VNOW-5303', 'VNOW-5293', 'VNOW-5290', 'VNOW-5239', 'VNOW-5224', 'VNOW-5200', 'VNOW-5184', 'VNOW-5160', 'VNOW-5108', 'VNOW-5104', 'VNOW-5072', 'VNOW-5016', 'VNOW-4993', 'VNOW-4989', 'VNOW-4976', 'VNOW-4905', 'VNOW-4903', 'VNOW-4901', 'VNOW-4900', 'VNOW-4874', 'VNOW-4873', 'VNOW-4870', 'VNOW-4864', 'VNOW-4840', 'VNOW-4835', 'VNOW-4834', 'VNOW-4830', 'VNOW-4817', 'VNOW-4809', 'VNOW-4808', 'VNOW-4807', 'VNOW-4806', 'VNOW-4758', 'VNOW-4742', 'VNOW-4725', 'VNOW-4707', 'VNOW-4577', 'VNOW-4547', 'VNOW-4250', 'VNOW-3870', 'VNOW-3759', 'VNOW-3523', 'VNOW-2903']
  const issueKey = Math.floor(Math.random() * bugs.length)
  outputMessage(msg, bugs[issueKey], "Here's a random Low priority bug from the Spark backlog")
})

// Respond to a JIRA issue (e.g. PX-1234)
slapp.message(/(cs-|ra16-|mds-|px-|vm-|vnow-)(\d+)/i, ['mention', 'direct_message', 'ambient'], (msg) => {
  var text = (msg.body.event && msg.body.event.text) || ''
  var prPattern = /pull-requests/ig
  var pattern = /(cs-|ra16-|mds-|px-|vm-|vnow-)(\d+)/ig
  var prMatch = text.match(prPattern)
  var match = text.match(pattern)

  if (prMatch !== null && prMatch.length > 0) {
    // process as a pull request - need to extract the url that was pasted
    var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/
    var urlMatch = text.match(urlPattern)
    jira.getPRStatusString(process.env.BITBUCKET_URL, process.env.JIRA_U, process.env.JIRA_P, urlMatch[0])
      .then(bbStr => {
        // outputMessage(msg, match[0].toUpperCase(), bbStr)
        outputMessage(msg, match[0], '', 'Reviewers: ' + bbStr)
      })
  } else {
    // treat is as a regular text issue
<commit_msg>fixed issue and pull request on same message<commit_after>'use strict'

const express = require('express')
const Slapp = require('slapp')
const ConvoStore = require('slapp-convo-beepboop')
const Context = require('slapp-context-beepboop')
require('dotenv').config() // uid/pw go in .env file not checked in

const jira = require('./jira')

// use `PORT` env var on Beep Boop - default to 3000 locally
var port = process.env.PORT || 3000

var slapp = Slapp({
  // Beep Boop sets the SLACK_VERIFY_TOKEN env var
  verify_token: process.env.SLACK_VERIFY_TOKEN,
  convo_store: ConvoStore(),
  context: Context()
})

var previousIssue = ''

// response to the user typing "help"
slapp.message('help', ['mention', 'direct_message'], (msg) => {
  msg.say(`
Howdy! I will respond to the following messages:
\`help\` - to see this message
\`(cs-|ra16-|mds-|px-|vm-|vnow-)1234\` - to fetch a JIRA issue (e.g. PX-1416 or VNOW-5081).
\`(bitbucket pull request url)\` - to fetch the related issue, and current status of approvers (e.g. https://bitbucket.org/inmotionnow/web-vnow/pull-requests/248/petr-vnow-3774-develop/diff)
\`rand\` - show me a random Low priority bug from the Spark Backlog
`)
})

// return a random Spark low priority bug from the backlog
slapp.message('rand', ['mention', 'direct_message'], (msg) => {
  const bugs = ['VNOW-6343', 'VNOW-6340', 'VNOW-6338', 'VNOW-6334', 'VNOW-6330', 'VNOW-6329', 'VNOW-6328', 'VNOW-6327', 'VNOW-6317', 'VNOW-6215', 'VNOW-6188', 'VNOW-6185', 'VNOW-6184', 'VNOW-6176', 'VNOW-6175', 'VNOW-6172', 'VNOW-6151', 'VNOW-6150', 'VNOW-6146', 'VNOW-6144', 'VNOW-6137', 'VNOW-6133', 'VNOW-6128', 'VNOW-6124', 'VNOW-6122', 'VNOW-6115', 'VNOW-6113', 'VNOW-6107', 'VNOW-6096', 'VNOW-6094', 'VNOW-6093', 'VNOW-6092', 'VNOW-6087', 'VNOW-6082', 'VNOW-6081', 'VNOW-6078', 'VNOW-6076', 'VNOW-6074', 'VNOW-6072', 'VNOW-6042', 'VNOW-6024', 'VNOW-6020', 'VNOW-5992', 'VNOW-5974', 'VNOW-5971', 'VNOW-5961', 'VNOW-5932', 'VNOW-5928', 'VNOW-5914', 'VNOW-5900', 'VNOW-5891', 'VNOW-5890', 'VNOW-5879', 'VNOW-5868', 'VNOW-5867', 'VNOW-5843', 'VNOW-5825', 'VNOW-5804', 'VNOW-5756', 'VNOW-5739', 'VNOW-5733', 'VNOW-5696', 'VNOW-5691', 'VNOW-5643', 'VNOW-5561', 'VNOW-5527', 'VNOW-5492', 'VNOW-5483', 'VNOW-5476', 'VNOW-5452', 'VNOW-5423', 'VNOW-5422', 'VNOW-5399', 'VNOW-5366', 'VNOW-5365', 'VNOW-5340', 'VNOW-5319', 'VNOW-5303', 'VNOW-5293', 'VNOW-5290', 'VNOW-5239', 'VNOW-5224', 'VNOW-5200', 'VNOW-5184', 'VNOW-5160', 'VNOW-5108', 'VNOW-5104', 'VNOW-5072', 'VNOW-5016', 'VNOW-4993', 'VNOW-4989', 'VNOW-4976', 'VNOW-4905', 'VNOW-4903', 'VNOW-4901', 'VNOW-4900', 'VNOW-4874', 'VNOW-4873', 'VNOW-4870', 'VNOW-4864', 'VNOW-4840', 'VNOW-4835', 'VNOW-4834', 'VNOW-4830', 'VNOW-4817', 'VNOW-4809', 'VNOW-4808', 'VNOW-4807', 'VNOW-4806', 'VNOW-4758', 'VNOW-4742', 'VNOW-4725', 'VNOW-4707', 'VNOW-4577', 'VNOW-4547', 'VNOW-4250', 'VNOW-3870', 'VNOW-3759', 'VNOW-3523', 'VNOW-2903']
  const issueKey = Math.floor(Math.random() * bugs.length)
  outputMessage(msg, bugs[issueKey], "Here's a random Low priority bug from the Spark backlog")
})

// Respond to a JIRA issue (e.g. PX-1234)
slapp.message(/(cs-|ra16-|mds-|px-|vm-|vnow-)(\d+)/i, ['mention', 'direct_message', 'ambient'], (msg) => {
  var text = (msg.body.event && msg.body.event.text) || ''
  var prPattern = /pull-requests/ig
  var pattern = /(cs-|ra16-|mds-|px-|vm-|vnow-)(\d+)/ig
  var prMatch = text.match(prPattern)
  var match = text.match(pattern)

  if (prMatch !== null && prMatch.length > 0) {
    // process as a pull request - need to extract the url that was pasted
    var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/
    var urlMatch = text.match(urlPattern)
    jira.getPRStatusString(process.env.BITBUCKET_URL, process.env.JIRA_U, process.env.JIRA_P, urlMatch[0])
      .then(bbStr => {
        // what if user posted PX-123 and then a separate PR url? Need to make sure we only return the text for the pr (not the random issue number)
        if (match.length > 1) {
          match = urlMatch[0].match(pattern)
        }
        // outputMessage(msg, match[0].toUpperCase(), bbStr)
        outputMessage(msg, match[0], '', 'Reviewers: ' + bbStr)
      })
  } else {
    // treat is as a regular text issue

{'fraction_non_alphanumeric': 0.22701758762629412, 'fraction_numerical': 0.1297243357864538, 'mean_word_length': 4.156270096463023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 1, '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': '160875', 'n_tokens_mistral': 4218, 'n_tokens_neox': 3423, 'n_words': 713}