migrate_issues.rb
def hendl_issue(original)
    original_comments = client.issue_comments(source, original.number)
    comments = []
    original_comments.each do |original_comment|
      mapped_login_id = map_login_id(original_comment.user.login)
      table_code = table(mapped_login_id, "@#{mapped_login_id} commented")
      body = [table_code, original_comment.body]
      comments << {
        created_at: original_comment.created_at.iso8601,
        body: body.join("\n\n")
      }
    end

    actual_label = original.labels.collect { |a| a[:name] }

    mapped_login_id = map_login_id(original.user.login)

    table_link = "Imported from <a href='#{original.html_url}'>#{source}##{original.number}</a>"
    table_code = table(mapped_login_id, "Original issue by @#{mapped_login_id} - #{table_link}")
    body = [table_code, original.body]
    data = {
      issue: {
        title: original.title,
        body: body.join("\n\n"),
        created_at: original.created_at.iso8601,
        assignee: original.assignee.nil? ? nil : map_login_id(original.assignee.login),
        labels: actual_label + ["imported"],
        closed: original.state != "open"
      },
      comments: comments
    }
    data[:issue][:closed_at] = original.closed_at.iso8601 if original.state != "open"

    response = Excon.post("https://api.github.com/repos/#{destination}/import/issues", body: data.to_json, headers: request_headers)
    response = JSON.parse(response.body)
    status_url = response['url']
    puts response

    new_issue_url = nil

    begin
      (5..35).each do |request_num|
        sleep(request_num)

        puts "Sending #{status_url}"
        async_response = Excon.get(status_url, headers: request_headers) # if this crashes, make sure to have a valid token with admin permission to the actual repo
        async_response = JSON.parse(async_response.body)
        puts async_response.to_s.yellow

        new_issue_url = async_response['issue_url']
        break if new_issue_url.to_s.length > 0
        puts "unable to get new issue url for #{original.number} after #{request_num - 4} requests".yellow
      end
    rescue => ex
      puts "Something went wrong, wups"
      puts ex.to_s
      # If the error message is
      # {"message"=>"Not Found", "documentation_url"=>"https://developer.github.com/v3"}
      # that just means that fastlane-bot doesn't have admin access
    end

    if new_issue_url.to_s.length > 0
      new_issue_url.gsub!("api.github.com/repos", "github.com")

      client.update_issue(source, original.number, labels: (actual_label + ["migrated"]))

      # reason, link to the new issue
      puts "closing old issue #{original.number}"
      body = []
      body << "This issue was migrated to #{new_issue_url}. Please post all further comments there."
      body << reason unless reason.nil?
      puts new_issue_url
      client.add_comment(source, original.number, body.join("\n\n"))
      smart_sleep
      client.close_issue(source, original.number) unless original.state == "closed"
    else
      puts "unable to find new issue url, not closing or commenting".red
      client.update_issue(source, original.number, labels: (actual_label + ["migration_failed"]))
      puts "Status URL: #{status_url}"
      # This means we have to manually migrate the issue
      # if you want to try it again, just remove the migration_failed tag
    end
  end
# We copy over all the issues, and also mention everyone
# so that people are automatically subscribed to notifications
We copy over all the issues, and also mention everyone
so that people are automatically subscribed to notifications
We copy over all the issues and also mention everyone so that people are automatically subscribed to notifications
def hendl_issue(original)
    original_comments = client.issue_comments(source, original.number)
    comments = []
    original_comments.each do |original_comment|
      mapped_login_id = map_login_id(original_comment.user.login)
      table_code = table(mapped_login_id, "@#{mapped_login_id} commented")
      body = [table_code, original_comment.body]
      comments << {
        created_at: original_comment.created_at.iso8601,
        body: body.join("\n\n")
      }
    end
    actual_label = original.labels.collect { |a| a[:name] }
    mapped_login_id = map_login_id(original.user.login)
    table_link = "Imported from <a href='#{original.html_url}'>#{source}##{original.number}</a>"
    table_code = table(mapped_login_id, "Original issue by @#{mapped_login_id} - #{table_link}")
    body = [table_code, original.body]
    data = {
      issue: {
        title: original.title,
        body: body.join("\n\n"),
        created_at: original.created_at.iso8601,
        assignee: original.assignee.nil? ? nil : map_login_id(original.assignee.login),
        labels: actual_label + ["imported"],
        closed: original.state != "open"
      },
      comments: comments
    }
    data[:issue][:closed_at] = original.closed_at.iso8601 if original.state != "open"
    response = Excon.post("https://api.github.com/repos/#{destination}/import/issues", body: data.to_json, headers: request_headers)
    response = JSON.parse(response.body)
    status_url = response['url']
    puts response
    new_issue_url = nil
    begin
      (5..35).each do |request_num|
        sleep(request_num)
        puts "Sending #{status_url}"
        async_response = Excon.get(status_url, headers: request_headers) 
        async_response = JSON.parse(async_response.body)
        puts async_response.to_s.yellow
        new_issue_url = async_response['issue_url']
        break if new_issue_url.to_s.length > 0
        puts "unable to get new issue url for #{original.number} after #{request_num - 4} requests".yellow
      end
    rescue => ex
      puts "Something went wrong, wups"
      puts ex.to_s
    end
    if new_issue_url.to_s.length > 0
      new_issue_url.gsub!("api.github.com/repos", "github.com")
      client.update_issue(source, original.number, labels: (actual_label + ["migrated"]))
      puts "closing old issue #{original.number}"
      body = []
      body << "This issue was migrated to #{new_issue_url}. Please post all further comments there."
      body << reason unless reason.nil?
      puts new_issue_url
      client.add_comment(source, original.number, body.join("\n\n"))
      smart_sleep
      client.close_issue(source, original.number) unless original.state == "closed"
    else
      puts "unable to find new issue url, not closing or commenting".red
      client.update_issue(source, original.number, labels: (actual_label + ["migration_failed"]))
      puts "Status URL: #{status_url}"
    end
  end
def hendl_issue ( original ) original_comments = client . issue_comments ( source , original . number ) comments = [ ] original_comments . each do | original_comment | mapped_login_id = map_login_id ( original_comment . user . login ) table_code = table ( mapped_login_id , "@#{mapped_login_id} commented" ) body = [ table_code , original_comment . body ] comments << { created_at : original_comment . created_at . iso8601 , body : body . join ( "\n\n" ) } end actual_label = original . labels . collect { | a | a [ :name ] } mapped_login_id = map_login_id ( original . user . login ) table_link = "Imported from <a href='#{original.html_url}'>#{source}##{original.number}</a>" table_code = table ( mapped_login_id , "Original issue by @#{mapped_login_id} - #{table_link}" ) body = [ table_code , original . body ] data = { issue : { title : original . title , body : body . join ( "\n\n" ) , created_at : original . created_at . iso8601 , assignee : original . assignee . nil? ? nil : map_login_id ( original . assignee . login ) , labels : actual_label + [ "imported" ] , closed : original . state != "open" } , comments : comments } data [ :issue ] [ :closed_at ] = original . closed_at . iso8601 if original . state != "open" response = Excon . post ( "https://api.github.com/repos/#{destination}/import/issues" , body : data . to_json , headers : request_headers ) response = JSON . parse ( response . body ) status_url = response [ 'url' ] puts response new_issue_url = nil begin ( 5 .. 35 ) . each do | request_num | sleep ( request_num ) puts "Sending #{status_url}" async_response = Excon . get ( status_url , headers : request_headers ) async_response = JSON . parse ( async_response . body ) puts async_response . to_s . yellow new_issue_url = async_response [ 'issue_url' ] break if new_issue_url . to_s . length > 0 puts "unable to get new issue url for #{original.number} after #{request_num - 4} requests" . yellow end rescue => ex puts "Something went wrong, wups" puts ex . to_s end if new_issue_url . to_s . length > 0 new_issue_url . gsub! ( "api.github.com/repos" , "github.com" ) client . update_issue ( source , original . number , labels : ( actual_label + [ "migrated" ] ) ) puts "closing old issue #{original.number}" body = [ ] body << "This issue was migrated to #{new_issue_url}. Please post all further comments there." body << reason unless reason . nil? puts new_issue_url client . add_comment ( source , original . number , body . join ( "\n\n" ) ) smart_sleep client . close_issue ( source , original . number ) unless original . state == "closed" else puts "unable to find new issue url, not closing or commenting" . red client . update_issue ( source , original . number , labels : ( actual_label + [ "migration_failed" ] ) ) puts "Status URL: #{status_url}" end end
We copy over all the issues, and also mention everyone
so that people are automatically subscribed to notifications
We copy over all the issues and also mention everyone so that people are automatically subscribed to notifications
# if this crashes, make sure to have a valid token with admin permission to the actual repo # If the error message is # {"message"=>"Not Found", "documentation_url"=>"https://developer.github.com/v3"} # that just means that fastlane-bot doesn't have admin access # reason, link to the new issue # This means we have to manually migrate the issue # if you want to try it again, just remove the migration_failed tag
original