Skip to content

Instantly share code, notes, and snippets.

@hyiromori hyiromori/move_issues.md
Last active Jul 8, 2019

Embed
What would you like to do?
Move Issues: GitHub (GraphQL) -> JIRA (CSV)

Move Issues: GitHub (GraphQL) -> JIRA (CSV)

GraphQL Query

https://developer.github.com/v4/explorer/

query {
  repository(name: "team", owner: "integrity-healthcare") {
    issues(states: OPEN, first: 100) {
      nodes{
        number
        title
        bodyText
        comments(first: 100) {
          nodes {
            author{
              login
            }
            bodyText
            createdAt
          }
        }
      }
    }
  }
}

Ruby Source

require 'json'
require 'csv'

JSON_FILE = "#{ENV['HOME']}/github.json"
CSV_FILE = "#{ENV['HOME']}/jira.csv"

data = File.open(JSON_FILE, 'r') do |file|
  JSON.parse(file.read)
end

issues = data['data']['repository']['issues']['nodes']
CSV.open(CSV_FILE, 'w') do |file|
  file.puts(%w(Summary Description))
  issues.map do |issue|
    number = issue['number']
    title = issue['title']
    comments = issue['comments']['nodes'].map do |comment|
      "Author: #{comment['author']['login']}\n"\
      "CreatedAt: #{comment['createdAt']}\n\n"\
      "#{comment['bodyText']}"
    end.join("\n\n---\n\n")
    text = "GitHub Issue No: #{number}\n\n#{issue['bodyText']}"
    text += "\n\n---\n\n#{comments}" if comments != ''
    file.puts([title, text])
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.