<commit_before>require 'octokit'

command 'github import' do |c|
  c.syntax = %{jm github import <issue id>}
  c.summary = %{Import a Github issue into Jira}

  c.action do |args, options|

    iid = args.shift

    okey = $cfg['github.token']
    if okey.nil? then
      say_error "Missing github token!"
      exit 2
    end

    oc = Octokit::Client.new(:access_token => okey)
    if oc.nil? then
      say_error "cannot create client"
      exit 3
    end
    oc.login

    repo = oc.repo $cfg['github.project']
    rel = repo.rels[:issues]
    gissue = rel.get(:uri=>{:number=>iid})
    if gissue.status != 200 then
      say_error "Failed to get issue: #{gissue}"
      exit 2
    end
    gissue = gissue.data

    jira = JiraMule::JiraUtils.new(args, options)
    # Create Issue
    it = jira.checkIssueType # TODO Look at github labels and pick issue type
    if it.nil? then
      say_error "Cannot make an Issue of type 'bug'"
      exit 3
    end

    by = gissue[:user]
    qubody = []
    qubody << %{From [#{by[:login]}|#{by[:html_url]}]:}
    qubody << '{quote}'
    qubody << gissue[:body]
    qubody << '{quote}'

    jissue = jira.createIssue(it.first[:name], gissue[:title], qubody.join("\n"))
    jira.verbose "Created #{jissue[:key]}"

    # Link
    jira.linkTo(jissue[:key], gissue[:html_url], gissue[:title])

  end
end
alias_command :ghi, 'github import'

#  vim: set ai et sw=2 ts=2 :<commit_msg>If user name exists in Jira, mention them.<commit_after>require 'octokit'

command 'github import' do |c|
  c.syntax = %{jm github import <issue id>}
  c.summary = %{Import a Github issue into Jira}

  c.action do |args, options|

    iid = args.shift

    okey = $cfg['github.token']
    if okey.nil? then
      say_error "Missing github token!"
      exit 2
    end

    oc = Octokit::Client.new(:access_token => okey)
    if oc.nil? then
      say_error "cannot create client"
      exit 3
    end
    oc.login

    repo = oc.repo $cfg['github.project']
    rel = repo.rels[:issues]
    gissue = rel.get(:uri=>{:number=>iid})
    if gissue.status != 200 then
      say_error "Failed to get issue: #{gissue}"
      exit 2
    end
    gissue = gissue.data

    jira = JiraMule::JiraUtils.new(args, options)
    # Create Issue
    it = jira.checkIssueType # TODO Look at github labels and pick issue type
    if it.nil? then
      say_error "Cannot make an Issue of type 'bug'"
      exit 3
    end

    by = gissue[:user]
    # See if they have same user name in Jira.  If so, assume its them and mention.
    jby = jira.checkUser(by[:login])

    qubody = []
    if not jby.nil? and not jby.empty? then
      qubody << %{From [#{by[:login]}|#{by[:html_url]}] [~#{jby.first}]:}
    else
      qubody << %{From [#{by[:login]}|#{by[:html_url]}]:}
    end
    qubody << '{quote}'
    qubody << gissue[:body]
    qubody << '{quote}'

    jissue = jira.createIssue(it.first[:name], gissue[:title], qubody.join("\n"))
    jira.verbose "Created #{jissue[:key]}"

    # Link
    jira.linkTo(jissue[:key], gissue[:html_url], gissue[:title])

  end
end
alias_command :ghi, 'github import'

#  vim: set ai et sw=2 ts=2 :
{'fraction_non_alphanumeric': 0.14399744572158366, 'fraction_numerical': 0.005747126436781609, 'mean_word_length': 2.7975757575757574, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 11, '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': '3295894', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1087, 'n_words': 320}